First part of resolving user inherited permissions

ref #93
This commit is contained in:
Nicolai Ort 2021-01-13 17:57:42 +01:00
parent 37fc167002
commit cd7b15aadf
1 changed files with 17 additions and 0 deletions

View File

@ -3,6 +3,7 @@ import { ChildEntity, Column, JoinTable, ManyToMany, OneToMany } from "typeorm";
import { config } from '../../config';
import { ResponsePrincipal } from '../responses/ResponsePrincipal';
import { ResponseUser } from '../responses/ResponseUser';
import { Permission } from './Permission';
import { Principal } from './Principal';
import { UserAction } from './UserAction';
import { UserGroup } from './UserGroup';
@ -129,8 +130,24 @@ export class User extends Principal {
@OneToMany(() => UserAction, action => action.user, { nullable: true })
actions: UserAction[]
/**
* Resolves all permissions granted to this user through groups.
*/
public get inheritedPermissions(): Permission[] {
let returnPermissions: Permission[] = new Array<Permission>();
if (!this.groups) { return returnPermissions; }
for (let group of this.groups) {
for (let permission of group.permissions) {
returnPermissions.push(permission);
}
}
return returnPermissions;
}
/**
* Resolves all permissions granted to this user through groups or directly to the string enum format.
* Also deduplicates the array.
*/
public get allPermissions(): string[] {
let returnPermissions: string[] = new Array<string>();