use assignment notification parameter for collaborator notifications

This commit is contained in:
Yuri Kuznetsov
2025-11-27 17:16:43 +02:00
parent 3581736bd5
commit b7a079b9d3
3 changed files with 49 additions and 14 deletions

View File

@@ -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;
}

View File

@@ -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<string, mixed> $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));
}
}

View File

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