diff --git a/src/Bundle/ChillMainBundle/Controller/NotificationController.php b/src/Bundle/ChillMainBundle/Controller/NotificationController.php index 5b7fb269b..a6e876b6d 100644 --- a/src/Bundle/ChillMainBundle/Controller/NotificationController.php +++ b/src/Bundle/ChillMainBundle/Controller/NotificationController.php @@ -14,7 +14,6 @@ namespace Chill\MainBundle\Controller; use Chill\MainBundle\Entity\Notification; use Chill\MainBundle\Entity\NotificationComment; use Chill\MainBundle\Entity\User; -use Chill\MainBundle\Entity\Workflow\EntityWorkflow; use Chill\MainBundle\Form\NotificationCommentType; use Chill\MainBundle\Form\NotificationType; use Chill\MainBundle\Notification\Exception\NotificationHandlerNotFound; @@ -22,7 +21,6 @@ use Chill\MainBundle\Notification\NotificationHandlerManager; use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Repository\NotificationRepository; use Chill\MainBundle\Repository\UserRepository; -use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository; use Chill\MainBundle\Security\Authorization\NotificationVoter; use Doctrine\ORM\EntityManagerInterface; use Psr\Log\LoggerInterface; @@ -70,8 +68,7 @@ class NotificationController extends AbstractController NotificationHandlerManager $notificationHandlerManager, PaginatorFactory $paginatorFactory, TranslatorInterface $translator, - UserRepository $userRepository, - EntityWorkflowRepository $entityWorkflowRepository + UserRepository $userRepository ) { $this->em = $em; $this->logger = $logger; @@ -82,7 +79,6 @@ class NotificationController extends AbstractController $this->paginatorFactory = $paginatorFactory; $this->translator = $translator; $this->userRepository = $userRepository; - $this->entityWorkflowRepository = $entityWorkflowRepository; } /** @@ -349,7 +345,6 @@ class NotificationController extends AbstractController 'appendCommentForm' => isset($appendCommentForm) ? $appendCommentForm->createView() : null, 'editedCommentForm' => isset($editedCommentForm) ? $editedCommentForm->createView() : null, 'editedCommentId' => $commentId ?? null, - 'notificationCc' => $this->isNotificationCc($notification), ]); // we mark the notification as read after having computed the response @@ -369,21 +364,6 @@ class NotificationController extends AbstractController ]; } - private function isNotificationCc(Notification $notification): bool - { - $notificationCc = false; - - if ($notification->getRelatedEntityClass() === EntityWorkflow::class) { - $relatedEntity = $this->entityWorkflowRepository->findOneBy(['id' => $notification->getRelatedEntityId()]); - - if ($relatedEntity->getCurrentStepCreatedBy() !== $this->security->getUser()) { - $notificationCc = true; - } - } - - return $notificationCc; - } - private function itemsForTemplate(array $notifications): array { $templateData = []; @@ -393,7 +373,6 @@ class NotificationController extends AbstractController 'template' => $this->notificationHandlerManager->getTemplate($notification), 'template_data' => $this->notificationHandlerManager->getTemplateData($notification), 'notification' => $notification, - 'isNotificationCc' => $this->isNotificationCc($notification), ]; } diff --git a/src/Bundle/ChillMainBundle/Notification/Templating/NotificationTwigExtensionRuntime.php b/src/Bundle/ChillMainBundle/Notification/Templating/NotificationTwigExtensionRuntime.php index 5cf4ad084..0720c6da6 100644 --- a/src/Bundle/ChillMainBundle/Notification/Templating/NotificationTwigExtensionRuntime.php +++ b/src/Bundle/ChillMainBundle/Notification/Templating/NotificationTwigExtensionRuntime.php @@ -76,7 +76,6 @@ class NotificationTwigExtensionRuntime implements RuntimeExtensionInterface return $environment->render('@ChillMain/Notification/extension_list_notifications_for.html.twig', [ 'notifications' => $notifications, 'appendCommentForms' => $appendCommentForms, - 'notificationCc' => false, ]); } } diff --git a/src/Bundle/ChillMainBundle/Resources/views/Notification/extension_list_notifications_for.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Notification/extension_list_notifications_for.html.twig index 77d16a6a1..748142ab8 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Notification/extension_list_notifications_for.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Notification/extension_list_notifications_for.html.twig @@ -6,7 +6,6 @@ 'full_content': true, 'fold_item': true, 'action_button': true, - 'notification_cc': notificationCc, } %}{# #} {% endfor %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Notification/list.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Notification/list.html.twig index f7ab7f523..6dff67299 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Notification/list.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Notification/list.html.twig @@ -51,7 +51,7 @@ {% set notification = data.notification %} {% include 'ChillMainBundle:Notification:_list_item.html.twig' with { 'fold_item': true, - 'notification_cc': data.isNotificationCc + 'notification_cc': data.template_data.notificationCc is defined ? data.template_data.notificationCc : false } %} {% endfor %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig index 00c88cd50..2f9d5d63f 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig @@ -28,7 +28,7 @@ 'action_button': false, 'full_content': true, 'fold_item': false, - 'notification_cc': notificationCc + 'notification_cc': handler.getTemplateData(notification).notificationCc is defined ? handler.getTemplateData(notification).notificationCc : false } %} diff --git a/src/Bundle/ChillMainBundle/Workflow/Notification/WorkflowNotificationHandler.php b/src/Bundle/ChillMainBundle/Workflow/Notification/WorkflowNotificationHandler.php index 0d0c4305b..438e4c0e3 100644 --- a/src/Bundle/ChillMainBundle/Workflow/Notification/WorkflowNotificationHandler.php +++ b/src/Bundle/ChillMainBundle/Workflow/Notification/WorkflowNotificationHandler.php @@ -16,6 +16,7 @@ use Chill\MainBundle\Entity\Workflow\EntityWorkflow; use Chill\MainBundle\Notification\NotificationHandlerInterface; use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository; use Chill\MainBundle\Workflow\EntityWorkflowManager; +use Symfony\Component\Security\Core\Security; class WorkflowNotificationHandler implements NotificationHandlerInterface { @@ -23,10 +24,17 @@ class WorkflowNotificationHandler implements NotificationHandlerInterface private EntityWorkflowRepository $entityWorkflowRepository; - public function __construct(EntityWorkflowRepository $entityWorkflowRepository, EntityWorkflowManager $entityWorkflowManager) + private Security $security; + + public function __construct( + EntityWorkflowRepository $entityWorkflowRepository, + EntityWorkflowManager $entityWorkflowManager, + Security $security + ) { $this->entityWorkflowRepository = $entityWorkflowRepository; $this->entityWorkflowManager = $entityWorkflowManager; + $this->security = $security; } public function getTemplate(Notification $notification, array $options = []): string @@ -37,13 +45,28 @@ class WorkflowNotificationHandler implements NotificationHandlerInterface public function getTemplateData(Notification $notification, array $options = []): array { $entityWorkflow = $this->entityWorkflowRepository->find($notification->getRelatedEntityId()); - return [ 'entity_workflow' => $entityWorkflow, 'handler' => $this->entityWorkflowManager->getHandler($entityWorkflow), + 'notificationCc' => $this->isNotificationCc($notification), ]; } + private function isNotificationCc(Notification $notification): bool + { + $notificationCc = false; + + if ($notification->getRelatedEntityClass() === EntityWorkflow::class) { + $relatedEntity = $this->entityWorkflowRepository->findOneBy(['id' => $notification->getRelatedEntityId()]); + + if ($relatedEntity->getCurrentStepCreatedBy() !== $this->security->getUser()) { + $notificationCc = true; + } + } + + return $notificationCc; + } + public function supports(Notification $notification, array $options = []): bool { return $notification->getRelatedEntityClass() === EntityWorkflow::class;