diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index 8fd455e4..aa1a902b 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -143,10 +143,6 @@ export class KeycloakController extends Controller { // }); // io.getInstance()?.emit("FolderCreate", folderData); - const _roles = { - role: body.roles || [], - }; - const addRole = await this.addRole(userId, _roles); const profile = await this.profileRepo.findOne({ where: { @@ -157,6 +153,21 @@ export class KeycloakController extends Controller { if (profile) { profile.keycloak = userId; await this.profileRepo.save(profile); + if (body.roles != null && body.roles.length > 0) { + const roleKeycloak = await this.roleKeycloakRepo.find({ + where: { id: In(body.roles) }, + }); + const _profile = await this.profileRepo.findOne({ + where: { keycloak: userId }, + relations: ["roleKeycloaks"], + }); + if (_profile) { + _profile.roleKeycloaks = Array.from( + new Set([..._profile.roleKeycloaks, ...roleKeycloak]), + ); + this.profileRepo.save(_profile); + } + } } return userId; } @@ -183,7 +194,6 @@ export class KeycloakController extends Controller { // const _rolesUpdate = { // role: body.roles || [], // }; - // const addRole = await this.addRole(userId, _rolesUpdate); return chkUpdate; } @@ -498,13 +508,14 @@ export class KeycloakController extends Controller { const result = await createGroup(body.name); if (!result) throw new Error("Failed. Cannot create group."); } - + @Post("log/sso") async addLogSSO( @Request() req: RequestWithUser, - @Body() body: { - text: string, - } + @Body() + body: { + text: string; + }, ) { try { addLogSequence(req, {