Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat: addressed grepy comment

=2e9bbd5a5c15
diff --git a/backend/src/ee/services/scim/scim-service.ts b/backend/src/ee/services/scim/scim-service.ts
index 55415a2fb7..488dc2651f 100644
--- a/backend/src/ee/services/scim/scim-service.ts
+++ b/backend/src/ee/services/scim/scim-service.ts
@@ -1498,18 +1498,38 @@ export const scimServiceFactory = ({
}
if (group.name !== displayName) {
- const conflictingGroup = await groupDAL.findOne({ name: displayName, orgId }, tx);
- if (conflictingGroup) {
- throw new ScimRequestError({
- detail: `Group with name '${displayName}' already exists in the organization`,
- status: 409,
- scimType: "uniqueness"
+ const previousName = group.name;
+ // The group lock is per group, so two renames onto one name can race; the unique index
+ // on (orgId, name) is what decides, and its violation is the conflict.
+ const [modifiedGroup] = await groupDAL
+ .update(
+ {
+ id: groupId,
+ orgId
+ },
+ {
+ name: displayName
+ },
+ tx
+ )
+ .catch((err: unknown) => {
+ if (
+ err instanceof DatabaseError &&
+ (err.error as { code?: string })?.code === DatabaseErrorCode.UniqueViolation
+ ) {
+ throw new ScimRequestError({
+ detail: `Group with name '${displayName}' already exists in the organization`,
+ status: 409,
+ scimType: "uniqueness",
+ error: err
+ });
+ }
+ throw err;
});
- }
await externalGroupOrgRoleMappingDAL.update(
{
- groupName: group.name,
+ groupName: previousName,
orgId
},
{
@@ -1518,17 +1538,6 @@ export const scimServiceFactory = ({
tx
);
- const [modifiedGroup] = await groupDAL.update(
- {
- id: groupId,
- orgId
- },
- {
- name: displayName
- },
- tx
- );
-
group = modifiedGroup;
}