mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: start webhook support
This commit is contained in:
@@ -2,11 +2,13 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Config\WebhookScheme;
|
||||
use App\Entity\Domain;
|
||||
use App\Entity\DomainEntity;
|
||||
use App\Entity\DomainEvent;
|
||||
use App\Entity\User;
|
||||
use App\Entity\WatchList;
|
||||
use App\Notifier\TestChatNotification;
|
||||
use App\Repository\WatchListRepository;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
@@ -32,6 +34,9 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
|
||||
use Symfony\Component\Notifier\Transport\Dsn;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
|
||||
@@ -65,6 +70,23 @@ class WatchListController extends AbstractController
|
||||
$user = $this->getUser();
|
||||
$watchList->setUser($user);
|
||||
|
||||
if (null !== $watchList->getWebhookDsn()) {
|
||||
foreach ($watchList->getWebhookDsn() as $dsnString) {
|
||||
$dsn = new Dsn($dsnString);
|
||||
|
||||
$scheme = $dsn->getScheme();
|
||||
$webhookScheme = WebhookScheme::tryFrom($scheme);
|
||||
|
||||
if (null === $webhookScheme) {
|
||||
throw new BadRequestHttpException("The DSN scheme ($scheme) is not supported");
|
||||
}
|
||||
$transportFactoryClass = $webhookScheme->getChatTransportFactory();
|
||||
/** @var AbstractTransportFactory $transportFactory */
|
||||
$transportFactory = new $transportFactoryClass();
|
||||
$transportFactory->create($dsn)->send((new TestChatNotification())->asChatMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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.
|
||||
@@ -151,6 +173,16 @@ class WatchListController extends AbstractController
|
||||
$user = $this->getUser();
|
||||
$watchList->setUser($user);
|
||||
|
||||
if (null !== $watchList->getWebhookDsn()) {
|
||||
foreach ($watchList->getWebhookDsn() as $dsnString) {
|
||||
$scheme = (new Dsn($dsnString))->getScheme();
|
||||
|
||||
if (null === WebhookScheme::tryFrom($scheme)) {
|
||||
throw new BadRequestHttpException("The DSN scheme ($scheme) is not supported");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->getParameter('limited_features')) {
|
||||
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', [
|
||||
|
||||
Reference in New Issue
Block a user