action ID

This commit is contained in:
Yuri Kuznetsov
2025-06-30 19:03:55 +03:00
parent 0a7fe37014
commit 15de70c8f7
15 changed files with 216 additions and 96 deletions
@@ -33,6 +33,7 @@ use Espo\Core\Name\Field;
use Espo\Core\Notification\AssignmentNotificatorFactory;
use Espo\Core\Notification\AssignmentNotificator;
use Espo\Core\Notification\AssignmentNotificator\Params as AssignmentNotificatorParams;
use Espo\Core\ORM\Repository\Option\SaveContext;
use Espo\Core\Utils\Metadata;
use Espo\Core\Utils\Config;
use Espo\Tools\Stream\Service as StreamService;
@@ -98,6 +99,12 @@ class HookProcessor
$params = AssignmentNotificatorParams::create()->withRawOptions($options);
$saveContext = $options[SaveContext::NAME] ?? null;
if ($saveContext instanceof SaveContext) {
$params = $params->withActionId($saveContext->getId());
}
$notificator->process($entity, $params);
}
@@ -0,0 +1,37 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* 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\HookProcessor;
readonly class Params
{
public function __construct(
public ?string $actionId = null,
) {}
}
@@ -34,6 +34,7 @@ use Espo\Core\Acl\Table;
use Espo\Core\Name\Field;
use Espo\ORM\Name\Attribute;
use Espo\Tools\Notification\HookProcessor\Params;
use Espo\Tools\Stream\Service as StreamService;
use Espo\ORM\EntityManager;
@@ -59,10 +60,10 @@ class NoteHookProcessor
private InternalAclManager $internalAclManager
) {}
public function afterSave(Note $note): void
public function afterSave(Note $note, Params $params): void
{
if ($note->getParentType() && $note->getParentId()) {
$this->afterSaveParent($note);
$this->afterSaveParent($note, $params);
return;
}
@@ -70,7 +71,7 @@ class NoteHookProcessor
$this->afterSaveNoParent($note);
}
private function afterSaveParent(Note $note): void
private function afterSaveParent(Note $note, Params $params): void
{
$parentType = $note->getParentType();
$parentId = $note->getParentId();
@@ -159,7 +160,7 @@ class NoteHookProcessor
$notifyUserIdList[] = $user->getId();
}
$this->processNotify($note, array_unique($notifyUserIdList));
$this->processNotify($note, array_unique($notifyUserIdList), $params);
}
private function afterSaveNoParent(Note $note): void
@@ -186,15 +187,13 @@ class NoteHookProcessor
if ($targetType === Note::TARGET_ALL) {
$this->afterSaveTargetAll($note);
return;
}
}
/**
* @param string[] $userIdList
*/
private function processNotify(Note $note, array $userIdList): void
private function processNotify(Note $note, array $userIdList, ?Params $params = null): void
{
$filteredUserIdList = array_filter(
$userIdList,
@@ -230,7 +229,7 @@ class NoteHookProcessor
return;
}
$this->service->notifyAboutNote($filteredUserIdList, $note);
$this->service->notifyAboutNote($filteredUserIdList, $note, $params);
}
private function afterSaveTargetUsers(Note $note): void
@@ -42,6 +42,7 @@ use Espo\Core\Utils\DateTime as DateTimeUtil;
use Espo\Modules\Crm\Entities\CaseObj;
use Espo\ORM\EntityManager;
use Espo\ORM\Name\Attribute;
use Espo\Tools\Notification\HookProcessor\Params;
class Service
{
@@ -67,8 +68,9 @@ class Service
/**
* @param string[] $userIdList
* @param ?Params $params Parameters. As of v9.2.0.
*/
public function notifyAboutNote(array $userIdList, Note $note): void
public function notifyAboutNote(array $userIdList, Note $note, ?Params $params = null): void
{
$related = null;
@@ -134,7 +136,8 @@ class Service
->setRelatedParent(
$note->getParentType() && $note->getParentId() ?
LinkParent::create($note->getParentType(), $note->getParentId()) : null
);
)
->setActionId($params?->actionId);
$collection[] = $notification;
}