This commit is contained in:
Yuri Kuznetsov
2024-02-29 17:25:08 +02:00
parent 9b3c59bfa4
commit f19952af12
10 changed files with 142 additions and 93 deletions
@@ -29,19 +29,18 @@
namespace Espo\Classes\FieldProcessing\Note;
use Espo\ORM\Entity;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Entities\Note;
use Espo\ORM\Entity;
/**
* @implements Loader<Note>
*/
class AttachmentsLoader implements Loader
class AdditionalFieldsLoader implements Loader
{
public function process(Entity $entity, Params $params): void
{
/** @var Note $entity */
$entity->loadAttachments();
$entity->loadAdditionalFields();
}
}
@@ -0,0 +1,50 @@
<?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\Classes\Record\Note;
use Espo\Core\Record\Input\Data;
use Espo\Core\Record\Input\Filter;
/**
* @noinspection PhpUnused
*/
class UpdateInputFilter implements Filter
{
public function filter(Data $data): void
{
$data->clear('parentId');
$data->clear('parentType');
$data->clear('targetType');
$data->clear('usersIds');
$data->clear('teamsIds');
$data->clear('portalsIds');
$data->clear('isGlobal');
}
}
@@ -0,0 +1,59 @@
<?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\Classes\Record\Portal;
use Espo\Core\Record\Input\Data;
use Espo\Core\Record\Input\Filter;
use Espo\Core\Utils\Config;
use Espo\Entities\User;
/**
* @noinspection PhpUnused
*/
class InputFilter implements Filter
{
public function __construct(
private User $user,
private Config $config
) {}
public function filter(Data $data): void
{
if (!$this->config->get('restrictedMode')) {
return;
}
if ($this->user->isSuperAdmin()) {
return;
}
$data->clear('customUrl');
}
}
+2 -1
View File
@@ -264,7 +264,8 @@ class Note extends Entity
{
if (
$this->getType() == self::TYPE_POST ||
$this->getType() == self::TYPE_EMAIL_RECEIVED
$this->getType() == self::TYPE_EMAIL_RECEIVED ||
$this->getType() == self::TYPE_EMAIL_SENT
) {
$this->loadAttachments();
}
@@ -0,0 +1,10 @@
{
"links": {
"teams": {
"readOnly": true
},
"users": {
"readOnly": true
}
}
}
@@ -1,6 +1,9 @@
{
"readLoaderClassNameList": [
"Espo\\Classes\\FieldProcessing\\Note\\AttachmentsLoader"
"Espo\\Classes\\FieldProcessing\\Note\\AdditionalFieldsLoader"
],
"updateInputFilterClassNameList": [
"Espo\\Classes\\Record\\Note\\UpdateInputFilter"
],
"beforeCreateHookClassNameList": [
"Espo\\Classes\\RecordHooks\\Note\\BeforeCreate"
@@ -14,6 +14,12 @@
"customUrl",
"customId"
],
"createInputFilterClassNameList": [
"Espo\\Classes\\Record\\Portal\\InputFilter"
],
"updateInputFilterClassNameList": [
"Espo\\Classes\\Record\\Portal\\InputFilter"
],
"afterUpdateHookClassNameList": [
"Espo\\Classes\\RecordHooks\\Portal\\AfterUpdate"
]
-44
View File
@@ -37,26 +37,11 @@ use Espo\Entities\Note as NoteEntity;
use Espo\Entities\User as UserEntity;
use Espo\ORM\Entity;
use stdClass;
/**
* @extends Record<NoteEntity>
*/
class Note extends Record
{
public function filterUpdateInput(stdClass $data): void
{
parent::filterUpdateInput($data);
unset($data->parentId);
unset($data->parentType);
unset($data->targetType);
unset($data->usersIds);
unset($data->teamsIds);
unset($data->portalsIds);
unset($data->isGlobal);
}
/**
* @throws BadRequest
* @throws Forbidden
@@ -205,35 +190,6 @@ class Note extends Record
}
}
public function link(string $id, string $link, string $foreignId) : void
{
if ($link === 'teams' || $link === 'users') {
throw new Forbidden();
}
parent::link($id, $link, $foreignId);
}
public function unlink(string $id, string $link, string $foreignId) : void
{
if ($link === 'teams' || $link === 'users') {
throw new Forbidden();
}
parent::unlink($id, $link, $foreignId);
}
/**
* @param NoteEntity $entity
* @return void
*/
public function loadAdditionalFields(Entity $entity)
{
parent::loadAdditionalFields($entity);
$entity->loadAdditionalFields();
}
private function getUserRepository(): UserRepository
{
/** @var UserRepository */
+3 -36
View File
@@ -29,45 +29,12 @@
namespace Espo\Services;
use Espo\Entities\Portal as PortalEntity;
use Espo\Core\Di;
use stdClass;
use Espo\Core\ORM\Entity;
/**
* @extends Record<PortalEntity>
* @extends Record<Entity>
*/
class Portal extends Record implements
Di\DataManagerAware
class Portal extends Record
{
use Di\DataManagerSetter;
protected bool $getEntityBeforeUpdate = true;
public function filterCreateInput(stdClass $data): void
{
parent::filterCreateInput($data);
$this->filterRestrictedFields($data);
}
public function filterUpdateInput(stdClass $data): void
{
parent::filterUpdateInput($data);
$this->filterRestrictedFields($data);
}
private function filterRestrictedFields(stdClass $data): void
{
if (!$this->config->get('restrictedMode')) {
return;
}
if ($this->user->isSuperAdmin()) {
return;
}
unset($data->customUrl);
}
}
@@ -31,8 +31,9 @@ namespace tests\integration\Espo\Core\Utils;
use Espo\Core\Utils\Json;
use Espo\Core\Utils\Metadata;
use tests\integration\Core\BaseTestCase;
class MetadataTest extends \tests\integration\Core\BaseTestCase
class MetadataTest extends BaseTestCase
{
private $filePath1 = 'custom/Espo/Custom/Resources/metadata/app/rebuild.json';
private $filePath2 = 'custom/Espo/Custom/Resources/metadata/recordDefs/Note.json';
@@ -45,9 +46,6 @@ class MetadataTest extends \tests\integration\Core\BaseTestCase
parent::tearDown();
}
/**
* @throws \Espo\Core\Exceptions\Error
*/
public function testAppend1()
{
$initial = $this->getMetadata()->get(['app', 'rebuild', 'actionClassNameList']);
@@ -63,7 +61,7 @@ class MetadataTest extends \tests\integration\Core\BaseTestCase
$contents2 = Json::encode(
(object) [
'readLoaderClassNameList' => [
"\\Espo\\Classes\\FieldProcessing\\Note\\AttachmentsLoader",
"\\Espo\\Classes\\FieldProcessing\\Note\\AdditionalFieldsLoader",
]
]
);
@@ -88,8 +86,8 @@ class MetadataTest extends \tests\integration\Core\BaseTestCase
$this->assertSame(
[
"Espo\\Classes\\FieldProcessing\\Note\\AttachmentsLoader",
"\\Espo\\Classes\\FieldProcessing\\Note\\AttachmentsLoader",
"Espo\\Classes\\FieldProcessing\\Note\\AdditionalFieldsLoader",
"\\Espo\\Classes\\FieldProcessing\\Note\\AdditionalFieldsLoader",
],
$metadata->get(['recordDefs', 'Note', 'readLoaderClassNameList'])
);