From 3de5d29fe8efdf740e517a2facb64e175bb33828 Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 24 Mar 2023 14:57:02 +0100 Subject: [PATCH] Feature: show 'Cc' for notications as Cc --- .../Controller/NotificationController.php | 23 ++++++++++++++++++- .../NotificationTwigExtensionRuntime.php | 4 +++- .../views/Notification/_list_item.html.twig | 18 ++++++++++++++- ...extension_list_notifications_for.html.twig | 1 + .../views/Notification/list.html.twig | 3 ++- .../views/Notification/show.html.twig | 3 ++- .../translations/messages.fr.yml | 2 ++ .../translations/messages.nl.yml | 2 ++ 8 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Controller/NotificationController.php b/src/Bundle/ChillMainBundle/Controller/NotificationController.php index a6e876b6d..5b7fb269b 100644 --- a/src/Bundle/ChillMainBundle/Controller/NotificationController.php +++ b/src/Bundle/ChillMainBundle/Controller/NotificationController.php @@ -14,6 +14,7 @@ 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; @@ -21,6 +22,7 @@ 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; @@ -68,7 +70,8 @@ class NotificationController extends AbstractController NotificationHandlerManager $notificationHandlerManager, PaginatorFactory $paginatorFactory, TranslatorInterface $translator, - UserRepository $userRepository + UserRepository $userRepository, + EntityWorkflowRepository $entityWorkflowRepository ) { $this->em = $em; $this->logger = $logger; @@ -79,6 +82,7 @@ class NotificationController extends AbstractController $this->paginatorFactory = $paginatorFactory; $this->translator = $translator; $this->userRepository = $userRepository; + $this->entityWorkflowRepository = $entityWorkflowRepository; } /** @@ -345,6 +349,7 @@ 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 @@ -364,6 +369,21 @@ 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 = []; @@ -373,6 +393,7 @@ 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 8ccd420c5..5cf4ad084 100644 --- a/src/Bundle/ChillMainBundle/Notification/Templating/NotificationTwigExtensionRuntime.php +++ b/src/Bundle/ChillMainBundle/Notification/Templating/NotificationTwigExtensionRuntime.php @@ -74,7 +74,9 @@ class NotificationTwigExtensionRuntime implements RuntimeExtensionInterface } return $environment->render('@ChillMain/Notification/extension_list_notifications_for.html.twig', [ - 'notifications' => $notifications, 'appendCommentForms' => $appendCommentForms, + 'notifications' => $notifications, + 'appendCommentForms' => $appendCommentForms, + 'notificationCc' => false, ]); } } diff --git a/src/Bundle/ChillMainBundle/Resources/views/Notification/_list_item.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Notification/_list_item.html.twig index 1024d56b3..9bec09e4c 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Notification/_list_item.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Notification/_list_item.html.twig @@ -30,11 +30,27 @@ {% endif %} {% if c.notification.addressees|length > 0 %}
  • - + {% if c.notification_cc is defined %} + {% if c.notification_cc %} + + + {{ 'notification.cc'|trans }} : + + + {% else %} + + + {{ 'notification.to'|trans }} : + + + {% endif %} + {% else %} + {{ 'notification.to'|trans }} : + {% endif %} {% for a in c.notification.addressees %} {{ a|chill_entity_render_string }} 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 748142ab8..77d16a6a1 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,6 +6,7 @@ '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 1f1cbe673..f7ab7f523 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Notification/list.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Notification/list.html.twig @@ -50,7 +50,8 @@ {% for data in datas %} {% set notification = data.notification %} {% include 'ChillMainBundle:Notification:_list_item.html.twig' with { - 'fold_item': true + 'fold_item': true, + 'notification_cc': data.isNotificationCc } %} {% endfor %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig index cce7ebd64..00c88cd50 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig @@ -27,7 +27,8 @@ }, 'action_button': false, 'full_content': true, - 'fold_item': false + 'fold_item': false, + 'notification_cc': notificationCc } %} diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index 051eb0df0..985fb61c1 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -525,7 +525,9 @@ notification: list: Notifications Sent: Envoyé to: À + cc: Cc sent_to: Destinataire(s) + sent_cc: En copie from: De received_from: Expéditeur you were notified by %sender%: Vous avez été notifié par %sender% diff --git a/src/Bundle/ChillMainBundle/translations/messages.nl.yml b/src/Bundle/ChillMainBundle/translations/messages.nl.yml index 97a82b371..2e4ee5a88 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.nl.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.nl.yml @@ -446,7 +446,9 @@ notification: list: Notifications Sent: Envoyé to: À + cc: Cc sent_to: Destinataire(s) + sent_cc: En copie from: De received_from: Expéditeur you were notified by %sender%: Vous avez été notifié par %sender%