From 4e31fc89d487bea4759e37efd91ef3d2cb88b60f Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 12 Oct 2022 18:35:43 +0300 Subject: [PATCH] email filter move to folder --- .../Acl/EmailFilter/OwnershipChecker.php | 25 ++-- .../Espo/Core/Mail/Account/Fetcher.php | 31 ++++- application/Espo/Core/Mail/Importer.php | 21 ++- application/Espo/Entities/EmailFilter.php | 21 +++ .../Resources/i18n/en_US/EmailFilter.json | 10 +- .../Resources/layouts/EmailFilter/detail.json | 6 +- .../layouts/EmailFilter/detailSmall.json | 6 +- .../layouts/EmailFilter/filters.json | 2 +- .../metadata/clientDefs/EmailFilter.json | 120 +++++++++++++++++- .../metadata/entityDefs/EmailFilter.json | 22 +++- application/Espo/Services/EmailFilter.php | 93 +++++++++++++- client/src/handlers/email-filter.js | 118 +++++++++++++++++ .../src/views/email-filter/fields/action.js | 23 +--- .../views/email-filter/fields/email-folder.js | 22 +--- .../views/email-filter/record/detail-small.js | 35 ----- .../src/views/email-filter/record/detail.js | 105 --------------- .../views/email-filter/record/edit-small.js | 36 ------ client/src/views/email-filter/record/edit.js | 49 ------- 18 files changed, 446 insertions(+), 299 deletions(-) create mode 100644 client/src/handlers/email-filter.js delete mode 100644 client/src/views/email-filter/record/detail-small.js delete mode 100644 client/src/views/email-filter/record/detail.js delete mode 100644 client/src/views/email-filter/record/edit-small.js delete mode 100644 client/src/views/email-filter/record/edit.js diff --git a/application/Espo/Classes/Acl/EmailFilter/OwnershipChecker.php b/application/Espo/Classes/Acl/EmailFilter/OwnershipChecker.php index b2588f1ae7..503a1278b3 100644 --- a/application/Espo/Classes/Acl/EmailFilter/OwnershipChecker.php +++ b/application/Espo/Classes/Acl/EmailFilter/OwnershipChecker.php @@ -29,7 +29,9 @@ namespace Espo\Classes\Acl\EmailFilter; +use Espo\Entities\EmailAccount; use Espo\Entities\User; +use Espo\Entities\EmailFilter; use Espo\ORM\Entity; @@ -39,41 +41,48 @@ use Espo\Core\{ }; /** - * @implements OwnershipOwnChecker<\Espo\Entities\EmailFilter> + * @implements OwnershipOwnChecker */ class OwnershipChecker implements OwnershipOwnChecker { - private $entityManager; + private EntityManager $entityManager; public function __construct(EntityManager $entityManager) { $this->entityManager = $entityManager; } + /** + * @param EmailFilter $entity + */ public function checkOwn(User $user, Entity $entity): bool { - if (!$entity->has('parentId') || !$entity->has('parentType')) { + if ($entity->isGlobal()) { return false; } - $parentType = $entity->get('parentType'); - $parentId = $entity->get('parentId'); + $parentType = $entity->getParentType(); + $parentId = $entity->getParentId(); if (!$parentType || !$parentId) { return false; } - $parent = $this->entityManager->getEntity($parentType, $parentId); + $parent = $this->entityManager->getEntityById($parentType, $parentId); if (!$parent) { return false; } - if ($parent->getEntityType() === 'User') { + if ($parent->getEntityType() === User::ENTITY_TYPE) { return $parent->getId() === $user->getId(); } - if ($parent->has('assignedUserId') && $parent->get('assignedUserId') === $user->getId()) { + if ( + $parent instanceof EmailAccount && + $parent->has('assignedUserId') && + $parent->get('assignedUserId') === $user->getId() + ) { return true; } diff --git a/application/Espo/Core/Mail/Account/Fetcher.php b/application/Espo/Core/Mail/Account/Fetcher.php index db0b095102..5606c76b3b 100644 --- a/application/Espo/Core/Mail/Account/Fetcher.php +++ b/application/Espo/Core/Mail/Account/Fetcher.php @@ -48,9 +48,12 @@ use Espo\Core\Field\DateTime as DateTimeField; use Espo\Entities\EmailFilter; use Espo\Entities\Email; +use Espo\Entities\InboundEmail; use Espo\ORM\Collection; use Espo\ORM\EntityManager; +use Espo\ORM\Query\Part\Expression; +use Espo\ORM\Query\Part\Order; use Throwable; use DateTime; @@ -392,22 +395,40 @@ class Fetcher */ private function getFilterList(Account $account): Collection { - /** @var Collection */ - return $this->entityManager + $actionList = [EmailFilter::ACTION_SKIP]; + + if ($account->getEntityType() === InboundEmail::ENTITY_TYPE) { + $actionList[] = EmailFilter::ACTION_MOVE_TO_GROUP_FOLDER; + } + + $builder = $this->entityManager ->getRDBRepository(EmailFilter::ENTITY_TYPE) ->where([ - 'action' => 'Skip', + 'action' => $actionList, 'OR' => [ [ 'parentType' => $account->getEntityType(), 'parentId' => $account->getId(), + 'action' => $actionList, ], [ 'parentId' => null, + 'action' => EmailFilter::ACTION_SKIP, ], ] - ]) - ->find(); + ]); + + if (count($actionList) > 1) { + $builder->order( + Order::createByPositionInList( + Expression::column('action'), + $actionList + ) + ); + } + + /** @var Collection */ + return $builder->find(); } private function checkFetchOnlyHeader(Storage $storage, int $id): bool diff --git a/application/Espo/Core/Mail/Importer.php b/application/Espo/Core/Mail/Importer.php index acdafc720d..8bbf78a653 100644 --- a/application/Espo/Core/Mail/Importer.php +++ b/application/Espo/Core/Mail/Importer.php @@ -31,6 +31,7 @@ namespace Espo\Core\Mail; use Espo\Core\Mail\Importer\DuplicateFinder; use Espo\Entities\Email; +use Espo\Entities\EmailFilter; use Espo\Entities\Job; use Espo\Modules\Crm\Entities\Account; use Espo\Modules\Crm\Entities\Contact; @@ -181,10 +182,18 @@ class Importer $email->setLinkMultipleColumn('users', 'folderId', $uId, $folderId); } - if ($this->filtersMatcher->findMatch($email, $filterList, true)) { + $matchedFilter = $this->filtersMatcher->findMatch($email, $filterList, true); + + if ($matchedFilter && $matchedFilter->getAction() === EmailFilter::ACTION_SKIP) { return null; } + if ($matchedFilter && $matchedFilter->getAction() === EmailFilter::ACTION_MOVE_TO_GROUP_FOLDER) { + $groupEmailFolderId = $matchedFilter->getGroupEmailFolderId(); + + $email->set('groupFolderId', $groupEmailFolderId); + } + if ( $parser->hasHeader($message, 'message-Id') && $parser->getHeader($message, 'message-Id') @@ -265,9 +274,17 @@ class Importer if (!$data->fetchOnlyHeader()) { $inlineAttachmentList = $parser->getInlineAttachmentList($message, $email); - if ($this->filtersMatcher->findMatch($email, $filterList)) { + $matchedFilter = $this->filtersMatcher->findMatch($email, $filterList); + + if ($matchedFilter && $matchedFilter->getAction() === EmailFilter::ACTION_SKIP) { return null; } + + if ($matchedFilter && $matchedFilter->getAction() === EmailFilter::ACTION_MOVE_TO_GROUP_FOLDER) { + $groupEmailFolderId = $matchedFilter->getGroupEmailFolderId(); + + $email->set('groupFolderId', $groupEmailFolderId); + } } else { $email->set('body', 'Not fetched. The email size exceeds the limit.'); diff --git a/application/Espo/Entities/EmailFilter.php b/application/Espo/Entities/EmailFilter.php index 9156ac9d2c..f413a1230b 100644 --- a/application/Espo/Entities/EmailFilter.php +++ b/application/Espo/Entities/EmailFilter.php @@ -35,6 +35,7 @@ class EmailFilter extends \Espo\Core\ORM\Entity public const ACTION_SKIP = 'Skip'; public const ACTION_MOVE_TO_FOLDER = 'Move to Folder'; + public const ACTION_MOVE_TO_GROUP_FOLDER = 'Move to Group Folder'; /** * @return self::ACTION_*|null @@ -49,6 +50,26 @@ class EmailFilter extends \Espo\Core\ORM\Entity return $this->get('emailFolderId'); } + public function getGroupEmailFolderId(): ?string + { + return $this->get('groupEmailFolderId'); + } + + public function isGlobal(): bool + { + return (bool) $this->get('isGlobal'); + } + + public function getParentType(): ?string + { + return $this->get('parentType'); + } + + public function getParentId(): ?string + { + return $this->get('parentId'); + } + public function getFrom(): ?string { return $this->get('from'); diff --git a/application/Espo/Resources/i18n/en_US/EmailFilter.json b/application/Espo/Resources/i18n/en_US/EmailFilter.json index 58001a9482..a9f4d446b2 100644 --- a/application/Espo/Resources/i18n/en_US/EmailFilter.json +++ b/application/Espo/Resources/i18n/en_US/EmailFilter.json @@ -6,7 +6,12 @@ "bodyContains": "Body Contains", "action": "Action", "isGlobal": "Is Global", - "emailFolder": "Folder" + "emailFolder": "Folder", + "groupEmailFolder": "Group Email Folder" + }, + "links": { + "emailFolder": "Folder", + "groupEmailFolder": "Group Email Folder" }, "labels": { "Create EmailFilter": "Create Email Filter", @@ -15,7 +20,8 @@ "options": { "action": { "Skip": "Ignore", - "Move to Folder": "Put in Folder" + "Move to Folder": "Put in Folder", + "Move to Group Folder": "Put in Group Folder" } }, "tooltips": { diff --git a/application/Espo/Resources/layouts/EmailFilter/detail.json b/application/Espo/Resources/layouts/EmailFilter/detail.json index 0a1c46456d..b866e056db 100644 --- a/application/Espo/Resources/layouts/EmailFilter/detail.json +++ b/application/Espo/Resources/layouts/EmailFilter/detail.json @@ -13,6 +13,9 @@ [ false, {"name": "emailFolder"} ], + [ + false, {"name": "groupEmailFolder"} + ], [ {"name": "subject", "fullWidth": true} ], @@ -21,5 +24,4 @@ ] ] } - -] \ No newline at end of file +] diff --git a/application/Espo/Resources/layouts/EmailFilter/detailSmall.json b/application/Espo/Resources/layouts/EmailFilter/detailSmall.json index 3d1d6a4264..5ae8ca83da 100644 --- a/application/Espo/Resources/layouts/EmailFilter/detailSmall.json +++ b/application/Espo/Resources/layouts/EmailFilter/detailSmall.json @@ -13,6 +13,9 @@ [ {"name": "emailFolder"} ], + [ + {"name": "groupEmailFolder"} + ], [ {"name": "from"} ], @@ -27,5 +30,4 @@ ] ] } - -] \ No newline at end of file +] diff --git a/application/Espo/Resources/layouts/EmailFilter/filters.json b/application/Espo/Resources/layouts/EmailFilter/filters.json index 278b508c38..37604de5ee 100644 --- a/application/Espo/Resources/layouts/EmailFilter/filters.json +++ b/application/Espo/Resources/layouts/EmailFilter/filters.json @@ -3,4 +3,4 @@ "action", "createdBy", "createdAt" -] \ No newline at end of file +] diff --git a/application/Espo/Resources/metadata/clientDefs/EmailFilter.json b/application/Espo/Resources/metadata/clientDefs/EmailFilter.json index 2bf48d6908..d65324f37b 100644 --- a/application/Espo/Resources/metadata/clientDefs/EmailFilter.json +++ b/application/Espo/Resources/metadata/clientDefs/EmailFilter.json @@ -1,14 +1,11 @@ { "controller": "controllers/record", + "dynamicHandler": "handlers/email-filter", "modalViews": { "edit": "views/email-filter/modals/edit" }, "recordViews": { - "list": "views/email-filter/record/list", - "detail": "views/email-filter/record/detail", - "edit": "views/email-filter/record/edit", - "editQuick": "views/email-filter/record/edit-small", - "detailQuick": "views/email-filter/record/detail-small" + "list": "views/email-filter/record/list" }, "searchPanelDisabled": false, "menu": { @@ -23,5 +20,116 @@ ] } }, - "boolFilterList": ["onlyMy"] + "boolFilterList": [ + "onlyMy" + ], + "dynamicLogic": { + "fields": { + "parent": { + "visible": { + "conditionGroup": [ + { + "attribute": "isGlobal", + "type": "isFalse" + } + ] + }, + "required": { + "conditionGroup": [ + { + "attribute": "isGlobal", + "type": "isFalse" + } + ] + } + }, + "emailFolder": { + "visible": { + "conditionGroup": [ + { + "attribute": "action", + "type": "equals", + "value": "Move to Folder" + } + ] + }, + "required": { + "conditionGroup": [ + { + "attribute": "action", + "type": "equals", + "value": "Move to Folder" + } + ] + } + }, + "groupEmailFolder": { + "visible": { + "conditionGroup": [ + { + "attribute": "action", + "type": "equals", + "value": "Move to Group Folder" + } + ] + }, + "required": { + "conditionGroup": [ + { + "attribute": "action", + "type": "equals", + "value": "Move to Group Folder" + } + ] + } + } + }, + "options": { + "action": [ + { + "conditionGroup": [ + { + "attribute": "isGlobal", + "type": "isTrue" + } + ], + "optionList": [ + "Skip" + ] + }, + { + "conditionGroup": [ + { + "attribute": "parentType", + "type": "equals", + "value": "User" + } + ], + "optionList": [ + "Skip", + "Move to Folder" + ] + }, + { + "conditionGroup": [ + { + "attribute": "parentType", + "type": "equals", + "value": "InboundEmail" + } + ], + "optionList": [ + "Skip", + "Move to Group Folder" + ] + }, + { + "conditionGroup": [], + "optionList": [ + "Skip" + ] + } + ] + } + } } diff --git a/application/Espo/Resources/metadata/entityDefs/EmailFilter.json b/application/Espo/Resources/metadata/entityDefs/EmailFilter.json index 9a61724fe4..a3986430a4 100644 --- a/application/Espo/Resources/metadata/entityDefs/EmailFilter.json +++ b/application/Espo/Resources/metadata/entityDefs/EmailFilter.json @@ -31,7 +31,8 @@ }, "isGlobal": { "type": "bool", - "tooltip": true + "tooltip": true, + "default": false }, "parent": { "type": "linkParent", @@ -40,13 +41,20 @@ "action": { "type": "enum", "default": "Skip", - "options": ["Skip", "Move to Folder"], + "options": [ + "Skip", + "Move to Folder", + "Move to Group Folder" + ], "view": "views/email-filter/fields/action" }, "emailFolder": { "type": "link", "view": "views/email-filter/fields/email-folder" }, + "groupEmailFolder": { + "type": "link" + }, "createdAt": { "type": "datetime", "readOnly": true @@ -75,11 +83,19 @@ }, "parent": { "type": "belongsToParent", - "entityList": ["User", "EmailAccount", "InboundEmail"] + "entityList": [ + "User", + "EmailAccount", + "InboundEmail" + ] }, "emailFolder": { "type": "belongsTo", "entity": "EmailFolder" + }, + "groupEmailFolder": { + "type": "belongsTo", + "entity": "GroupEmailFolder" } }, "collection": { diff --git a/application/Espo/Services/EmailFilter.php b/application/Espo/Services/EmailFilter.php index d3e46284d1..4f81439508 100644 --- a/application/Espo/Services/EmailFilter.php +++ b/application/Espo/Services/EmailFilter.php @@ -29,26 +29,113 @@ namespace Espo\Services; +use Espo\Entities\EmailAccount as EmailAccountEntity; +use Espo\Entities\EmailFilter as EmailFilterEntity; +use Espo\Entities\InboundEmail as InboundEmailEntity; +use Espo\Entities\User as UserEntity; use Espo\ORM\Entity; use Espo\Core\Exceptions\Forbidden; +use stdClass; /** - * @extends Record<\Espo\Entities\EmailFilter> + * @extends Record */ class EmailFilter extends Record { + /** + * @param EmailFilterEntity $entity + * @throws Forbidden + */ protected function beforeCreateEntity(Entity $entity, $data) { parent::beforeCreateEntity($entity, $data); - if (!$this->getAcl()->check($entity, 'edit')) { + // Check if own. + if (!$this->acl->checkEntityEdit($entity)) { throw new Forbidden(); } - if ($entity->get('isGlobal')) { + $this->controlEntityValues($entity); + } + + /** + * @param EmailFilterEntity $entity + * @throws Forbidden + */ + protected function beforeUpdateEntity(Entity $entity, $data) + { + parent::beforeUpdateEntity($entity, $data); + + $this->controlEntityValues($entity); + } + + /** + * @throws Forbidden + */ + private function controlEntityValues(EmailFilterEntity $entity): void + { + if ($entity->isGlobal()) { $entity->set('parentId', null); $entity->set('parentType', null); + + if ($entity->getAction() !== EmailFilterEntity::ACTION_SKIP) { + throw new Forbidden("Not allowed `action`."); + } + } + + if ($entity->getParentType() && !$entity->getParentId()) { + throw new Forbidden("Not allowed `parentId` value."); + } + + if ( + $entity->getParentType() === UserEntity::ENTITY_TYPE && + !in_array( + $entity->getAction(), + [ + EmailFilterEntity::ACTION_SKIP, + EmailFilterEntity::ACTION_MOVE_TO_FOLDER, + ] + ) + ) { + throw new Forbidden("Not allowed `action`."); + } + + if ( + $entity->getParentType() === InboundEmailEntity::ENTITY_TYPE && + !in_array( + $entity->getAction(), + [ + EmailFilterEntity::ACTION_SKIP, + EmailFilterEntity::ACTION_MOVE_TO_GROUP_FOLDER, + ] + ) + ) { + throw new Forbidden("Not allowed `action`."); + } + + if ( + $entity->getParentType() === EmailAccountEntity::ENTITY_TYPE && + $entity->getAction() !== EmailFilterEntity::ACTION_SKIP + ) { + throw new Forbidden("Not allowed `action`."); + } + + if ($entity->getAction() !== EmailFilterEntity::ACTION_MOVE_TO_FOLDER) { + $entity->set('emailFolderId', null); + } + + if ($entity->getAction() !== EmailFilterEntity::ACTION_MOVE_TO_GROUP_FOLDER) { + $entity->set('groupEmailFolderId', null); } } + + public function filterUpdateInput(stdClass $data): void + { + parent::filterUpdateInput($data); + + unset($data->isGlobal); + unset($data->parentId); + unset($data->parentType); + } } diff --git a/client/src/handlers/email-filter.js b/client/src/handlers/email-filter.js new file mode 100644 index 0000000000..16ccce15fa --- /dev/null +++ b/client/src/handlers/email-filter.js @@ -0,0 +1,118 @@ +/************************************************************************ + * This file is part of EspoCRM. + * + * EspoCRM - Open Source CRM application. + * Copyright (C) 2014-2022 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko + * Website: https://www.espocrm.com + * + * EspoCRM is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EspoCRM 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EspoCRM. If not, see http://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 General Public License version 3. + * + * In accordance with Section 7(b) of the GNU General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. + ************************************************************************/ + +define('handlers/email-filter', ['dynamic-handler'], (Dep) => { + + return Dep.extend({ + + init: function () { + if (this.model.isNew()) { + if (!this.recordView.getUser().isAdmin()) { + this.recordView.hideField('isGlobal'); + } + } + + if ( + !this.model.isNew() && + !this.recordView.getUser().isAdmin() && + !this.model.get('isGlobal') + ) { + this.recordView.hideField('isGlobal'); + } + + if (this.model.isNew() && !this.model.get('parentId')) { + this.model.set('parentType', 'User'); + this.model.set('parentId', this.recordView.getUser().id); + this.model.set('parentName', this.recordView.getUser().get('name')); + + if (!this.recordView.getUser().isAdmin()) { + this.recordView.setFieldReadOnly('parent'); + } + } + else if ( + this.model.get('parentType') && + !this.recordView.options.duplicateSourceId && + this.model.get('parentType') !== 'User' + ) { + this.recordView.setFieldReadOnly('parent'); + this.recordView.setFieldReadOnly('isGlobal'); + } + + this.recordView.listenTo(this.model, 'change:isGlobal', (model, value, o) => { + if (!o.ui) { + return; + } + + if (value) { + this.model.set('action', 'Skip'); + this.model.set('parentType', null); + this.model.set('parentId', null); + this.model.set('emailFolderId', null); + this.model.set('groupEmailFolderId', null); + } + }); + + this.recordView.listenTo(this.model, 'change:parentType', (model, value, o) => { + if (!o.ui) { + return; + } + + // Avoiding side effects. + setTimeout(() => { + if (value === 'EmailAccount') { + this.model.set('action', 'Skip'); + this.model.set('emailFolderId', null); + this.model.set('groupEmailFolderId', null); + + return; + } + + if (value !== 'InboundEmail') { + if (this.model.get('action') === 'Move to Group Folder') { + this.model.set('action', 'Skip'); + } + + this.model.set('groupEmailFolderId', null); + + return; + } + + if (value !== 'User') { + if (this.model.get('action') === 'Move to Folder') { + this.model.set('action', 'Skip'); + } + + this.model.set('groupFolderId', null); + + return; + } + }, 40); + }); + }, + }); +}); diff --git a/client/src/views/email-filter/fields/action.js b/client/src/views/email-filter/fields/action.js index 44146d0e96..c66aa251ad 100644 --- a/client/src/views/email-filter/fields/action.js +++ b/client/src/views/email-filter/fields/action.js @@ -28,26 +28,5 @@ define('views/email-filter/fields/action', ['views/fields/enum'], function (Dep) { - return Dep.extend({ - - setup: function () { - Dep.prototype.setup.call(this); - - this.controlActionOptions(); - - this.listenTo(this.model, 'change:parentType', this.controlActionOptions, this); - }, - - controlActionOptions: function () { - if (this.model.get('parentType') === 'User') { - this.params.options = ['Skip', 'Move to Folder']; - } else { - this.params.options = ['Skip']; - } - - if (this.isRendered()) { - this.reRender(); - } - }, - }); + return Dep.extend({}); }); diff --git a/client/src/views/email-filter/fields/email-folder.js b/client/src/views/email-filter/fields/email-folder.js index d9c9067174..d0ca605dea 100644 --- a/client/src/views/email-filter/fields/email-folder.js +++ b/client/src/views/email-filter/fields/email-folder.js @@ -25,7 +25,8 @@ * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -Espo.define('views/email-filter/fields/email-folder', 'views/fields/link', function (Dep) { + +define('views/email-filter/fields/email-folder', ['views/fields/link'], function (Dep) { return Dep.extend({ @@ -42,27 +43,12 @@ Espo.define('views/email-filter/fields/email-folder', 'views/fields/link', funct attribute: 'assignedUserId', value: this.model.get('parentId'), data: { - nameValue: this.model.get('parentName') - } + nameValue: this.model.get('parentName'), + }, } }; } } }, - - setup: function () { - Dep.prototype.setup.call(this); - - this.listenTo(this.model, 'change:parentId', function (model, e, data) { - if (data.ui) { - this.model.set({ - emailFolderId: null, - emailFolderName: null - }); - } - }, this); - } - }); - }); diff --git a/client/src/views/email-filter/record/detail-small.js b/client/src/views/email-filter/record/detail-small.js deleted file mode 100644 index 6d8d9ff8f2..0000000000 --- a/client/src/views/email-filter/record/detail-small.js +++ /dev/null @@ -1,35 +0,0 @@ -/************************************************************************ - * This file is part of EspoCRM. - * - * EspoCRM - Open Source CRM application. - * Copyright (C) 2014-2022 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko - * Website: https://www.espocrm.com - * - * EspoCRM is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * EspoCRM 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with EspoCRM. If not, see http://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 General Public License version 3. - * - * In accordance with Section 7(b) of the GNU General Public License version 3, - * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. - ************************************************************************/ - -define('views/email-filter/record/detail-small', ['views/email-filter/record/detail'], function (Dep) { - - return Dep.extend({ - - bottomView: null, - }); -}); diff --git a/client/src/views/email-filter/record/detail.js b/client/src/views/email-filter/record/detail.js deleted file mode 100644 index 98e10d1d2d..0000000000 --- a/client/src/views/email-filter/record/detail.js +++ /dev/null @@ -1,105 +0,0 @@ -/************************************************************************ - * This file is part of EspoCRM. - * - * EspoCRM - Open Source CRM application. - * Copyright (C) 2014-2022 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko - * Website: https://www.espocrm.com - * - * EspoCRM is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * EspoCRM 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with EspoCRM. If not, see http://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 General Public License version 3. - * - * In accordance with Section 7(b) of the GNU General Public License version 3, - * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. - ************************************************************************/ - -define('views/email-filter/record/detail', ['views/record/detail'], function (Dep) { - - return Dep.extend({ - - setup: function () { - Dep.prototype.setup.call(this); - - this.setupFilterFields(); - }, - - setupFilterFields: function () { - this.controlIsGlobal(); - - this.listenTo(this.model, 'change:isGlobal', (model, value, data) => { - this.controlIsGlobal(); - - if (data.ui) { - if (model.get('isGlobal')) { - this.model.set({ - parentId: null, - parentType: null, - parentName: null - }); - } else { - this.model.set('parentType', 'User'); - this.model.set('parentId', this.getUser().id); - this.model.set('parentName', this.getUser().get('name')); - } - } - }); - - if (!this.getUser().isAdmin()) { - this.setFieldReadOnly('parent'); - this.setFieldReadOnly('isGlobal'); - } - - if (this.model.isNew()) { - if (!this.model.get('parentId')) { - this.model.set('parentType', 'User'); - this.model.set('parentId', this.getUser().id); - this.model.set('parentName', this.getUser().get('name')); - } - if (!this.getUser().isAdmin()) { - this.hideField('isGlobal'); - } - - this.setFieldRequired('parent'); - } else { - this.setFieldReadOnly('isGlobal'); - this.setFieldReadOnly('parent'); - } - - - this.controlEmailFolder(); - - this.listenTo(this.model, 'change', () => { - this.controlEmailFolder(); - }); - }, - - controlIsGlobal: function () { - if (this.model.get('isGlobal')) { - this.hideField('parent'); - } else { - this.showField('parent'); - } - }, - - controlEmailFolder: function () { - if (this.model.get('action') !== 'Move to Folder' || this.model.get('parentType') !== 'User') { - this.hideField('emailFolder'); - } else { - this.showField('emailFolder'); - } - }, - }); -}); diff --git a/client/src/views/email-filter/record/edit-small.js b/client/src/views/email-filter/record/edit-small.js deleted file mode 100644 index c3ea8b86f1..0000000000 --- a/client/src/views/email-filter/record/edit-small.js +++ /dev/null @@ -1,36 +0,0 @@ -/************************************************************************ - * This file is part of EspoCRM. - * - * EspoCRM - Open Source CRM application. - * Copyright (C) 2014-2022 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko - * Website: https://www.espocrm.com - * - * EspoCRM is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * EspoCRM 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with EspoCRM. If not, see http://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 General Public License version 3. - * - * In accordance with Section 7(b) of the GNU General Public License version 3, - * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. - ************************************************************************/ - -define('views/email-filter/record/edit-small', ['views/email-filter/record/edit'], function (Dep) { - - return Dep.extend({ - - bottomView: null, - }); -}); - diff --git a/client/src/views/email-filter/record/edit.js b/client/src/views/email-filter/record/edit.js deleted file mode 100644 index c6eeb4fa9f..0000000000 --- a/client/src/views/email-filter/record/edit.js +++ /dev/null @@ -1,49 +0,0 @@ -/************************************************************************ - * This file is part of EspoCRM. - * - * EspoCRM - Open Source CRM application. - * Copyright (C) 2014-2022 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko - * Website: https://www.espocrm.com - * - * EspoCRM is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * EspoCRM 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with EspoCRM. If not, see http://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 General Public License version 3. - * - * In accordance with Section 7(b) of the GNU General Public License version 3, - * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. - ************************************************************************/ - -define('views/email-filter/record/edit', -['views/record/edit', 'views/email-filter/record/detail'], -function (Dep, Detail) { - - return Dep.extend({ - - setup: function () { - Dep.prototype.setup.call(this); - Detail.prototype.setupFilterFields.call(this); - }, - - controlIsGlobal: function () { - Detail.prototype.controlIsGlobal.call(this); - }, - - controlEmailFolder: function () { - Detail.prototype.controlEmailFolder.call(this); - }, - }); -}); -