chore: merge master

This commit is contained in:
Maël Gangloff
2025-05-21 13:20:04 +02:00
4 changed files with 97 additions and 107 deletions

View File

@@ -23,9 +23,6 @@ use Eluceo\iCal\Domain\Entity\Calendar;
use Eluceo\iCal\Presentation\Component\Property;
use Eluceo\iCal\Presentation\Component\Property\Value\TextValue;
use Eluceo\iCal\Presentation\Factory\CalendarFactory;
use Exception;
use JsonException;
use Laminas\Feed\Writer\Deleted;
use Laminas\Feed\Writer\Entry;
use Laminas\Feed\Writer\Feed;
use Psr\Log\LoggerInterface;
@@ -58,18 +55,17 @@ class WatchListController extends AbstractController
{
public function __construct(
private readonly SerializerInterface&DecoderInterface&DenormalizerInterface $serializer,
private readonly EntityManagerInterface $em,
private readonly WatchListRepository $watchListRepository,
private readonly LoggerInterface $logger,
private readonly ChatNotificationService $chatNotificationService,
private readonly DomainRepository $domainRepository,
private readonly RDAPService $RDAPService,
private readonly RateLimiterFactory $rdapRequestsLimiter,
private readonly KernelInterface $kernel,
private readonly EntityManagerInterface $em,
private readonly WatchListRepository $watchListRepository,
private readonly LoggerInterface $logger,
private readonly ChatNotificationService $chatNotificationService,
private readonly DomainRepository $domainRepository,
private readonly RDAPService $RDAPService,
private readonly RateLimiterFactory $rdapRequestsLimiter,
private readonly KernelInterface $kernel,
#[Autowire(service: 'service_container')]
private readonly ContainerInterface $locator,
)
{
private readonly ContainerInterface $locator,
) {
}
/**
@@ -79,8 +75,8 @@ class WatchListController extends AbstractController
* @throws ExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws JsonException
* @throws Exception
* @throws \JsonException
* @throws \Exception
*/
#[Route(
path: '/api/watchlists',
@@ -104,7 +100,7 @@ class WatchListController extends AbstractController
* This policy guarantees the equal probability of obtaining a domain name if it is requested by several users.
*/
if ($this->getParameter('limited_features')) {
if ($watchList->getDomains()->count() > (int)$this->getParameter('limit_max_watchlist_domains')) {
if ($watchList->getDomains()->count() > (int) $this->getParameter('limit_max_watchlist_domains')) {
$this->logger->notice('User {username} tried to create a Watchlist. The maximum number of domains has been reached.', [
'username' => $user->getUserIdentifier(),
]);
@@ -112,7 +108,7 @@ class WatchListController extends AbstractController
}
$userWatchLists = $user->getWatchLists();
if ($userWatchLists->count() >= (int)$this->getParameter('limit_max_watchlist')) {
if ($userWatchLists->count() >= (int) $this->getParameter('limit_max_watchlist')) {
$this->logger->notice('User {username} tried to create a Watchlist. The maximum number of Watchlists has been reached', [
'username' => $user->getUserIdentifier(),
]);
@@ -120,7 +116,7 @@ class WatchListController extends AbstractController
}
/** @var Domain[] $trackedDomains */
$trackedDomains = $userWatchLists->reduce(fn(array $acc, WatchList $watchList) => [...$acc, ...$watchList->getDomains()->toArray()], []);
$trackedDomains = $userWatchLists->reduce(fn (array $acc, WatchList $watchList) => [...$acc, ...$watchList->getDomains()->toArray()], []);
/** @var Domain $domain */
foreach ($watchList->getDomains()->getIterator() as $domain) {
@@ -136,7 +132,7 @@ class WatchListController extends AbstractController
}
}
if (null !== $watchList->getWebhookDsn() && count($watchList->getWebhookDsn()) > (int)$this->getParameter('limit_max_watchlist_webhooks')) {
if (null !== $watchList->getWebhookDsn() && count($watchList->getWebhookDsn()) > (int) $this->getParameter('limit_max_watchlist_webhooks')) {
$this->logger->notice('User {username} tried to create a Watchlist. The maximum number of webhooks has been reached.', [
'username' => $user->getUserIdentifier(),
]);
@@ -176,7 +172,7 @@ class WatchListController extends AbstractController
}
/**
* @throws Exception
* @throws \Exception
* @throws ExceptionInterface
*/
private function verifyConnector(WatchList $watchList, ?Connector $connector): void
@@ -224,12 +220,12 @@ class WatchListController extends AbstractController
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws JsonException
* @throws \JsonException
* @throws OptimisticLockException
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws ExceptionInterface
* @throws Exception
* @throws \Exception
*/
#[Route(
path: '/api/watchlists/{token}',
@@ -249,7 +245,7 @@ class WatchListController extends AbstractController
$watchList->setUser($user);
if ($this->getParameter('limited_features')) {
if ($watchList->getDomains()->count() > (int)$this->getParameter('limit_max_watchlist_domains')) {
if ($watchList->getDomains()->count() > (int) $this->getParameter('limit_max_watchlist_domains')) {
$this->logger->notice('User {username} tried to update a Watchlist. The maximum number of domains has been reached for this Watchlist', [
'username' => $user->getUserIdentifier(),
]);
@@ -260,8 +256,8 @@ class WatchListController extends AbstractController
/** @var Domain[] $trackedDomains */
$trackedDomains = $userWatchLists
->filter(fn(WatchList $wl) => $wl->getToken() !== $watchList->getToken())
->reduce(fn(array $acc, WatchList $wl) => [...$acc, ...$wl->getDomains()->toArray()], []);
->filter(fn (WatchList $wl) => $wl->getToken() !== $watchList->getToken())
->reduce(fn (array $acc, WatchList $wl) => [...$acc, ...$wl->getDomains()->toArray()], []);
/** @var Domain $domain */
foreach ($watchList->getDomains()->getIterator() as $domain) {
@@ -276,7 +272,7 @@ class WatchListController extends AbstractController
}
}
if (null !== $watchList->getWebhookDsn() && count($watchList->getWebhookDsn()) > (int)$this->getParameter('limit_max_watchlist_webhooks')) {
if (null !== $watchList->getWebhookDsn() && count($watchList->getWebhookDsn()) > (int) $this->getParameter('limit_max_watchlist_webhooks')) {
$this->logger->notice('User {username} tried to update a Watchlist. The maximum number of webhooks has been reached.', [
'username' => $user->getUserIdentifier(),
]);
@@ -313,7 +309,7 @@ class WatchListController extends AbstractController
* @throws ParseException
* @throws EofException
* @throws InvalidDataException
* @throws Exception
* @throws \Exception
*/
#[Route(
path: '/api/watchlists/{token}/calendar',
@@ -349,7 +345,7 @@ class WatchListController extends AbstractController
}
/**
* @throws Exception
* @throws \Exception
*/
#[Route(
path: '/api/tracked',
@@ -370,7 +366,7 @@ class WatchListController extends AbstractController
/** @var Domain $domain */
foreach ($watchList->getDomains()->getIterator() as $domain) {
/** @var DomainEvent|null $exp */
$exp = $domain->getEvents()->findFirst(fn(int $key, DomainEvent $e) => !$e->getDeleted() && 'expiration' === $e->getAction());
$exp = $domain->getEvents()->findFirst(fn (int $key, DomainEvent $e) => !$e->getDeleted() && 'expiration' === $e->getAction());
if (!$domain->getDeleted() && null !== $exp && !in_array($domain, $domains)) {
$domains[] = $domain;
@@ -378,7 +374,7 @@ class WatchListController extends AbstractController
}
}
usort($domains, fn(Domain $d1, Domain $d2) => $d1->getExpiresInDays() - $d2->getExpiresInDays());
usort($domains, fn (Domain $d1, Domain $d2) => $d1->getExpiresInDays() - $d2->getExpiresInDays());
return $domains;
}
@@ -389,7 +385,7 @@ class WatchListController extends AbstractController
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws JsonException
* @throws \JsonException
*/
private function registerDomainsInWatchlist(string $content, array $groups): WatchList
{
@@ -402,11 +398,11 @@ class WatchListController extends AbstractController
throw new BadRequestHttpException('Invalid payload: missing or invalid "domains" field.');
}
$domains = array_map(fn(string $d) => str_replace('/api/domains/', '', $d), $data['domains']);
$domains = array_map(fn (string $d) => str_replace('/api/domains/', '', $d), $data['domains']);
foreach ($domains as $ldhName) {
/** @var ?Domain $domain */
$domain = $this->domainRepository->findOneBy(['ldhName' => $ldhName]);
$domain = $this->domainRepository->findOneBy(['ldhName' => RDAPService::convertToIdn($ldhName)]);
if (null === $domain) {
try {
@@ -439,7 +435,7 @@ class WatchListController extends AbstractController
}
/**
* @throws Exception
* @throws \Exception
*/
#[Route(
path: '/api/watchlists/{token}/rss/events',
@@ -457,11 +453,11 @@ class WatchListController extends AbstractController
$feed = (new Feed())
->setLanguage('en')
->setCopyright('Domain Watchdog makes this information available "as is," and does not guarantee its accuracy.')
->setTitle('Domain events (' . $watchlist->getName().')')
->setGenerator("Domain Watchdog - RSS Feed", null, "https://github.com/maelgangloff/domain-watchdog")
->setTitle('Domain events ('.$watchlist->getName().')')
->setGenerator('Domain Watchdog - RSS Feed', null, 'https://github.com/maelgangloff/domain-watchdog')
->setDescription('The latest events for domain names in your Watchlist')
->setLink($request->getSchemeAndHttpHost() . "/#/tracking/watchlist")
->setFeedLink($request->getSchemeAndHttpHost() . "/api/watchlists/" . $token . '/rss/events', 'atom')
->setLink($request->getSchemeAndHttpHost().'/#/tracking/watchlist')
->setFeedLink($request->getSchemeAndHttpHost().'/api/watchlists/'.$token.'/rss/events', 'atom')
->setDateCreated($watchlist->getCreatedAt());
/** @var Domain $domain */
@@ -471,13 +467,13 @@ class WatchListController extends AbstractController
}
}
return new Response($feed->export("atom"), Response::HTTP_OK, [
return new Response($feed->export('atom'), Response::HTTP_OK, [
'Content-Type' => 'application/atom+xml; charset=utf-8',
]);
}
/**
* @throws Exception
* @throws \Exception
*/
#[Route(
path: '/api/watchlists/{token}/rss/status',
@@ -495,11 +491,11 @@ class WatchListController extends AbstractController
$feed = (new Feed())
->setLanguage('en')
->setCopyright('Domain Watchdog makes this information available "as is," and does not guarantee its accuracy.')
->setTitle('Domain EPP status (' . $watchlist->getName().')')
->setGenerator("Domain Watchdog - RSS Feed", null, "https://github.com/maelgangloff/domain-watchdog")
->setTitle('Domain EPP status ('.$watchlist->getName().')')
->setGenerator('Domain Watchdog - RSS Feed', null, 'https://github.com/maelgangloff/domain-watchdog')
->setDescription('The latest changes to the EPP status of the domain names in your Watchlist')
->setLink($request->getSchemeAndHttpHost() . "/#/tracking/watchlist")
->setFeedLink($request->getSchemeAndHttpHost() . "/api/watchlists/" . $token . '/rss/status', 'atom')
->setLink($request->getSchemeAndHttpHost().'/#/tracking/watchlist')
->setFeedLink($request->getSchemeAndHttpHost().'/api/watchlists/'.$token.'/rss/status', 'atom')
->setDateCreated($watchlist->getCreatedAt());
/** @var Domain $domain */
@@ -509,67 +505,65 @@ class WatchListController extends AbstractController
}
}
return new Response($feed->export("atom"), Response::HTTP_OK, [
return new Response($feed->export('atom'), Response::HTTP_OK, [
'Content-Type' => 'application/atom+xml; charset=utf-8',
]);
}
/**
* @throws Exception
* @throws \Exception
*/
private function getRssEventEntries(string $baseUrl, Domain $domain): array
{
$entries = [];
foreach ($domain->getEvents()->filter(fn (DomainEvent $e) => $e->getDate()->diff(new \DateTimeImmutable('now'))->y <= 10)->getIterator() as $event) {
$entries[] = (new Entry())
->setId($baseUrl . "/api/domains/" . $domain->getLdhName() . '#events-' . $event->getId())
->setTitle($domain->getLdhName() . ': ' . $event->getAction(). ' - event update')
->setDescription("Domain name event")
->setLink($baseUrl . "/#/search/domain/" . $domain->getLdhName())
->setId($baseUrl.'/api/domains/'.$domain->getLdhName().'#events-'.$event->getId())
->setTitle($domain->getLdhName().': '.$event->getAction().' - event update')
->setDescription('Domain name event')
->setLink($baseUrl.'/#/search/domain/'.$domain->getLdhName())
->setContent($this->render('rss/event_entry.html.twig', [
'event' => $event
'event' => $event,
])->getContent())
->setDateModified($event->getDate())
->addAuthor(["name" => strtoupper($domain->getTld()->getTld()) . " Registry"]);
->addAuthor(['name' => strtoupper($domain->getTld()->getTld()).' Registry']);
}
return $entries;
}
/**
* @throws Exception
* @throws \Exception
*/
private function getRssStatusEntries(string $baseUrl, Domain $domain): array
{
$entries = [];
foreach ($domain->getDomainStatuses()->filter(fn (DomainStatus $e) => $e->getDate()->diff(new \DateTimeImmutable('now'))->y <= 10)->getIterator() as $domainStatus) {
$authors = [["name" => strtoupper($domain->getTld()->getTld()) . " Registry"]];
$authors = [['name' => strtoupper($domain->getTld()->getTld()).' Registry']];
/** @var string $status */
foreach ([...$domainStatus->getAddStatus(), ...$domainStatus->getDeleteStatus()] as $status) {
if(str_starts_with($status, 'client')) {
$authors[] = ["name" => "Registrar"];
if (str_starts_with($status, 'client')) {
$authors[] = ['name' => 'Registrar'];
break;
}
}
$entries[] = (new Entry())
->setId($baseUrl . "/api/domains/" . $domain->getLdhName() . '#status-' . $domainStatus->getId())
->setTitle($domain->getLdhName() . ' - EPP status update')
->setDescription("There has been a change in the EPP status of the domain name.")
->setLink($baseUrl . "/#/search/domain/" . $domain->getLdhName())
->setId($baseUrl.'/api/domains/'.$domain->getLdhName().'#status-'.$domainStatus->getId())
->setTitle($domain->getLdhName().' - EPP status update')
->setDescription('There has been a change in the EPP status of the domain name.')
->setLink($baseUrl.'/#/search/domain/'.$domain->getLdhName())
->setContent($this->render('rss/status_entry.html.twig', [
'domainStatus' => $domainStatus
'domainStatus' => $domainStatus,
])->getContent())
->setDateCreated($domainStatus->getCreatedAt())
->setDateModified($domainStatus->getDate())
->addCategory(["term" => $domain->getLdhName()])
->addCategory(["term" => strtoupper($domain->getTld()->getTld())])
->addCategory(['term' => $domain->getLdhName()])
->addCategory(['term' => strtoupper($domain->getTld()->getTld())])
->addAuthors($authors)
;
}
return $entries;
}
}