mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: register the same domain name twice with limited mode
This commit is contained in:
@@ -71,6 +71,7 @@ export function WatchlistForm({form, connectors, onCreateWatchlist}: {
|
|||||||
<Input placeholder={t`Watchlist Name`}
|
<Input placeholder={t`Watchlist Name`}
|
||||||
title={t`Naming the Watchlist makes it easier to find in the list below.`}
|
title={t`Naming the Watchlist makes it easier to find in the list below.`}
|
||||||
autoComplete='off'
|
autoComplete='off'
|
||||||
|
autoFocus
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.List
|
<Form.List
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class DomainRefreshController extends AbstractController
|
|||||||
return $domain;
|
return $domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (false === $kernel->isDebug()) {
|
if (false === $kernel->isDebug() && true === $this->getParameter('limited_features')) {
|
||||||
$limiter = $this->authenticatedApiLimiter->create($userId);
|
$limiter = $this->authenticatedApiLimiter->create($userId);
|
||||||
if (false === $limiter->consume()->isAccepted()) {
|
if (false === $limiter->consume()->isAccepted()) {
|
||||||
$this->logger->warning('User {username} was rate limited by the API.', [
|
$this->logger->warning('User {username} was rate limited by the API.', [
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ use Sabre\VObject\Reader;
|
|||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
use Symfony\Component\Serializer\SerializerInterface;
|
use Symfony\Component\Serializer\SerializerInterface;
|
||||||
|
|
||||||
@@ -58,12 +59,35 @@ class WatchListController extends AbstractController
|
|||||||
public function createWatchList(Request $request): WatchList
|
public function createWatchList(Request $request): WatchList
|
||||||
{
|
{
|
||||||
$watchList = $this->serializer->deserialize($request->getContent(), WatchList::class, 'json', ['groups' => 'watchlist:create']);
|
$watchList = $this->serializer->deserialize($request->getContent(), WatchList::class, 'json', ['groups' => 'watchlist:create']);
|
||||||
|
|
||||||
/** @var User $user */
|
/** @var User $user */
|
||||||
$user = $this->getUser();
|
$user = $this->getUser();
|
||||||
$watchList->setUser($user);
|
$watchList->setUser($user);
|
||||||
|
|
||||||
$this->logger->info('User {username} register a Watchlist.', [
|
/*
|
||||||
|
* In the limited version, we do not want a user to be able to register the same domain more than once in their watchlists.
|
||||||
|
* This policy guarantees the equal probability of obtaining a domain name if it is requested by several users.
|
||||||
|
*/
|
||||||
|
if ($this->getParameter('limited_features')) {
|
||||||
|
/** @var Domain[] $trackedDomains */
|
||||||
|
$trackedDomains = $user->getWatchLists()->reduce(fn (array $acc, WatchList $watchList) => [...$acc, ...$watchList->getDomains()->toArray()], []);
|
||||||
|
|
||||||
|
/** @var Domain $domain */
|
||||||
|
foreach ($watchList->getDomains()->getIterator() as $domain) {
|
||||||
|
if (in_array($domain, $trackedDomains)) {
|
||||||
|
$this->logger->notice('User {username} tried to create a watchlist with domain name {ldhName}. However, it is forbidden to register the same domain name twice with limited mode.', [
|
||||||
|
'username' => $user->getUserIdentifier(),
|
||||||
|
'ldhName' => $domain->getLdhName(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw new AccessDeniedHttpException('It is forbidden to register the same domain name twice in your watchlists with limited mode.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->logger->info('User {username} register a Watchlist ({token}).', [
|
||||||
'username' => $user->getUserIdentifier(),
|
'username' => $user->getUserIdentifier(),
|
||||||
|
'token' => $watchList->getToken(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->em->persist($watchList);
|
$this->em->persist($watchList);
|
||||||
|
|||||||
Reference in New Issue
Block a user