From 7fe08f1669b24374e41f02eb0f09e58da383daa9 Mon Sep 17 00:00:00 2001 From: yuri Date: Mon, 14 Dec 2015 11:58:14 +0200 Subject: [PATCH] acl fixes --- application/Espo/Core/Acl/Base.php | 3 ++ application/Espo/Core/Acl/Table.php | 22 +++++--- .../Modules/Crm/Acl/CampaignLogRecord.php | 4 +- .../Modules/Crm/Acl/CampaignTrackingUrl.php | 4 +- .../Espo/Modules/Crm/Acl/MassEmail.php | 6 ++- .../clientDefs/CampaignLogRecord.json | 3 ++ .../clientDefs/CampaignTrackingUrl.json | 3 +- .../metadata/clientDefs/MassEmail.json | 1 + .../crm/src/acl/campaign-tracking-url.js | 49 ++++++++++++++++++ .../client/modules/crm/src/acl/mass-email.js | 51 +++++++++++++++++++ frontend/client/src/acl.js | 39 +++++++------- 11 files changed, 149 insertions(+), 36 deletions(-) create mode 100644 application/Espo/Modules/Crm/Resources/metadata/clientDefs/CampaignLogRecord.json create mode 100644 frontend/client/modules/crm/src/acl/campaign-tracking-url.js create mode 100644 frontend/client/modules/crm/src/acl/mass-email.js diff --git a/application/Espo/Core/Acl/Base.php b/application/Espo/Core/Acl/Base.php index 0782bc9360..e0fd9b04c4 100644 --- a/application/Espo/Core/Acl/Base.php +++ b/application/Espo/Core/Acl/Base.php @@ -130,6 +130,9 @@ class Base implements Injectable if ($data === true) { return true; } + if (is_string($data)) { + return true; + } if (!is_null($action)) { if (array_key_exists($action, $data)) { diff --git a/application/Espo/Core/Acl/Table.php b/application/Espo/Core/Acl/Table.php index 7b088697d0..5b579b7ac2 100644 --- a/application/Espo/Core/Acl/Table.php +++ b/application/Espo/Core/Acl/Table.php @@ -70,10 +70,8 @@ class Table if ($config && $config->get('useCache') && file_exists($this->cacheFile)) { $cached = include $this->cacheFile; $this->data = $cached; - $this->initSolid(); } else { $this->load(); - $this->initSolid(); if ($config && $fileManager && $config->get('useCache')) { $this->buildCache(); } @@ -127,7 +125,6 @@ class Table $userPermissionList = []; if (!$this->user->isAdmin()) { - $userRoles = $this->user->get('roles'); foreach ($userRoles as $role) { @@ -154,7 +151,7 @@ class Table } } - $this->data['table'] = $aclTable; + $this->applySolid($aclTable); } else { $aclTable = array(); foreach ($this->getScopeList() as $scope) { @@ -169,9 +166,18 @@ class Table } } } - $this->data['table'] = $aclTable; } + foreach ($aclTable as $scope => $data) { + if (is_string($data)) { + if (array_key_exists($data, $aclTable)) { + $aclTable[$scope] = $aclTable[$data]; + } + } + } + + $this->data['table'] = $aclTable; + if (!$this->user->isAdmin()) { $this->data['assignmentPermission'] = $this->mergeValues($assignmentPermissionList, $this->metadata->get('app.acl.valueDefaults.assignmentPermission', 'all')); $this->data['userPermission'] = $this->mergeValues($userPermissionList, $this->metadata->get('app.acl.valueDefaults.userPermission', 'no')); @@ -181,7 +187,7 @@ class Table } } - private function initSolid() + private function applySolid(&$table) { if (!$this->metadata) { return; @@ -193,8 +199,8 @@ class Table $data = $this->metadata->get('app.acl.solid', array()); - foreach ($data as $entityType => $item) { - $this->data['table'][$entityType] = $item; + foreach ($data as $scope => $item) { + $table[$scope] = $item; } } diff --git a/application/Espo/Modules/Crm/Acl/CampaignLogRecord.php b/application/Espo/Modules/Crm/Acl/CampaignLogRecord.php index 25f780947c..0fed3e65fd 100644 --- a/application/Espo/Modules/Crm/Acl/CampaignLogRecord.php +++ b/application/Espo/Modules/Crm/Acl/CampaignLogRecord.php @@ -46,7 +46,7 @@ class CampaignLogRecord extends \Espo\Core\Acl\Base return true; } } - return; + return false; } public function checkInTeam(User $user, Entity $entity) @@ -60,7 +60,7 @@ class CampaignLogRecord extends \Espo\Core\Acl\Base return true; } } - return; + return false; } } diff --git a/application/Espo/Modules/Crm/Acl/CampaignTrackingUrl.php b/application/Espo/Modules/Crm/Acl/CampaignTrackingUrl.php index 09a51d4368..c8931fd0f9 100644 --- a/application/Espo/Modules/Crm/Acl/CampaignTrackingUrl.php +++ b/application/Espo/Modules/Crm/Acl/CampaignTrackingUrl.php @@ -46,7 +46,7 @@ class CampaignTrackingUrl extends \Espo\Core\Acl\Base return true; } } - return; + return false; } public function checkInTeam(User $user, Entity $entity) @@ -60,7 +60,7 @@ class CampaignTrackingUrl extends \Espo\Core\Acl\Base return true; } } - return; + return false; } } diff --git a/application/Espo/Modules/Crm/Acl/MassEmail.php b/application/Espo/Modules/Crm/Acl/MassEmail.php index 9092daa8db..313cea1460 100644 --- a/application/Espo/Modules/Crm/Acl/MassEmail.php +++ b/application/Espo/Modules/Crm/Acl/MassEmail.php @@ -45,8 +45,9 @@ class MassEmail extends \Espo\Core\Acl\Base if ($campaign && $this->getAclManager()->getImplementation('Campaign')->checkIsOwner($user, $campaign)) { return true; } + } else { + return parent::checkIsOwner($user, $entity); } - return; } public function checkInTeam(User $user, Entity $entity) @@ -59,8 +60,9 @@ class MassEmail extends \Espo\Core\Acl\Base if ($campaign && $this->getAclManager()->getImplementation('Campaign')->checkInTeam($user, $campaign)) { return true; } + } else { + return parent::checkInTeam($user, $entity); } - return; } } diff --git a/application/Espo/Modules/Crm/Resources/metadata/clientDefs/CampaignLogRecord.json b/application/Espo/Modules/Crm/Resources/metadata/clientDefs/CampaignLogRecord.json new file mode 100644 index 0000000000..618c3f8142 --- /dev/null +++ b/application/Espo/Modules/Crm/Resources/metadata/clientDefs/CampaignLogRecord.json @@ -0,0 +1,3 @@ +{ + "acl": "crm:acl/campaign-tracking-url" +} diff --git a/application/Espo/Modules/Crm/Resources/metadata/clientDefs/CampaignTrackingUrl.json b/application/Espo/Modules/Crm/Resources/metadata/clientDefs/CampaignTrackingUrl.json index 32a4a50a15..ccb24023e6 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/clientDefs/CampaignTrackingUrl.json +++ b/application/Espo/Modules/Crm/Resources/metadata/clientDefs/CampaignTrackingUrl.json @@ -1,3 +1,4 @@ { - "controller": "controllers/record" + "controller": "controllers/record", + "acl": "crm:acl/campaign-tracking-url" } diff --git a/application/Espo/Modules/Crm/Resources/metadata/clientDefs/MassEmail.json b/application/Espo/Modules/Crm/Resources/metadata/clientDefs/MassEmail.json index 232baff200..295144b882 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/clientDefs/MassEmail.json +++ b/application/Espo/Modules/Crm/Resources/metadata/clientDefs/MassEmail.json @@ -1,5 +1,6 @@ { "controller": "controllers/record", + "acl": "crm:acl/mass-email", "recordViews": { "detail": "crm:views/mass-email/record/detail" }, diff --git a/frontend/client/modules/crm/src/acl/campaign-tracking-url.js b/frontend/client/modules/crm/src/acl/campaign-tracking-url.js new file mode 100644 index 0000000000..927d1df23a --- /dev/null +++ b/frontend/client/modules/crm/src/acl/campaign-tracking-url.js @@ -0,0 +1,49 @@ +/************************************************************************ + * This file is part of EspoCRM. + * + * EspoCRM - Open Source CRM application. + * Copyright (C) 2014-2015 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko + * Website: http://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. + ************************************************************************/ + +Espo.define('crm:acl/campaign-tracking-url', 'acl', function (Dep) { + + return Dep.extend({ + + checkIsOwner: function (model) { + if (model.has('campaignId')) { + return true; + } + return false; + }, + + checkInTeam: function (model) { + if (model.has('campaignId')) { + return true; + } + return false; + } + }); + +}); + diff --git a/frontend/client/modules/crm/src/acl/mass-email.js b/frontend/client/modules/crm/src/acl/mass-email.js new file mode 100644 index 0000000000..28749adce8 --- /dev/null +++ b/frontend/client/modules/crm/src/acl/mass-email.js @@ -0,0 +1,51 @@ +/************************************************************************ + * This file is part of EspoCRM. + * + * EspoCRM - Open Source CRM application. + * Copyright (C) 2014-2015 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko + * Website: http://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. + ************************************************************************/ + +Espo.define('crm:acl/mass-email', 'acl', function (Dep) { + + return Dep.extend({ + + checkIsOwner: function (model) { + if (model.has('campaignId')) { + return true; + } else { + return Dep.prototype.checkIsOwner.call(this, model); + } + }, + + checkInTeam: function (model) { + if (model.has('campaignId')) { + return true; + } else { + return Dep.prototype.checkInTeam.call(this, model); + } + } + }); + +}); + diff --git a/frontend/client/src/acl.js b/frontend/client/src/acl.js index 97529afcf8..958b348579 100644 --- a/frontend/client/src/acl.js +++ b/frontend/client/src/acl.js @@ -26,15 +26,6 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ - -/** * Example: - * Lead: { - * edit: 'own', - * read: 'team', - * delete: 'no', - * } - */ - Espo.define('acl', [], function () { var Acl = function (user, scope) { @@ -78,7 +69,7 @@ Espo.define('acl', [], function () { return true; } - if (value == 'no') { + if (value === 'no') { return false; } @@ -96,33 +87,39 @@ Espo.define('acl', [], function () { } } + var result = false; + if (value === 'team') { + result = inTeam; if (inTeam === null) { if (precise) { - return null; + result = null; } else { return true; } + } else if (inTeam) { + return true; + } + } + + if (isOwner === null) { + if (precise) { + result = null; } else { - return inTeam; + return true; } } - if (value === 'own' || value === 'team') { - if (isOwner === null) { - if (precise) { - return null; - } - } - } - - return false; + return result; } } return true; }, checkModel: function (model, data, action, precise) { + if (this.getUser().isAdmin()) { + return true; + } return this.checkScope(data, action, precise, this.checkIsOwner(model), this.checkInTeam(model)); },