2025-10-27 14:06:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\State;
|
|
|
|
|
|
|
|
|
|
use ApiPlatform\Metadata\Operation;
|
|
|
|
|
use ApiPlatform\State\ProviderInterface;
|
2025-11-08 20:02:37 +01:00
|
|
|
use App\Repository\DomainRepository;
|
|
|
|
|
use App\Repository\EntityRepository;
|
2025-10-27 14:06:25 +01:00
|
|
|
use App\Service\RDAPService;
|
|
|
|
|
use Symfony\Component\HttpFoundation\RequestStack;
|
2025-11-08 20:02:37 +01:00
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
2025-10-27 14:06:25 +01:00
|
|
|
|
2025-10-27 17:40:31 +01:00
|
|
|
readonly class FindDomainCollectionFromEntityProvider implements ProviderInterface
|
2025-10-27 14:06:25 +01:00
|
|
|
{
|
|
|
|
|
public function __construct(
|
|
|
|
|
private RequestStack $requestStack,
|
2025-11-08 20:02:37 +01:00
|
|
|
private EntityRepository $entityRepository,
|
|
|
|
|
private DomainRepository $domainRepository,
|
2025-10-27 14:06:25 +01:00
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
|
|
|
|
|
{
|
|
|
|
|
$request = $this->requestStack->getCurrentRequest();
|
2025-11-08 20:02:37 +01:00
|
|
|
$registrant = trim((string) $request->get('registrant'));
|
2025-10-27 14:06:25 +01:00
|
|
|
|
2025-11-08 20:02:37 +01:00
|
|
|
$forbidden = [
|
|
|
|
|
'redacted',
|
|
|
|
|
'privacy',
|
|
|
|
|
'registration private',
|
|
|
|
|
'domain administrator',
|
|
|
|
|
'registry super user account',
|
|
|
|
|
'ano nymous',
|
|
|
|
|
'by proxy',
|
|
|
|
|
];
|
2025-10-27 14:06:25 +01:00
|
|
|
|
2025-11-08 20:02:37 +01:00
|
|
|
foreach ($forbidden as $word) {
|
|
|
|
|
if (str_contains(strtolower($registrant), $word)) {
|
|
|
|
|
throw new HttpException(403, 'Forbidden search term');
|
|
|
|
|
}
|
2025-10-27 14:06:25 +01:00
|
|
|
}
|
|
|
|
|
|
2025-11-08 20:02:37 +01:00
|
|
|
$entities = $this->entityRepository->createQueryBuilder('e')
|
|
|
|
|
->where('e.tld IS NOT NULL')
|
|
|
|
|
->andWhere('e.handle NOT IN (:blacklist)')
|
|
|
|
|
->andWhere('UPPER(e.jCardOrg) = UPPER(:registrant) OR UPPER(e.jCardFn) = UPPER(:registrant)')
|
|
|
|
|
->setParameter('registrant', $registrant)
|
|
|
|
|
->setParameter('blacklist', RDAPService::ENTITY_HANDLE_BLACKLIST)
|
|
|
|
|
->getQuery()
|
|
|
|
|
->getResult();
|
2025-10-27 14:06:25 +01:00
|
|
|
|
2025-11-08 20:02:37 +01:00
|
|
|
if (empty($entities)) {
|
2025-10-27 14:06:25 +01:00
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-08 20:02:37 +01:00
|
|
|
return $this->domainRepository->createQueryBuilder('d')
|
|
|
|
|
->select('DISTINCT d')
|
|
|
|
|
->join('d.domainEntities', 'de')
|
|
|
|
|
->where('de.entity IN (:entityIds)')
|
|
|
|
|
->andWhere('JSONB_CONTAINS(de.roles, :role) = true')
|
|
|
|
|
->andWhere('de.deletedAt IS NULL')
|
|
|
|
|
->setParameter('entityIds', array_map(fn ($e) => $e->getId(), $entities))
|
|
|
|
|
->setParameter('role', '"registrant"')
|
|
|
|
|
->getQuery()->getResult();
|
2025-10-27 14:06:25 +01:00
|
|
|
}
|
|
|
|
|
}
|