2018-02-10 15:18:01 +00:00
|
|
|
import ngModule from '../module';
|
2017-10-20 06:39:30 +00:00
|
|
|
|
2019-01-23 12:11:44 +00:00
|
|
|
class AclService {
|
|
|
|
constructor($http) {
|
|
|
|
this.$http = $http;
|
|
|
|
}
|
2019-10-24 10:44:36 +00:00
|
|
|
|
2019-01-23 12:11:44 +00:00
|
|
|
reset() {
|
|
|
|
this.user = null;
|
|
|
|
this.roles = null;
|
|
|
|
}
|
2019-10-24 10:44:36 +00:00
|
|
|
|
2019-01-23 12:11:44 +00:00
|
|
|
load() {
|
2023-01-23 10:29:58 +00:00
|
|
|
return this.$http.get('Accounts/acl').then(async res => {
|
2019-01-23 12:11:44 +00:00
|
|
|
this.user = res.data.user;
|
|
|
|
this.roles = {};
|
2022-12-29 12:50:49 +00:00
|
|
|
this.rolesMap = {};
|
|
|
|
res.data.roles.forEach(role => {
|
|
|
|
if (role.role)
|
|
|
|
this.rolesMap[role.role.name] = true;
|
|
|
|
});
|
|
|
|
|
2023-01-23 10:29:58 +00:00
|
|
|
this.acls = {};
|
|
|
|
await this.$http.post('Accounts/user/acl', {aclList: this.rolesMap}).then(res => {
|
|
|
|
res.data.forEach(acl => {
|
|
|
|
this.acls[acl.model] = this.acls[acl.model] || {};
|
|
|
|
this.acls[acl.model][acl.property] = this.acls[acl.model][acl.property] || {};
|
|
|
|
this.acls[acl.model][acl.property][acl.accessType] = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-01-23 12:11:44 +00:00
|
|
|
for (let role of res.data.roles) {
|
|
|
|
if (role.role)
|
|
|
|
this.roles[role.role.name] = true;
|
|
|
|
}
|
2018-03-01 09:54:02 +00:00
|
|
|
});
|
|
|
|
}
|
2019-10-24 10:44:36 +00:00
|
|
|
|
2023-01-23 10:29:58 +00:00
|
|
|
returnAcls() {
|
|
|
|
return this.acls;
|
|
|
|
}
|
|
|
|
|
|
|
|
hasAnyACL(model, property, accessType) {
|
|
|
|
if (this.acls) {
|
|
|
|
if (this.acls[model]) {
|
|
|
|
if (this.acls[model][property]) {
|
|
|
|
if (this.acls[model][property][accessType])
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2022-12-29 12:50:49 +00:00
|
|
|
}
|
|
|
|
|
2019-01-23 12:11:44 +00:00
|
|
|
hasAny(roles) {
|
|
|
|
if (this.roles) {
|
|
|
|
for (let role of roles) {
|
|
|
|
if (this.roles[role])
|
|
|
|
return true;
|
2017-05-25 09:52:53 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-23 12:11:44 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-05-25 09:52:53 +00:00
|
|
|
}
|
2019-01-23 12:11:44 +00:00
|
|
|
AclService.$inject = ['$http'];
|
2017-05-25 09:52:53 +00:00
|
|
|
|
2019-01-23 12:11:44 +00:00
|
|
|
ngModule.service('aclService', AclService);
|