feature: add a link to create a notification to the referrer

This commit is contained in:
2022-05-27 23:24:54 +02:00
parent c41ee1d9de
commit bc288a2161
5 changed files with 60 additions and 18 deletions

View File

@@ -20,6 +20,7 @@ use Chill\MainBundle\Notification\Exception\NotificationHandlerNotFound;
use Chill\MainBundle\Notification\NotificationHandlerManager;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Repository\NotificationRepository;
use Chill\MainBundle\Repository\UserRepository;
use Chill\MainBundle\Security\Authorization\NotificationVoter;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
@@ -29,6 +30,7 @@ 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\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
@@ -55,6 +57,8 @@ class NotificationController extends AbstractController
private TranslatorInterface $translator;
private UserRepository $userRepository;
public function __construct(
EntityManagerInterface $em,
LoggerInterface $chillLogger,
@@ -63,7 +67,8 @@ class NotificationController extends AbstractController
NotificationRepository $notificationRepository,
NotificationHandlerManager $notificationHandlerManager,
PaginatorFactory $paginatorFactory,
TranslatorInterface $translator
TranslatorInterface $translator,
UserRepository $userRepository
) {
$this->em = $em;
$this->logger = $logger;
@@ -73,6 +78,7 @@ class NotificationController extends AbstractController
$this->notificationHandlerManager = $notificationHandlerManager;
$this->paginatorFactory = $paginatorFactory;
$this->translator = $translator;
$this->userRepository = $userRepository;
}
/**
@@ -100,6 +106,15 @@ class NotificationController extends AbstractController
->setRelatedEntityId($request->query->getInt('entityId'))
->setSender($this->security->getUser());
if ($request->query->has('tos')) {
foreach ($request->query->get('tos') as $toId) {
if (null === $to = $this->userRepository->find($toId)) {
throw new NotFoundHttpException("user with id {$toId} is not found");
}
$notification->addAddressee($to);
}
}
try {
$handler = $this->notificationHandlerManager->getHandler($notification);
} catch (NotificationHandlerNotFound $e) {