salix/front/core/services/acl-service.js

38 lines
787 B
JavaScript

import ngModule from '../module';
class AclService {
constructor($http) {
this.$http = $http;
}
reset() {
this.user = null;
this.roles = null;
}
load() {
return this.$http.get('/api/Accounts/acl').then(res => {
this.user = res.data.user;
this.roles = {};
for (let role of res.data.roles) {
if (role.role)
this.roles[role.role.name] = true;
}
});
}
hasAny(roles) {
if (this.roles) {
for (let role of roles) {
if (this.roles[role])
return true;
}
}
return false;
}
}
AclService.$inject = ['$http'];
ngModule.service('aclService', AclService);