Files
doneit-web/src/app/services/permission.service.ts
T

59 lines
897 B
TypeScript
Raw Normal View History

2021-07-29 17:02:16 +01:00
import { Injectable } from '@angular/core';
2022-03-28 15:46:07 +01:00
import { SessionStore } from '../store/session.service';
2021-07-29 17:02:16 +01:00
@Injectable({
providedIn: 'root'
})
export class PermissionService {
2021-08-27 15:21:15 +01:00
SessionStore = SessionStore
2021-07-29 17:02:16 +01:00
constructor() { }
userRole(args) {
2021-08-05 11:47:09 +01:00
if(!Array.isArray(args)) {
args = [args]
2021-07-29 17:02:16 +01:00
}
2022-03-28 15:46:07 +01:00
return args.includes(this.SessionStore.user.Profile)
}
userPermission(args) {
if(!Array.isArray(args)) {
args = [args]
}
2022-03-28 21:47:10 +01:00
2022-03-29 16:48:24 +01:00
for(let permission of (this.SessionStore.user.UserPermissions || [])) {
if (args.includes(permission)) {
2022-03-28 15:46:07 +01:00
return true;
}
}
2022-03-28 22:10:08 +01:00
return false;
2022-03-28 15:46:07 +01:00
2021-07-29 17:02:16 +01:00
}
role(args: any) {
2022-03-28 15:46:07 +01:00
2021-07-29 17:02:16 +01:00
let UserRoleIsValid = this.userRole(args)
return {
permissionAnyOf(role) {
2021-07-29 20:40:04 +01:00
2021-08-05 11:47:09 +01:00
if(!Array.isArray(role)) {
role = [role]
2021-07-29 17:02:16 +01:00
}
2022-03-29 16:48:24 +01:00
if(!UserRoleIsValid) { return false }
2021-07-29 17:02:16 +01:00
return true
}
}
}
2022-03-28 15:46:07 +01:00
}