src/app/core/auth/permissions.service.ts
Properties |
|
Methods |
isAllow | ||||||||
isAllow(action: Action)
|
||||||||
Defined in src/app/core/auth/permissions.service.ts:23
|
||||||||
Parameters :
Returns :
boolean
|
isDeny | ||||||||
isDeny(action: Action)
|
||||||||
Defined in src/app/core/auth/permissions.service.ts:31
|
||||||||
Parameters :
Returns :
boolean
|
isSomeAllow | ||||||||
isSomeAllow(actions: Action[])
|
||||||||
Defined in src/app/core/auth/permissions.service.ts:27
|
||||||||
Parameters :
Returns :
any
|
setPermissions | ||||||||
setPermissions(permissions: Permission[])
|
||||||||
Defined in src/app/core/auth/permissions.service.ts:17
|
||||||||
Parameters :
Returns :
void
|
Public actions |
actions:
|
Default value : Actions
|
Defined in src/app/core/auth/permissions.service.ts:15
|
Public changes |
changes:
|
Default value : this.permissionsSubject.asObservable()
|
Defined in src/app/core/auth/permissions.service.ts:14
|
Private permissions |
permissions:
|
Type : literal type
|
Default value : {}
|
Defined in src/app/core/auth/permissions.service.ts:11
|
Private permissionsSubject |
permissionsSubject:
|
Default value : new Subject()
|
Defined in src/app/core/auth/permissions.service.ts:12
|
import {Injectable} from "@angular/core";
import {Permission} from "../models/auth/permission.model";
import {Action, Actions} from "../models/auth/action.type";
import {PermissionStates} from "../models/auth/permission-state.type";
import {Subject} from "rxjs";
@Injectable()
export class PermissionsService {
private permissions: {[action: string]: Permission} = {};
private permissionsSubject = new Subject();
public changes = this.permissionsSubject.asObservable();
public actions = Actions;
setPermissions(permissions: Permission[]) {
this.permissions = {};
permissions.forEach(permission => this.permissions[permission.action] = permission);
this.permissionsSubject.next();
}
isAllow(action: Action): boolean {
return this.permissions[action] && this.permissions[action].state === PermissionStates.Allow;
}
isSomeAllow(...actions: Action[]) {
return actions.some(this.isAllow)
}
isDeny(action: Action): boolean {
return !this.permissions[action] || this.permissions[action].state === PermissionStates.Deny;
}
}