diff --git a/application/Espo/Tools/Notification/CollaboratorsNotificator.php b/application/Espo/Tools/Notification/CollaboratorsNotificator.php index 2aae2715b3..c0e824e948 100644 --- a/application/Espo/Tools/Notification/CollaboratorsNotificator.php +++ b/application/Espo/Tools/Notification/CollaboratorsNotificator.php @@ -33,6 +33,7 @@ use Espo\Core\Acl\AssignmentChecker\Helper; use Espo\Core\Field\LinkParent; use Espo\Core\Name\Field; use Espo\Core\Notification\AssignmentNotificator\Params; +use Espo\Core\Notification\UserEnabledChecker; use Espo\Core\ORM\Entity; use Espo\Entities\Notification; use Espo\Entities\User; @@ -44,6 +45,7 @@ class CollaboratorsNotificator private Helper $helper, private EntityManager $entityManager, private User $user, + private UserEnabledChecker $userEnabledChecker, ) {} public function process(Entity $entity, Params $params): void @@ -85,18 +87,24 @@ class CollaboratorsNotificator private function toProcessUser(Entity $entity, string $userId): bool { + $entityType = $entity->getEntityType(); + if ($userId === $this->user->getId()) { return false; } - if ($this->helper->hasAssignedUsersField($entity->getEntityType())) { + if ($this->helper->hasAssignedUsersField($entityType)) { return !in_array($userId, $entity->getLinkMultipleIdList(Field::ASSIGNED_USERS)); } - if ($this->helper->hasAssignedUserField($entity->getEntityType())) { + if ($this->helper->hasAssignedUserField($entityType)) { return $userId !== $entity->get(Field::ASSIGNED_USER . 'Id'); } + if (!$this->userEnabledChecker->checkAssignment($entityType, $userId)) { + return false; + } + return true; } diff --git a/application/Espo/Tools/Notification/HookProcessor.php b/application/Espo/Tools/Notification/HookProcessor.php index e0a96ab969..a19d095b6d 100644 --- a/application/Espo/Tools/Notification/HookProcessor.php +++ b/application/Espo/Tools/Notification/HookProcessor.php @@ -75,8 +75,8 @@ class HookProcessor } $this->processAssignment($entity, $options); + $this->processCollaborating($entity, $options); - $this->collaboratorsNotificator->process($entity, $this->createParams($options)); } /** @@ -97,11 +97,9 @@ class HookProcessor return; } - $assignmentNotificationsEntityList = $this->config->get('assignmentNotificationsEntityList') ?? []; - if ( (!$force || !$hasStream) && - !in_array($entityType, $assignmentNotificationsEntityList) + !in_array($entityType, $this->getAssignmentEnabledEntityTypeList()) ) { return; } @@ -235,4 +233,28 @@ class HookProcessor return $params; } + + /** + * @return string[] + */ + private function getAssignmentEnabledEntityTypeList(): array + { + return $this->config->get('assignmentNotificationsEntityList') ?? []; + } + + /** + * @param array $options + */ + private function processCollaborating(CoreEntity $entity, array $options): void + { + // If stream is enabled, then always process. Otherwise, use the parameter for 'assignment'. + if ( + !$this->checkHasStream($entity->getEntityType()) && + !in_array($entity->getEntityType(), $this->getAssignmentEnabledEntityTypeList()) + ) { + return; + } + + $this->collaboratorsNotificator->process($entity, $this->createParams($options)); + } } diff --git a/application/Espo/Tools/Notification/RecordService.php b/application/Espo/Tools/Notification/RecordService.php index c3d42515aa..440fcfadd4 100644 --- a/application/Espo/Tools/Notification/RecordService.php +++ b/application/Espo/Tools/Notification/RecordService.php @@ -132,14 +132,6 @@ class RecordService $groupedCount = $groupedCountMap[$entity->getActionId()] ?? 0; } - if ($entity->getRelated() && $entity->getData()?->relatedName) { - $entity->set('relatedName', $entity->getData()->relatedName); - } - - if ($entity->getCreatedBy() && $entity->getData()?->createdByName) { - $entity->set('createdByName', $entity->getData()->createdByName); - } - $entity->set('groupedCount', $groupedCount); } @@ -218,6 +210,8 @@ class RecordService User $user ): void { + $this->prepareSetFields($entity); + $noteId = $this->getNoteId($entity); if (!$noteId) { @@ -471,4 +465,15 @@ class RecordService // @todo Param in preferences? return (bool) ($this->config->get('notificationGrouping') ?? true); } + + private function prepareSetFields(Notification $entity): void + { + if ($entity->getRelated() && $entity->getData()?->relatedName) { + $entity->set('relatedName', $entity->getData()->relatedName); + } + + if ($entity->getCreatedBy() && $entity->getData()?->createdByName) { + $entity->set('createdByName', $entity->getData()->createdByName); + } + } }