mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
fix cs
This commit is contained in:
@@ -32,16 +32,17 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use function in_array;
|
||||
|
||||
/**
|
||||
* @Route("/{_locale}/notification")
|
||||
*/
|
||||
class NotificationController extends AbstractController
|
||||
{
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private LoggerInterface $chillLogger;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private LoggerInterface $logger;
|
||||
|
||||
private NotificationHandlerManager $notificationHandlerManager;
|
||||
@@ -74,49 +75,6 @@ class NotificationController extends AbstractController
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{id}/access_key", name="chill_main_notification_grant_access_by_access_key")
|
||||
*/
|
||||
public function getAccessByAccessKey(Notification $notification, Request $request): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');
|
||||
|
||||
if (!$this->security->getUser() instanceof User) {
|
||||
throw new AccessDeniedHttpException('You must be authenticated and a user to create a notification');
|
||||
}
|
||||
|
||||
foreach (['accessKey', 'email'] as $param) {
|
||||
if (!$request->query->has($param)) {
|
||||
throw new BadRequestHttpException("Missing $param parameter");
|
||||
}
|
||||
}
|
||||
|
||||
if ($notification->getAccessKey() !== $request->query->getAlnum('accessKey')) {
|
||||
throw new AccessDeniedHttpException('access key is invalid');
|
||||
}
|
||||
|
||||
if (!in_array($request->query->get('email'), $notification->getAddressesEmails())) {
|
||||
return (new Response('The email address is no more associated with this notification'))
|
||||
->setStatusCode(Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
|
||||
$notification->addAddressee($this->security->getUser());
|
||||
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
$logMsg = '[Notification] a user is granted access to notification trough an access key';
|
||||
$context = [
|
||||
'notificationId' => $notification->getId(),
|
||||
'email' => $request->query->get('email'),
|
||||
'user' => $this->security->getUser()->getId(),
|
||||
];
|
||||
|
||||
$this->logger->info($logMsg, $context);
|
||||
$this->chillLogger->info($logMsg, $context);
|
||||
|
||||
return $this->redirectToRoute('chill_main_notification_show', ['id' => $notification->getId()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/create", name="chill_main_notification_create")
|
||||
*/
|
||||
@@ -202,6 +160,49 @@ class NotificationController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{id}/access_key", name="chill_main_notification_grant_access_by_access_key")
|
||||
*/
|
||||
public function getAccessByAccessKey(Notification $notification, Request $request): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');
|
||||
|
||||
if (!$this->security->getUser() instanceof User) {
|
||||
throw new AccessDeniedHttpException('You must be authenticated and a user to create a notification');
|
||||
}
|
||||
|
||||
foreach (['accessKey', 'email'] as $param) {
|
||||
if (!$request->query->has($param)) {
|
||||
throw new BadRequestHttpException("Missing {$param} parameter");
|
||||
}
|
||||
}
|
||||
|
||||
if ($notification->getAccessKey() !== $request->query->getAlnum('accessKey')) {
|
||||
throw new AccessDeniedHttpException('access key is invalid');
|
||||
}
|
||||
|
||||
if (!in_array($request->query->get('email'), $notification->getAddressesEmails(), true)) {
|
||||
return (new Response('The email address is no more associated with this notification'))
|
||||
->setStatusCode(Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
|
||||
$notification->addAddressee($this->security->getUser());
|
||||
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
$logMsg = '[Notification] a user is granted access to notification trough an access key';
|
||||
$context = [
|
||||
'notificationId' => $notification->getId(),
|
||||
'email' => $request->query->get('email'),
|
||||
'user' => $this->security->getUser()->getId(),
|
||||
];
|
||||
|
||||
$this->logger->info($logMsg, $context);
|
||||
$this->chillLogger->info($logMsg, $context);
|
||||
|
||||
return $this->redirectToRoute('chill_main_notification_show', ['id' => $notification->getId()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/inbox", name="chill_main_notification_my")
|
||||
*/
|
||||
|
Reference in New Issue
Block a user