permission system - permission formatting
This commit is contained in:
parent
d889f92643
commit
2f5d9d3f01
15 changed files with 352 additions and 18 deletions
|
@ -16,6 +16,8 @@ import InviteService from "../service/inviteService";
|
|||
import UserService from "../service/userService";
|
||||
import CustomRequestException from "../exceptions/customRequestException";
|
||||
import { CLUB_NAME } from "../env.defaults";
|
||||
import { CreatePermissionCommand } from "../command/permissionCommand";
|
||||
import PermissionCommandHandler from "../command/permissionCommandHandler";
|
||||
|
||||
/**
|
||||
* @description start first user
|
||||
|
@ -98,7 +100,7 @@ export async function verifyInvite(req: Request, res: Response): Promise<any> {
|
|||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function finishInvite(req: Request, res: Response): Promise<any> {
|
||||
export async function finishInvite(req: Request, res: Response, grantAdmin: boolean = false): Promise<any> {
|
||||
let mail = req.body.mail;
|
||||
let token = req.body.token;
|
||||
let totp = req.body.totp;
|
||||
|
@ -127,10 +129,23 @@ export async function finishInvite(req: Request, res: Response): Promise<any> {
|
|||
};
|
||||
let id = await UserCommandHandler.create(createUser);
|
||||
|
||||
if (grantAdmin) {
|
||||
let createPermission: CreatePermissionCommand = {
|
||||
permission: "*",
|
||||
userId: id,
|
||||
};
|
||||
await PermissionCommandHandler.create(createPermission);
|
||||
}
|
||||
|
||||
let jwtData: JWTToken = {
|
||||
userId: id,
|
||||
mail: mail,
|
||||
username: username,
|
||||
rights: [],
|
||||
firstname: firstname,
|
||||
lastname: lastname,
|
||||
permissions: {
|
||||
...(grantAdmin ? { admin: true } : {}),
|
||||
},
|
||||
};
|
||||
|
||||
let accessToken: string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue