From f5e1b7175e7fda7f8e8a93ce970c1d7f0e29b07c Mon Sep 17 00:00:00 2001 From: yuri Date: Tue, 10 Sep 2019 11:03:56 +0300 Subject: [PATCH] utils checkActionAvailability --- client/src/utils.js | 20 ++++++++++++ client/src/views/main.js | 12 +++---- client/src/views/record/list.js | 36 +++++---------------- client/src/views/record/panels-container.js | 8 ++--- 4 files changed, 37 insertions(+), 39 deletions(-) diff --git a/client/src/utils.js b/client/src/utils.js index b4bf2bf737..d8f68f3593 100644 --- a/client/src/utils.js +++ b/client/src/utils.js @@ -49,6 +49,26 @@ define('utils', [], function () { } }, + checkActionAvailability: function (helper, item) { + var config = helper.config; + + if (item.configCheck) { + var configCheck = item.configCheck; + var opposite = false; + if (configCheck.substr(0, 1) === '!') { + opposite = true; + configCheck = configCheck.substr(1); + } + var configCheckResult = config.getByPath(configCheck.split('.')); + if (opposite) { + configCheckResult = !configCheckResult; + } + if (!configCheckResult) return false; + } + + return true; + }, + checkActionAccess: function (acl, obj, item, isPrecise) { var hasAccess = true; if (item.acl) { diff --git a/client/src/views/main.js b/client/src/views/main.js index f1f64b5099..497443a014 100644 --- a/client/src/views/main.js +++ b/client/src/views/main.js @@ -87,15 +87,15 @@ define('views/main', 'view', function (Dep) { if (this.menu) { ['buttons', 'actions', 'dropdown'].forEach(function (type) { (this.menu[type] || []).forEach(function (item) { + item = Espo.Utils.clone(item); menu[type] = menu[type] || []; - if (item.configCheck) { - if (!this.getConfig().getByPath(item.configCheck.split('.'))) return; - } - if (Espo.Utils.checkActionAccess(this.getAcl(), this.model || this.scope, item)) { - menu[type].push(item); - } + + if (!Espo.Utils.checkActionAvailability(this.getHelper(), item)) return; + if (!Espo.Utils.checkActionAccess(this.getAcl(), this.model || this.scope, item)) return; + item.name = item.name || item.action; item.action = item.action || this.name; + menu[type].push(item); }, this); }, this); } diff --git a/client/src/views/record/list.js b/client/src/views/record/list.js index 359bdd7ff3..ca380086e3 100644 --- a/client/src/views/record/list.js +++ b/client/src/views/record/list.js @@ -908,20 +908,10 @@ define('views/record/list', 'view', function (Dep) { (this.getMetadata().get(['clientDefs', this.scope, 'massActionList']) || []).forEach(function (item) { var defs = this.getMetadata().get(['clientDefs', this.scope, 'massActionDefs', item]) || {}; - var acl = defs.acl; - var aclScope = defs.aclScope; - if (acl || aclScope) { - if (!this.getAcl().check(aclScope || this.scope, acl)) { - return; - } - } - var configCheck = defs.configCheck; - if (configCheck) { - var arr = configCheck.split('.'); - if (!this.getConfig().getByPath(arr)) { - return; - } - } + + if (!Espo.Utils.checkActionAvailability(this.getHelper(), defs)) return; + if (!Espo.Utils.checkActionAccess(this.getAcl(), null, defs)) return; + this.massActionList.push(item); }, this); @@ -937,20 +927,10 @@ define('views/record/list', 'view', function (Dep) { if (this.collection.url !== this.entityType) return; if (~this.massActionList.indexOf(item)) { var defs = this.getMetadata().get(['clientDefs', this.scope, 'massActionDefs', item]) || {}; - var acl = defs.acl; - var aclScope = defs.aclScope; - if (acl || aclScope) { - if (!this.getAcl().check(aclScope || this.scope, acl)) { - return; - } - } - var configCheck = defs.configCheck; - if (configCheck) { - var arr = configCheck.split('.'); - if (!this.getConfig().getByPath(arr)) { - return; - } - } + + if (!Espo.Utils.checkActionAvailability(this.getHelper(), defs)) return; + if (!Espo.Utils.checkActionAccess(this.getAcl(), null, defs)) return; + this.checkAllResultMassActionList.push(item); } }, this); diff --git a/client/src/views/record/panels-container.js b/client/src/views/record/panels-container.js index 6ebb4b510e..5763aece38 100644 --- a/client/src/views/record/panels-container.js +++ b/client/src/views/record/panels-container.js @@ -82,11 +82,9 @@ define('views/record/panels-container', 'view', function (Dep) { applyAccessToActions: function (actionList) { if (!actionList) return; actionList.forEach(function (item) { - if (item.configCheck) { - if (!this.getConfig().getByPath(item.configCheck.split('.'))) { - item.hidden = true; - return; - } + if (!Espo.Utils.checkActionAvailability(this.getHelper(), item)) { + item.hidden = true; + return; } if (Espo.Utils.checkActionAccess(this.getAcl(), this.model, item, true)) { if (item.isHiddenByAcl) {