mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 21:35:50 +00:00
add permission logic to nav bar.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
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
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user