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]
The check for userParams.profile?.provider?.toLowerCase() === WIPRO_SSO_PROVIDER assumes that userParams.profile.provider is always a string. Consider adding a type check to ensure it is a string before calling toLowerCase() to prevent potential runtime errors.

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

Choose a reason for hiding this comment

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

[⚠️ performance]
The addUserToGroupByDescription method uses prisma.security_groups.findFirst to find a group by description. Ensure that the description field is indexed in the database to optimize this query, especially if the number of groups is large.

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
Expand Down