Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Self remediate project scoped roles issue (#38428)

Joshen Limcf90f2e250d3
diff --git a/apps/studio/components/interfaces/Organization/TeamSettings/UpdateRolesPanel/UpdateRolesConfirmationModal.tsx b/apps/studio/components/interfaces/Organization/TeamSettings/UpdateRolesPanel/UpdateRolesConfirmationModal.tsx
index 1b7a0a482de..1ba27891feb 100644
--- a/apps/studio/components/interfaces/Organization/TeamSettings/UpdateRolesPanel/UpdateRolesConfirmationModal.tsx
+++ b/apps/studio/components/interfaces/Organization/TeamSettings/UpdateRolesPanel/UpdateRolesConfirmationModal.tsx
@@ -76,7 +76,22 @@ export const UpdateRolesConfirmationModal = ({
.map((id) => {
return [...org_scoped_roles, ...project_scoped_roles].find((r) => r.id === id)
})
+ .map((x) => {
+ // [Joshen] This is merely a patch to handle a issue on the BE whereby for a project-scoped member,
+ // if one of the projects that the member is deleted, the roles isn't cleaned up on the BE
+ // Hence adding an FE patch here for dashboard to self-remediate by omitting any project IDs from the role
+ // which no longer exists in the organization projects list
+ if (!!x?.project_ids) {
+ return {
+ ...x,
+ project_ids: x.project_ids.filter((id) => orgProjects.some((p) => id === p.id)),
+ }
+ } else {
+ return x
+ }
+ })
.filter(Boolean) as OrganizationRole[]
+
const isChangeWithinOrgScope =
projectsRoleConfiguration.length === 1 && projectsRoleConfiguration[0].ref === undefined
diff --git a/apps/studio/components/interfaces/Organization/TeamSettings/UpdateRolesPanel/UpdateRolesPanel.utils.ts b/apps/studio/components/interfaces/Organization/TeamSettings/UpdateRolesPanel/UpdateRolesPanel.utils.ts
index 89104c2c2d5..7b2cb3e2d27 100644
--- a/apps/studio/components/interfaces/Organization/TeamSettings/UpdateRolesPanel/UpdateRolesPanel.utils.ts
+++ b/apps/studio/components/interfaces/Organization/TeamSettings/UpdateRolesPanel/UpdateRolesPanel.utils.ts
@@ -41,7 +41,10 @@ export const formatMemberRoleToProjectRoleConfiguration = (
}
})
.filter(Boolean)
- .flat() as ProjectRoleConfiguration[]
+ .flat()
+ .filter(
+ (p) => p !== undefined && 'baseRoleId' in p && p.ref !== undefined
+ ) as ProjectRoleConfiguration[]
return roleConfiguration
}