New user features feature/93-user_endpoints #95

Merged
niggl merged 5 commits from feature/93-user_endpoints into dev 2021-01-13 17:30:28 +00:00
Showing only changes of commit cd7b15aadf - Show all commits

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>();