Feature: show 'Cc' for notications as Cc

This commit is contained in:
nobohan
2023-03-24 14:57:02 +01:00
parent 94046aab81
commit 3de5d29fe8
8 changed files with 51 additions and 5 deletions

View File

@@ -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),
];
}