diff --git a/application/Espo/Core/Notification/DefaultAssignmentNotificator.php b/application/Espo/Core/Notification/DefaultAssignmentNotificator.php index 3107b3cfd9..d3fab847e0 100644 --- a/application/Espo/Core/Notification/DefaultAssignmentNotificator.php +++ b/application/Espo/Core/Notification/DefaultAssignmentNotificator.php @@ -73,7 +73,7 @@ class DefaultAssignmentNotificator implements AssignmentNotificator continue; } - $this->processForUser($entity, $userId, $params); + $this->processForUser($entity, $userId); } return; @@ -89,10 +89,10 @@ class DefaultAssignmentNotificator implements AssignmentNotificator $assignedUserId = $entity->get(self::ATTR_ASSIGNED_USER_ID); - $this->processForUser($entity, $assignedUserId, $params); + $this->processForUser($entity, $assignedUserId); } - protected function processForUser(Entity $entity, string $assignedUserId, Params $params): void + protected function processForUser(Entity $entity, string $assignedUserId): void { if (!$this->userChecker->checkAssignment($entity->getEntityType(), $assignedUserId)) { return; @@ -127,8 +127,7 @@ class DefaultAssignmentNotificator implements AssignmentNotificator 'userId' => $this->user->getId(), 'userName' => $this->user->getName(), ]) - ->setRelated(LinkParent::createFromEntity($entity)) - ->setActionId($params->getActionId()); + ->setRelated(LinkParent::createFromEntity($entity)); $this->entityManager->saveEntity($notification); } diff --git a/application/Espo/Tools/Notification/Service.php b/application/Espo/Tools/Notification/Service.php index 924d34808c..fadf886727 100644 --- a/application/Espo/Tools/Notification/Service.php +++ b/application/Espo/Tools/Notification/Service.php @@ -103,8 +103,6 @@ class Service ->find(); foreach ($users as $user) { - $userId = $user->getId(); - if (!$this->checkUserNoteAccess($user, $note)) { continue; } @@ -124,6 +122,16 @@ class Service continue; } + $actionId = $params?->actionId; + + if ( + in_array($note->getType(), [Note::TYPE_ASSIGN, Note::TYPE_CREATE]) && + ($note->getData()->assignedUserId ?? null) === $user->getId() + ) { + // Do not group notifications about assignment. + $actionId = null; + } + $notification = $this->entityManager->getRDBRepositoryByClass(Notification::class)->getNew(); $notification @@ -131,13 +139,13 @@ class Service ->set(Field::CREATED_AT, $now) ->setData(['noteId' => $note->getId()]) ->setType(Notification::TYPE_NOTE) - ->setUserId($userId) + ->setUserId($user->getId()) ->setRelated(LinkParent::createFromEntity($notification)) ->setRelatedParent( $note->getParentType() && $note->getParentId() ? LinkParent::create($note->getParentType(), $note->getParentId()) : null ) - ->setActionId($params?->actionId); + ->setActionId($actionId); $collection[] = $notification; }