utils checkActionAvailability
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user