Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
prevent removing custom roles that are used
x032205e38ba8503f9f
diff --git a/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/ProjectTemplateRolesSection.tsx b/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/ProjectTemplateRolesSection.tsxindex e175251eec..699e36b7f3 100644--- a/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/ProjectTemplateRolesSection.tsx+++ b/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/components/EditProjectTemplateSection/components/ProjectTemplateRolesSection.tsx@@ -42,6 +42,34 @@ export const ProjectTemplateRolesSection = ({ projectTemplate, isInfisicalTemplaconst updateProjectTemplate = useUpdateProjectTemplate();const handleRemoveRole = async (slug: string) => {+ // Check if role is used by users, groups, or identities+ const usersWithRole = projectTemplate.users?.filter((u) => u.roles.includes(slug)) || [];+ const groupsWithRole = projectTemplate.groups?.filter((g) => g.roles.includes(slug)) || [];+ const identitiesWithRole =+ projectTemplate.identities?.filter((i) => i.roles.includes(slug)) || [];+ const projectManagedIdentitiesWithRole =+ projectTemplate.projectManagedIdentities?.filter((i) => i.roles.includes(slug)) || [];++ const usageMessages: string[] = [];++ if (usersWithRole.length > 0)+ usageMessages.push(`${usersWithRole.length} user${usersWithRole.length === 1 ? "" : "s"}`);+ if (groupsWithRole.length > 0)+ usageMessages.push(`${groupsWithRole.length} group${groupsWithRole.length === 1 ? "" : "s"}`);+ if (identitiesWithRole.length > 0 || projectManagedIdentitiesWithRole.length > 0) {+ const totalIdentities = identitiesWithRole.length + projectManagedIdentitiesWithRole.length;+ usageMessages.push(`${totalIdentities} identit${totalIdentities === 1 ? "y" : "ies"}`);+ }++ if (usageMessages.length > 0) {+ createNotification({+ text: `Cannot remove role "${slug}" because it is assigned to ${usageMessages.join(", ")}`,+ type: "error"+ });+ handlePopUpClose("removeRole");+ return;+ }+await updateProjectTemplate.mutateAsync({templateId: projectTemplate.id,roles: projectTemplate.roles.filter(