Skip to content

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

fix: remove old code

IgorHorta949cd1896235
diff --git a/backend/src/ee/services/group/group-dal.ts b/backend/src/ee/services/group/group-dal.ts
index 149560c42b..b76688928c 100644
--- a/backend/src/ee/services/group/group-dal.ts
+++ b/backend/src/ee/services/group/group-dal.ts
@@ -603,18 +603,22 @@ export const groupDALFactory = (db: TDbClient) => {
}
};
- /**
- * Returns the groups that reference the given group via sourceGroupId (self-referential FK).
- * Used to block delete when this group is the source of linked/copied groups; error message can list them.
- */
- const getGroupsReferencingGroup = async (groupId: string, tx?: Knex): Promise<{ id: string; name: string }[]> => {
+ // Check if a group is linked by any sub-orgs (used to prevent deletion of groups still in use)
+ const getGroupsReferencingGroup = async (groupId: string, tx?: Knex) => {
try {
- const docs = await (tx || db.replicaNode())(TableName.Groups)
- .whereRaw('"sourceGroupId" = ?', [groupId])
- .select("id", "name");
+ const docs = await (tx || db.replicaNode())(TableName.Membership)
+ .where(`${TableName.Membership}.actorGroupId`, groupId)
+ .where(`${TableName.Membership}.scope`, AccessScope.Organization)
+ .join(TableName.Groups, `${TableName.Groups}.id`, `${TableName.Membership}.actorGroupId`)
+ .whereNot(`${TableName.Membership}.scopeOrgId`, db.ref("orgId").withSchema(TableName.Groups))
+ .join(TableName.Organization, `${TableName.Organization}.id`, `${TableName.Membership}.scopeOrgId`)
+ .select(
+ db.ref("id").withSchema(TableName.Organization).as("orgId"),
+ db.ref("name").withSchema(TableName.Organization).as("orgName")
+ );
return docs;
} catch (error) {
- throw new DatabaseError({ error, name: "Get groups referencing group" });
+ throw new DatabaseError({ error, name: "GetGroupsReferencingGroup" });
}
};
diff --git a/backend/src/ee/services/group/group-service.ts b/backend/src/ee/services/group/group-service.ts
index a3f746b6ab..5ee6398082 100644
--- a/backend/src/ee/services/group/group-service.ts
+++ b/backend/src/ee/services/group/group-service.ts
@@ -339,11 +339,11 @@ export const groupServiceFactory = ({
return group;
}
- const referencingGroups = await groupDAL.getGroupsReferencingGroup(id);
- if (referencingGroups.length > 0) {
- const groupList = referencingGroups.map((g) => `"${g.name}"`).join(", ");
+ const referencingSubOrgs = await groupDAL.getGroupsReferencingGroup(id);
+ if (referencingSubOrgs.length > 0) {
+ const orgList = referencingSubOrgs.map((o) => `"${o.orgName}"`).join(", ");
throw new BadRequestError({
- message: `Cannot delete this group because it is used as a source by other groups. Unlink or delete these groups first: ${groupList}.`
+ message: `Cannot delete this group because it is linked by sub-organizations. Unlink it from these sub-organizations first: ${orgList}.`
});
}