email to task originalEmailId

This commit is contained in:
Yuri Kuznetsov
2024-10-10 18:42:48 +03:00
parent 150677be0b
commit 94065bfa34
3 changed files with 76 additions and 1 deletions
@@ -0,0 +1,72 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 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\Modules\Crm\Classes\RecordHooks\Task;
use Espo\Core\Acl;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Record\Hook\SaveHook;
use Espo\Entities\Email;
use Espo\Modules\Crm\Entities\Task;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
/**
* @implements SaveHook<Task>
*/
class BeforeCreate implements SaveHook
{
public function __construct(
private Acl $acl,
private EntityManager $entityManager,
) {}
public function process(Entity $entity): void
{
/** @var ?string $emailId */
$emailId = $entity->get('originalEmailId');
if ($emailId === null) {
return;
}
$email = $this->entityManager->getRDBRepositoryByClass(Email::class)->getById($emailId);
if (!$email) {
throw new BadRequest("Email record not found.");
}
if (!$this->acl->checkEntityRead($entity)) {
throw new Forbidden("No access to email.");
}
$entity->set('emailId', $emailId);
}
}
@@ -4,5 +4,8 @@
],
"saverClassNameList": [
"Espo\\Core\\FieldProcessing\\Reminder\\Saver"
],
"beforeCreateHookClassNameList": [
"Espo\\Modules\\Crm\\Classes\\RecordHooks\\Task\\BeforeCreate"
]
}
+1 -1
View File
@@ -357,7 +357,7 @@ class EmailDetailView extends DetailView {
attributes.parentId = this.model.get('parentId');
attributes.parentName = this.model.get('parentName');
attributes.parentType = this.model.get('parentType');
attributes.emailId = this.model.id;
attributes.originalEmailId = this.model.id;
const subject = this.model.get('name');