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

35 lines
784 B
JavaScript
Raw Normal View History

2018-02-10 15:18:01 +00:00
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 = {};
2017-05-25 09:52:53 +00:00
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;
2017-05-25 09:52:53 +00:00
}
}
return false;
}
2017-05-25 09:52:53 +00:00
}
AclService.$inject = ['$http'];
2017-05-25 09:52:53 +00:00
ngModule.service('aclService', AclService);