From 025e7134fc11b0aa8f69ec53c7cee1f0b8100b32 Mon Sep 17 00:00:00 2001 From: yuri Date: Fri, 25 Dec 2015 17:01:50 +0200 Subject: [PATCH] acl changes and portal entity --- application/Espo/Controllers/Portal.php | 35 ++++++ application/Espo/Controllers/PortalRole.php | 34 ++++++ application/Espo/Core/Acl/Table.php | 113 ++++++++++++++---- application/Espo/Entities/Portal.php | 35 ++++++ application/Espo/Entities/PortalRole.php | 35 ++++++ application/Espo/Entities/Role.php | 3 +- .../Crm/Resources/metadata/app/acl.json | 12 +- .../Espo/Resources/i18n/en_US/Portal.json | 3 +- .../Espo/Resources/layouts/Portal/detail.json | 8 ++ .../layouts/Portal/relationships.json | 3 + .../Espo/Resources/metadata/app/acl.json | 106 +++++++++------- .../Resources/metadata/clientDefs/Portal.json | 12 ++ .../Resources/metadata/entityDefs/Portal.json | 7 +- frontend/client/res/templates/role/table.tpl | 2 +- .../client/src/views/role/record/table.js | 24 +++- 15 files changed, 350 insertions(+), 82 deletions(-) create mode 100644 application/Espo/Controllers/Portal.php create mode 100644 application/Espo/Controllers/PortalRole.php create mode 100644 application/Espo/Entities/Portal.php create mode 100644 application/Espo/Entities/PortalRole.php create mode 100644 application/Espo/Resources/layouts/Portal/detail.json create mode 100644 application/Espo/Resources/layouts/Portal/relationships.json create mode 100644 application/Espo/Resources/metadata/clientDefs/Portal.json diff --git a/application/Espo/Controllers/Portal.php b/application/Espo/Controllers/Portal.php new file mode 100644 index 0000000000..7a77cc1231 --- /dev/null +++ b/application/Espo/Controllers/Portal.php @@ -0,0 +1,35 @@ +mergeTableList($aclTableList); - $fieldTable = $this->mergefieldTableList($fieldTableList); + $fieldTable = $this->mergeFieldTableList($fieldTableList); + + $this->applyDefault($aclTable, $fieldTable); foreach ($this->getScopeList() as $scope) { if ($this->metadata->get('scopes.' . $scope . '.disabled')) { @@ -195,7 +197,7 @@ class Table } } - $this->applySolid($aclTable, $fieldTable); + $this->applyMandatory($aclTable, $fieldTable); } else { $aclTable = (object) []; foreach ($this->getScopeList() as $scope) { @@ -227,8 +229,15 @@ class Table $this->fillFieldTableQuickAccess(); if (!$this->user->isAdmin()) { - $this->data->assignmentPermission = $this->mergeValueList($assignmentPermissionList, $this->metadata->get('app.acl.valueDefaults.assignmentPermission', 'all')); - $this->data->userPermission = $this->mergeValueList($userPermissionList, $this->metadata->get('app.acl.valueDefaults.userPermission', 'no')); + $this->data->assignmentPermission = $this->mergeValueList($assignmentPermissionList, $this->metadata->get('app.acl.default.assignmentPermission', 'all')); + $this->data->userPermission = $this->mergeValueList($userPermissionList, $this->metadata->get('app.acl.default.userPermission', 'no')); + + if ($this->metadata->get('app.acl.mandatory.assignmentPermission')) { + $this->data->assignmentPermission = $this->metadata->get('app.acl.mandatory.assignmentPermission'); + } + if ($this->metadata->get('app.acl.mandatory.userPermission')) { + $this->data->userPermission = $this->metadata->get('app.acl.mandatory.userPermission'); + } } else { $this->data->assignmentPermission = 'all'; $this->data->userPermission = 'all'; @@ -348,7 +357,7 @@ class Table $this->data->fieldTableQuickAccess = $fieldTableQuickAccess; } - protected function applySolid(&$table, &$fieldTable) + protected function applyDefault(&$table, &$fieldTable) { if (!$this->metadata) { return; @@ -358,7 +367,64 @@ class Table return; } - $data = $this->metadata->get('app.acl.solid', array()); + $data = $this->metadata->get('app.acl.default.scopeLevel', array()); + + foreach ($data as $scope => $item) { + if (isset($table->$scope)) continue; + $value = $item; + if (is_array($item)) { + $value = (object) $item; + } + $table->$scope = $value; + } + + $fieldData = $this->metadata->get('app.acl.default.fieldLevel', array()); + + foreach ($fieldData as $scope => $s) { + foreach ($s as $field => $f) { + if (!isset($fieldTable->$scope)) { + $fieldTable->$scope = (object) []; + } + if (isset($fieldTable->$scope->$field)) continue; + $fieldTable->$scope->$field = (object) []; + foreach ($this->fieldActionList as $action) { + $level = 'no'; + if (isset($f[$action])) { + $level = $f[$action]; + } + $fieldTable->$scope->$field->$action = $level; + } + } + } + + foreach ($this->getScopeWithAclList() as $scope) { + if (!isset($table->$scope)) { + $aclType = $this->metadata->get('scopes.' . $scope . '.acl'); + if ($aclType === true) { + $aclType = 'recordAllTeamOwnNo'; + } + if (!empty($aclType)) { + $defaultValue = $this->metadata->get('app.acl.scopeLevelTypesDefaults.' . $aclType, true); + if (is_array($defaultValue)) { + $defaultValue = (object) $defaultValue; + } + $table->$scope = $defaultValue; + } + } + } + } + + protected function applyMandatory(&$table, &$fieldTable) + { + if (!$this->metadata) { + return; + } + + if ($this->user->isAdmin()) { + return; + } + + $data = $this->metadata->get('app.acl.mandatory.scopeLevel', array()); foreach ($data as $scope => $item) { $value = $item; @@ -367,6 +433,24 @@ class Table } $table->$scope = $value; } + + $fieldData = $this->metadata->get('app.acl.mandatory.fieldLevel', array()); + + foreach ($fieldData as $scope => $s) { + if (!isset($fieldTable->$scope)) { + $fieldTable->$scope = (object) []; + } + foreach ($s as $field => $f) { + $fieldTable->$scope->$field = (object) []; + foreach ($this->fieldActionList as $action) { + $level = 'no'; + if (isset($f[$action])) { + $level = $f[$action]; + } + $fieldTable->$scope->$field->$action = $level; + } + } + } } private function mergeValueList(array $list, $defaultValue) @@ -462,25 +546,10 @@ class Table } } - foreach ($scopeList as $scope) { - if (!isset($data->$scope)) { - $aclType = $this->metadata->get('scopes.' . $scope . '.acl'); - if ($aclType === true) { - $aclType = 'recordAllTeamOwnNo'; - } - if (!empty($aclType)) { - $defaultValue = $this->metadata->get('app.acl.defaults.' . $aclType, true); - if (is_array($defaultValue)) { - $defaultValue = (object) $defaultValue; - } - $data->$scope = $defaultValue; - } - } - } return $data; } - private function mergefieldTableList(array $tableList) + private function mergeFieldTableList(array $tableList) { $data = (object) []; $scopeList = $this->getScopeWithAclList(); diff --git a/application/Espo/Entities/Portal.php b/application/Espo/Entities/Portal.php new file mode 100644 index 0000000000..5449c7cbb1 --- /dev/null +++ b/application/Espo/Entities/Portal.php @@ -0,0 +1,35 @@ + -{{#if fieldTableDataList.length}} +{{#if hasFieldLevelData}}

{{translate 'Field Level' scope='Role'}}

diff --git a/frontend/client/src/views/role/record/table.js b/frontend/client/src/views/role/record/table.js index 600f0810c9..898d9fd8df 100644 --- a/frontend/client/src/views/role/record/table.js +++ b/frontend/client/src/views/role/record/table.js @@ -76,6 +76,16 @@ Espo.define('views/role/record/table', 'view', function (Dep) { data.tableDataList = this.getTableDataList(); data.fieldTableDataList = this.fieldTableDataList; + + var hasFieldLevelData = false; + this.fieldTableDataList.forEach(function (d) { + if (d.list.length) { + hasFieldLevelData = true; + return; + } + }, this); + data.hasFieldLevelData = hasFieldLevelData; + return data; }, @@ -203,10 +213,13 @@ Espo.define('views/role/record/table', 'view', function (Dep) { if (!d.entity) return; if (!(scope in this.acl.fieldData)) { - this.fieldTableDataList.push({ - name: scope, - list: [] - }); + if (this.mode === 'edit') { + this.fieldTableDataList.push({ + name: scope, + list: [] + }); + return; + } return; }; var scopeData = this.acl.fieldData[scope]; @@ -227,6 +240,9 @@ Espo.define('views/role/record/table', 'view', function (Dep) { }) }, this); + if (this.mode === 'detail') { + if (!list.length) return; + } fieldDataList.push({ name: field, list: list