Files
doneit-web/src/app/services/permission.service.ts
T
Peter Maquiran 3598d7c851 fix
2022-03-28 22:10:08 +01:00

59 lines
894 B
TypeScript

import { Injectable } from '@angular/core';
import { SessionStore } from '../store/session.service';
@Injectable({
providedIn: 'root'
})
export class PermissionService {
SessionStore = SessionStore
constructor() { }
userRole(args) {
if(!Array.isArray(args)) {
args = [args]
}
return args.includes(this.SessionStore.user.Profile)
}
userPermission(args) {
if(!Array.isArray(args)) {
args = [args]
}
for(let permission of (this.SessionStore.user.UserPermissions || [])){
if (args.includes(permission)){
return true;
}
}
return false;
}
role(args: any) {
let UserRoleIsValid = this.userRole(args)
return {
permissionAnyOf(role) {
if(!Array.isArray(role)) {
role = [role]
}
if(!UserRoleIsValid) {return false }
return true
}
}
}
}