parent
3c37aafe1f
commit
a2c3dfbf85
@ -27,7 +27,7 @@ export class RunnerController {
|
|||||||
@OpenAPI({ description: 'Lists all runners from all teams/orgs. <br> This includes the runner\'s group and distance ran.' })
|
@OpenAPI({ description: 'Lists all runners from all teams/orgs. <br> This includes the runner\'s group and distance ran.' })
|
||||||
async getAll() {
|
async getAll() {
|
||||||
let responseRunners: ResponseRunner[] = new Array<ResponseRunner>();
|
let responseRunners: ResponseRunner[] = new Array<ResponseRunner>();
|
||||||
const runners = await this.runnerRepository.find({ relations: ['scans', 'group'] });
|
const runners = await this.runnerRepository.find({ relations: ['scans', 'group', 'group.permissions', 'permissions'] });
|
||||||
runners.forEach(runner => {
|
runners.forEach(runner => {
|
||||||
responseRunners.push(new ResponseRunner(runner));
|
responseRunners.push(new ResponseRunner(runner));
|
||||||
});
|
});
|
||||||
|
@ -106,23 +106,6 @@ export class JwtUser {
|
|||||||
this.refreshTokenCount = user.refreshTokenCount;
|
this.refreshTokenCount = user.refreshTokenCount;
|
||||||
this.uuid = user.uuid;
|
this.uuid = user.uuid;
|
||||||
this.profilePic = user.profilePic;
|
this.profilePic = user.profilePic;
|
||||||
this.permissions = this.getPermissions(user);
|
this.permissions = user.allPermissions;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handels getting the permissions granted to this user (direct or indirect).
|
|
||||||
* @param user User which's permissions shall be gotten.
|
|
||||||
*/
|
|
||||||
public getPermissions(user: User): string[] {
|
|
||||||
let returnPermissions: string[] = new Array<string>();
|
|
||||||
for (let permission of user.permissions) {
|
|
||||||
returnPermissions.push(permission.toString());
|
|
||||||
}
|
|
||||||
for (let group of user.groups) {
|
|
||||||
for (let permission of group.permissions) {
|
|
||||||
returnPermissions.push(permission.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Array.from(new Set(returnPermissions));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -128,6 +128,24 @@ export class User extends Principal {
|
|||||||
@OneToMany(() => UserAction, action => action.user, { nullable: true })
|
@OneToMany(() => UserAction, action => action.user, { nullable: true })
|
||||||
actions: UserAction[]
|
actions: UserAction[]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves all permissions granted to this user through groups or directly to the string enum format.
|
||||||
|
*/
|
||||||
|
public get allPermissions(): string[] {
|
||||||
|
let allPermissions = new Array<string>();
|
||||||
|
for (let permission in this.permissions) {
|
||||||
|
allPermissions.push(permission.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let group of this.groups) {
|
||||||
|
for (let permission in group.permissions) {
|
||||||
|
allPermissions.push(permission.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(allPermissions)
|
||||||
|
return Array.from(new Set(allPermissions));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turns this entity into it's response class.
|
* Turns this entity into it's response class.
|
||||||
*/
|
*/
|
||||||
|
@ -5,7 +5,6 @@ import {
|
|||||||
IsOptional,
|
IsOptional,
|
||||||
IsString
|
IsString
|
||||||
} from "class-validator";
|
} from "class-validator";
|
||||||
import { Permission } from '../entities/Permission';
|
|
||||||
import { User } from '../entities/User';
|
import { User } from '../entities/User';
|
||||||
import { UserGroup } from '../entities/UserGroup';
|
import { UserGroup } from '../entities/UserGroup';
|
||||||
import { ResponsePrincipal } from './ResponsePrincipal';
|
import { ResponsePrincipal } from './ResponsePrincipal';
|
||||||
@ -74,7 +73,7 @@ export class ResponseUser extends ResponsePrincipal {
|
|||||||
*/
|
*/
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
permissions: Permission[];
|
permissions: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a ResponseUser object from a user.
|
* Creates a ResponseUser object from a user.
|
||||||
@ -91,6 +90,6 @@ export class ResponseUser extends ResponsePrincipal {
|
|||||||
this.enabled = user.enabled;
|
this.enabled = user.enabled;
|
||||||
this.profilePic = user.profilePic;
|
this.profilePic = user.profilePic;
|
||||||
this.groups = user.groups;
|
this.groups = user.groups;
|
||||||
this.permissions = user.permissions;
|
this.permissions = user.allPermissions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user