2018-02-10 15:18:01 +00:00
|
|
|
import ngModule from '../module';
|
2017-10-20 06:39:30 +00:00
|
|
|
|
|
|
|
var acl = window.salix ? window.salix.acl : {};
|
2018-02-10 15:18:01 +00:00
|
|
|
ngModule.constant('aclConstant', acl);
|
2017-05-25 09:52:53 +00:00
|
|
|
|
2017-05-31 07:46:05 +00:00
|
|
|
aclService.$inject = ['aclConstant'];
|
|
|
|
function aclService(aclConstant) {
|
2018-03-01 09:54:02 +00:00
|
|
|
if (aclConstant.roles) {
|
|
|
|
this.roles = {};
|
|
|
|
Object.keys(aclConstant.roles).forEach(role => {
|
|
|
|
this.roles[role.toLowerCase()] = aclConstant.roles[role];
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.roles = undefined;
|
|
|
|
}
|
2017-05-31 07:46:05 +00:00
|
|
|
|
2017-05-25 09:52:53 +00:00
|
|
|
this.routeHasPermission = function(route) {
|
|
|
|
let hasPermission;
|
2017-05-31 07:46:05 +00:00
|
|
|
if (!this.roles)
|
|
|
|
hasPermission = false;
|
|
|
|
else if (!route.acl)
|
2017-05-25 09:52:53 +00:00
|
|
|
hasPermission = true;
|
|
|
|
else if (!this.roles || !Object.keys(this.roles).length)
|
|
|
|
hasPermission = false;
|
|
|
|
else
|
|
|
|
hasPermission = this.aclPermission(route.acl);
|
|
|
|
return hasPermission;
|
|
|
|
};
|
|
|
|
this.aclPermission = function(aclCollection) {
|
|
|
|
let hasPermission = false;
|
|
|
|
let total = aclCollection.length;
|
|
|
|
for (let i = 0; i < total; i++) {
|
2018-03-01 09:54:02 +00:00
|
|
|
let role = aclCollection[i].trim().toLowerCase();
|
|
|
|
if (this.roles[role]) {
|
2017-05-25 09:52:53 +00:00
|
|
|
hasPermission = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hasPermission;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-02-10 15:18:01 +00:00
|
|
|
ngModule.service('aclService', aclService);
|