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

42 lines
645 B
TypeScript
Raw Normal View History

2021-07-29 17:02:16 +01:00
import { Injectable } from '@angular/core';
2021-08-27 15:21:15 +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
}
2021-08-27 15:21:15 +01:00
return args.includes(this.SessionStore.user.Profile)
2021-07-29 17:02:16 +01:00
}
role(args: any) {
2021-07-29 20:40:04 +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
}
if(!UserRoleIsValid) {return false }
return true
}
}
}
}