Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/api/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💡 correctness]
Consider using localeCompare for case-insensitive comparison instead of toLowerCase(), as it may handle locale-specific cases more accurately.

) {
await this.addUserToGroupByDescription(
prisma,
nextUserId,
WIPRO_ALL_GROUP_NAME,
);
}

return createdUser;
});
Expand Down Expand Up @@ -2392,6 +2403,34 @@ export class UserService {
}
}

private async addUserToGroupByDescription(
prisma: any,
userId: number,
groupName: string,
) {
try {
const groupRecord = await prisma.security_groups.findFirst({
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ maintainability]
The prisma parameter is typed as any. Consider specifying a more precise type to leverage TypeScript's type checking and improve maintainability.

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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ design]
Consider handling the error more explicitly, such as rethrowing it or returning a specific error response, to ensure that the caller is aware of the failure.

this.logger.error(
`Unable to resolve group '${groupName}' for user ${userId}`,
error,
);
}
}

/**
* Add user to group.
* @param prisma Prisma client
Expand Down