parent
3bd4948c43
commit
aa0337ea33
|
@ -29,7 +29,7 @@ export class UserController {
|
|||
@OpenAPI({ description: 'Lists all users. <br> This includes their groups and permissions directly granted to them (if existing/associated).' })
|
||||
async getAll() {
|
||||
let responseUsers: ResponseUser[] = new Array<ResponseUser>();
|
||||
const users = await this.userRepository.find({ relations: ['permissions', 'groups'] });
|
||||
const users = await this.userRepository.find({ relations: ['permissions', 'groups', 'groups.permissions'] });
|
||||
users.forEach(user => {
|
||||
responseUsers.push(new ResponseUser(user));
|
||||
});
|
||||
|
@ -43,7 +43,7 @@ export class UserController {
|
|||
@OnUndefined(UserNotFoundError)
|
||||
@OpenAPI({ description: 'Lists all information about the user whose id got provided. <br> Please remember that only permissions granted directly to the user will show up here, not permissions inherited from groups.' })
|
||||
async getOne(@Param('id') id: number) {
|
||||
let user = await this.userRepository.findOne({ id: id }, { relations: ['permissions', 'groups'] })
|
||||
let user = await this.userRepository.findOne({ id: id }, { relations: ['permissions', 'groups', 'groups.permissions'] })
|
||||
if (!user) { throw new UserNotFoundError(); }
|
||||
return new ResponseUser(user);
|
||||
}
|
||||
|
|
|
@ -132,18 +132,20 @@ export class User extends Principal {
|
|||
* 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());
|
||||
let returnPermissions: string[] = new Array<string>();
|
||||
|
||||
if (!this.permissions) { return returnPermissions; }
|
||||
for (let permission of this.permissions) {
|
||||
returnPermissions.push(permission.toString());
|
||||
}
|
||||
|
||||
if (!this.groups) { return returnPermissions; }
|
||||
for (let group of this.groups) {
|
||||
for (let permission in group.permissions) {
|
||||
allPermissions.push(permission.toString());
|
||||
for (let permission of group.permissions) {
|
||||
returnPermissions.push(permission.toString());
|
||||
}
|
||||
}
|
||||
console.log(allPermissions)
|
||||
return Array.from(new Set(allPermissions));
|
||||
return Array.from(new Set(returnPermissions));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -91,5 +91,6 @@ export class ResponseUser extends ResponsePrincipal {
|
|||
this.profilePic = user.profilePic;
|
||||
this.groups = user.groups;
|
||||
this.permissions = user.allPermissions;
|
||||
this.groups.forEach(function (g) { delete g.permissions });
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue