From 29238f01ccc1793b92539a22c604714fa5549d95 Mon Sep 17 00:00:00 2001 From: Justin Gasper Date: Sun, 2 Nov 2025 22:51:23 +1100 Subject: [PATCH] Add wipro users to "Wipro - All" group --- src/api/user/user.service.ts | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/api/user/user.service.ts b/src/api/user/user.service.ts index 8c259a8..22b79b1 100644 --- a/src/api/user/user.service.ts +++ b/src/api/user/user.service.ts @@ -64,6 +64,8 @@ export const ACTIVATION_OTP_EXPIRY_SECONDS = 24 * 60 * 60; // 24 hours export const ACTIVATION_OTP_LENGTH = 6; const OTP_ACTIVATION_MODE = 1; const ACTIVATION_OTP_EXPIRY_MINUTES = 24 * 60; +const WIPRO_SSO_PROVIDER = 'wipro-adfs'; +const WIPRO_ALL_GROUP_NAME = 'Wipro - All'; @Injectable() export class UserService { @@ -828,6 +830,15 @@ export class UserService { // add user to initial groups await this.addUserToDefaultGroups(prisma, nextUserId); + if ( + userParams.profile?.provider?.toLowerCase() === WIPRO_SSO_PROVIDER + ) { + await this.addUserToGroupByDescription( + prisma, + nextUserId, + WIPRO_ALL_GROUP_NAME, + ); + } return createdUser; }); @@ -2392,6 +2403,34 @@ export class UserService { } } + private async addUserToGroupByDescription( + prisma: any, + userId: number, + groupName: string, + ) { + try { + const groupRecord = await prisma.security_groups.findFirst({ + where: { description: groupName }, + }); + if (!groupRecord) { + this.logger.warn( + `Group '${groupName}' not found when assigning user ${userId}.`, + ); + return; + } + await this.addUserToGroup( + prisma, + userId, + Number(groupRecord.group_id), + ); + } catch (error) { + this.logger.error( + `Unable to resolve group '${groupName}' for user ${userId}`, + error, + ); + } + } + /** * Add user to group. * @param prisma Prisma client