EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
Notification group to super parent
Yuriid8d0654e75c4
diff --git a/application/Espo/Tools/Notification/NoteHookProcessor.php b/application/Espo/Tools/Notification/NoteHookProcessor.phpindex 668d5464a3..51c1ad06d5 100644--- a/application/Espo/Tools/Notification/NoteHookProcessor.php+++ b/application/Espo/Tools/Notification/NoteHookProcessor.php@@ -82,31 +82,27 @@ class NoteHookProcessorreturn;}- $userList = $this->getSubscriberList($parentType, $parentId, $note->isInternal());+ $users = $this->getSubscriberList($parentType, $parentId, $note->isInternal());- $userIdMetList = [];+ $regularUserIds = [];- foreach ($userList as $user) {- $userIdMetList[] = $user->getId();+ foreach ($users as $user) {+ $regularUserIds[] = $user->getId();}+ $superUserIds = [];+if ($superParentType && $superParentId) {- $additionalUserList = $this->getSubscriberList(- $superParentType,- $superParentId,- $note->isInternal()- );-- foreach ($additionalUserList as $user) {- if (- $user->isPortal() ||- in_array($user->getId(), $userIdMetList)- ) {- continue;- }+ $superUsers = $this->getSubscriberList($superParentType, $superParentId, $note->isInternal());++ $superUsers = $superUsers->filter(function (User $user) use ($regularUserIds) {+ return !$user->isPortal() && !in_array($user->getId(), $regularUserIds);+ });- $userIdMetList[] = $user->getId();- $userList[] = $user;+ foreach ($superUsers as $user) {+ $superUserIds[] = $user->getId();++ $users[] = $user;}}@@ -116,23 +112,23 @@ class NoteHookProcessor$skipAclCheck = !$note->isAclProcessed();$teamIdList = null;- $userIdList = null;+ $regularUserIds = null;if (!$skipAclCheck) {$teamIdList = $note->getLinkMultipleIdList(Field::TEAMS);- $userIdList = $note->getLinkMultipleIdList('users');+ $regularUserIds = $note->getLinkMultipleIdList('users');}$notifyUserIdList = [];- foreach ($userList as $user) {+ foreach ($users as $user) {if ($skipAclCheck) {$notifyUserIdList[] = $user->getId();continue;}- /** @var string[] $userIdList */+ /** @var string[] $regularUserIds *//** @var string[] $teamIdList */if ($user->isAdmin()) {@@ -153,14 +149,18 @@ class NoteHookProcessor$level = $this->internalAclManager->getLevel($user, $targetType, Table::ACTION_READ);- if (!$this->checkUserAccess($user, $level, $teamIdList, $userIdList)) {+ if (!$this->checkUserAccess($user, $level, $teamIdList, $regularUserIds)) {continue;}$notifyUserIdList[] = $user->getId();}- $this->processNotify($note, array_unique($notifyUserIdList), $params);+ $regularIds = array_unique(array_diff($notifyUserIdList, $superUserIds));+ $superIds = array_unique(array_intersect($notifyUserIdList, $superUserIds));++ $this->processNotify($note, $regularIds, $params);+ $this->processNotify($note, $superIds, $params, true);}private function afterSaveNoParent(Note $note): void@@ -193,7 +193,7 @@ class NoteHookProcessor/*** @param string[] $userIdList*/- private function processNotify(Note $note, array $userIdList, ?Params $params = null): void+ private function processNotify(Note $note, array $userIdList, ?Params $params = null, bool $isSuper = false): void{$filteredUserIdList = array_filter($userIdList,@@ -229,7 +229,14 @@ class NoteHookProcessorreturn;}- $this->service->notifyAboutNote($filteredUserIdList, $note, $params);+ $notifyParams = new NoteNotifyParams(isSuper: $isSuper);++ $this->service->notifyAboutNote(+ userIdList: $filteredUserIdList,+ note: $note,+ params: $params,+ notifyParams: $notifyParams,+ );}private function afterSaveTargetUsers(Note $note): voiddiff --git a/application/Espo/Tools/Notification/NoteNotifyParams.php b/application/Espo/Tools/Notification/NoteNotifyParams.phpnew file mode 100644index 0000000000..14bf911847--- /dev/null+++ b/application/Espo/Tools/Notification/NoteNotifyParams.php@@ -0,0 +1,40 @@+<?php+/************************************************************************+ * This file is part of EspoCRM.+ *+ * EspoCRM – Open Source CRM application.+ * Copyright (C) 2014-2026 EspoCRM, Inc.+ * Website: https://www.espocrm.com+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * The interactive user interfaces in modified source and object code versions+ * of this program must display Appropriate Legal Notices, as required under+ * Section 5 of the GNU Affero General Public License version 3.+ *+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.+ ************************************************************************/++namespace Espo\Tools\Notification;++/**+ * @since 10.0.1+ */+readonly class NoteNotifyParams+{+ public function __construct(+ public bool $isSuper = false,+ ) {}+}diff --git a/application/Espo/Tools/Notification/Service.php b/application/Espo/Tools/Notification/Service.phpindex 493df4e9e2..46d66d38cd 100644--- a/application/Espo/Tools/Notification/Service.php+++ b/application/Espo/Tools/Notification/Service.php@@ -69,10 +69,15 @@ class Service/*** @param string[] $userIdList- * @param ?Params $params Parameters. As of v9.2.0.+ * @param ?Params $params Hook parameters. As of v9.2.0.+ * @param ?NoteNotifyParams $notifyParams Parameters. As of v10.0.1.*/- public function notifyAboutNote(array $userIdList, Note $note, ?Params $params = null): void- {+ public function notifyAboutNote(+ array $userIdList,+ Note $note,+ ?Params $params = null,+ ?NoteNotifyParams $notifyParams = null,+ ): void {$related = null;if ($note->getRelatedType() === Email::ENTITY_TYPE) {@@ -134,6 +139,14 @@ class Service$actionId = null;}+ $relatedParent = $note->getParentType() && $note->getParentId() ?+ LinkParent::create($note->getParentType(), $note->getParentId()) : null;++ if ($notifyParams?->isSuper) {+ $relatedParent = $note->getSuperParentType() && $note->getSuperParentId() ?+ LinkParent::create($note->getSuperParentType(), $note->getSuperParentId()) : null;+ }+$notification = $this->entityManager->getRDBRepositoryByClass(Notification::class)->getNew();$notification@@ -143,10 +156,7 @@ class Service->setType(Notification::TYPE_NOTE)->setUserId($user->getId())->setRelated(LinkParent::fromEntity($note))- ->setRelatedParent(- $note->getParentType() && $note->getParentId() ?- LinkParent::create($note->getParentType(), $note->getParentId()) : null- )+ ->setRelatedParent($relatedParent)->setActionId($actionId)->setIsFeatured($isFeatured);