diff --git a/src/Bundle/ChillMainBundle/Controller/NotificationController.php b/src/Bundle/ChillMainBundle/Controller/NotificationController.php index a2b26832e..be6b60492 100644 --- a/src/Bundle/ChillMainBundle/Controller/NotificationController.php +++ b/src/Bundle/ChillMainBundle/Controller/NotificationController.php @@ -120,6 +120,36 @@ class NotificationController extends AbstractController ]); } + /** + * @Route("/{id}/edit", name="chill_main_notification_edit") + */ + public function editAction(Notification $notification, Request $request): Response + { + $this->denyAccessUnlessGranted(NotificationVoter::UPDATE, $notification); + + $form = $this->createForm(NotificationType::class, $notification); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->em->flush(); + + $this->addFlash('success', $this->translator->trans('notification.Notification updated')); + + if ($request->query->has('returnPath')) { + return new RedirectResponse($request->query->get('returnPath')); + } + + return $this->redirectToRoute('chill_main_notification_my'); + } + + return $this->render('@ChillMain/Notification/edit.html.twig', [ + 'form' => $form->createView(), + 'handler' => $this->notificationHandlerManager->getHandler($notification), + 'notification' => $notification, + ]); + } + /** * @Route("/inbox", name="chill_main_notification_my") */ diff --git a/src/Bundle/ChillMainBundle/Entity/Notification.php b/src/Bundle/ChillMainBundle/Entity/Notification.php index 4e6953239..bf7aac4b3 100644 --- a/src/Bundle/ChillMainBundle/Entity/Notification.php +++ b/src/Bundle/ChillMainBundle/Entity/Notification.php @@ -12,7 +12,6 @@ declare(strict_types=1); namespace Chill\MainBundle\Entity; use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; -use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; use DateTimeImmutable; use DateTimeInterface; use Doctrine\Common\Collections\ArrayCollection; diff --git a/src/Bundle/ChillMainBundle/Resources/views/Notification/edit.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Notification/edit.html.twig new file mode 100644 index 000000000..a6a52acf7 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/views/Notification/edit.html.twig @@ -0,0 +1,25 @@ +{% extends "@ChillMain/layout.html.twig" %} + +{% block content %} +
+
+ {% include handler.template(notification) with handler.templateData(notification) %} + + {{ form_start(form, { 'attr': { 'id': 'notification' }}) }} + + {{ form_row(form.addressees) }} + {{ form_row(form.message) }} + + {{ form_end(form) }} + + +
+
+{% endblock %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Notification/list.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Notification/list.html.twig index 96074e14d..064adcee1 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Notification/list.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Notification/list.html.twig @@ -66,9 +66,16 @@
diff --git a/src/Bundle/ChillMainBundle/Security/Authorization/NotificationVoter.php b/src/Bundle/ChillMainBundle/Security/Authorization/NotificationVoter.php index 547a39f82..bc68d906b 100644 --- a/src/Bundle/ChillMainBundle/Security/Authorization/NotificationVoter.php +++ b/src/Bundle/ChillMainBundle/Security/Authorization/NotificationVoter.php @@ -22,9 +22,9 @@ final class NotificationVoter extends Voter { public const COMMENT_EDIT = 'CHILL_MAIN_NOTIFICATION_COMMENT_EDIT'; - public const SEE = 'chill_main_notification_see'; + public const SEE = 'CHILL_MAIN_NOTIFICATION_SEE'; - public const UPDATE = 'chill_main_notification_update'; + public const UPDATE = 'CHILL_MAIN_NOTIFICATION_UPDATE'; protected function supports($attribute, $subject): bool { @@ -48,6 +48,9 @@ final class NotificationVoter extends Voter case self::SEE: return $subject->getSender() === $user || $subject->getAddressees()->contains($user); + case self::UPDATE: + return $subject->getSender() === $user; + default: throw new UnexpectedValueException("this subject {$attribute} is not implemented"); }