Separado aclService en fichero propio

This commit is contained in:
Dani Herrero 2017-05-25 11:52:53 +02:00
parent 81f9de098d
commit fd3dd56542
3 changed files with 30 additions and 25 deletions

View File

@ -0,0 +1,28 @@
import ngModule from './module';
function aclService() {
this.roles = window.Salix.acl.roles;
this.routeHasPermission = function(route) {
let hasPermission;
if (!route.acl)
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++) {
if (this.roles[aclCollection[i]]) {
hasPermission = true;
break;
}
}
return hasPermission;
};
}
ngModule.service('aclService', aclService);

View File

@ -1,5 +1,6 @@
import './module';
import './spliting';
import './aclService';
import './configroutes';
import './config';
import './run';

View File

@ -76,28 +76,4 @@ function interceptorConfig($httpProvider) {
}
ngModule.config(interceptorConfig);
function aclService() {
this.roles = window.Salix.acl.roles;
this.routeHasPermission = function(route) {
let hasPermission;
if (!route.acl)
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++) {
if (this.roles[aclCollection[i]]) {
hasPermission = true;
break;
}
}
return hasPermission;
};
}
ngModule.service('aclService', aclService);