From 24b50651c9416d726612ccfc28e092a233ef8603 Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Fri, 22 Nov 2024 13:02:00 -0800 Subject: [PATCH 1/2] fix: correct update role mapping for identity/user and prevent updating role slug to "custom" --- .../identity-project-service.ts | 7 +++- .../IdentityRoleDetailsSection.tsx | 27 ++++++++++++++-- .../MemberRoleDetailsSection.tsx | 32 +++++++++++++++++-- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/backend/src/services/identity-project/identity-project-service.ts b/backend/src/services/identity-project/identity-project-service.ts index a49b15c1bd..10274f001f 100644 --- a/backend/src/services/identity-project/identity-project-service.ts +++ b/backend/src/services/identity-project/identity-project-service.ts @@ -182,7 +182,12 @@ export const identityProjectServiceFactory = ({ // validate custom roles input const customInputRoles = roles.filter( - ({ role }) => !Object.values(ProjectMembershipRole).includes(role as ProjectMembershipRole) + ({ role }) => + !Object.values(ProjectMembershipRole) + // we don't want to include custom in this check; + // this unintentionally lets users set slug to custom which is reserved + .filter((r) => r !== ProjectMembershipRole.Custom) + .includes(role as ProjectMembershipRole) ); const hasCustomRole = Boolean(customInputRoles.length); const customRoles = hasCustomRole diff --git a/frontend/src/views/Project/IdentityDetailsPage/components/IdentityRoleDetailsSection/IdentityRoleDetailsSection.tsx b/frontend/src/views/Project/IdentityDetailsPage/components/IdentityRoleDetailsSection/IdentityRoleDetailsSection.tsx index 8e157fcab0..300114228f 100644 --- a/frontend/src/views/Project/IdentityDetailsPage/components/IdentityRoleDetailsSection/IdentityRoleDetailsSection.tsx +++ b/frontend/src/views/Project/IdentityDetailsPage/components/IdentityRoleDetailsSection/IdentityRoleDetailsSection.tsx @@ -50,11 +50,34 @@ export const IdentityRoleDetailsSection = ({ const handleRoleDelete = async () => { const { id } = popUp?.deleteRole?.data as TProjectRole; try { - const updatedRole = identityMembershipDetails?.roles?.filter((el) => el.id !== id); + const updatedRoles = identityMembershipDetails?.roles?.filter((el) => el.id !== id); await updateIdentityWorkspaceRole({ workspaceId: currentWorkspace?.id || "", identityId: identityMembershipDetails.identity.id, - roles: updatedRole + roles: updatedRoles.map( + ({ + role, + customRoleSlug, + isTemporary, + temporaryMode, + temporaryRange, + temporaryAccessStartTime, + temporaryAccessEndTime + }) => ({ + role: role === "custom" ? customRoleSlug : role, + ...(isTemporary + ? { + isTemporary, + temporaryMode, + temporaryRange, + temporaryAccessStartTime, + temporaryAccessEndTime + } + : { + isTemporary + }) + }) + ) }); createNotification({ type: "success", text: "Successfully removed role" }); handlePopUpClose("deleteRole"); diff --git a/frontend/src/views/Project/MemberDetailsPage/components/MemberRoleDetailsSection/MemberRoleDetailsSection.tsx b/frontend/src/views/Project/MemberDetailsPage/components/MemberRoleDetailsSection/MemberRoleDetailsSection.tsx index e854ebc592..5ff78360dc 100644 --- a/frontend/src/views/Project/MemberDetailsPage/components/MemberRoleDetailsSection/MemberRoleDetailsSection.tsx +++ b/frontend/src/views/Project/MemberDetailsPage/components/MemberRoleDetailsSection/MemberRoleDetailsSection.tsx @@ -61,10 +61,33 @@ export const MemberRoleDetailsSection = ({ const handleRoleDelete = async () => { const { id } = popUp?.deleteRole?.data as TProjectRole; try { - const updatedRole = membershipDetails?.roles?.filter((el) => el.id !== id); + const updatedRoles = membershipDetails?.roles?.filter((el) => el.id !== id); await updateUserWorkspaceRole({ workspaceId: currentWorkspace?.id || "", - roles: updatedRole, + roles: updatedRoles.map( + ({ + role, + customRoleSlug, + isTemporary, + temporaryMode, + temporaryRange, + temporaryAccessStartTime, + temporaryAccessEndTime + }) => ({ + role: role === "custom" ? customRoleSlug : role, + ...(isTemporary + ? { + isTemporary, + temporaryMode, + temporaryRange, + temporaryAccessStartTime, + temporaryAccessEndTime + } + : { + isTemporary + }) + }) + ), membershipId: membershipDetails.id }); createNotification({ type: "success", text: "Successfully removed role" }); @@ -215,7 +238,10 @@ export const MemberRoleDetailsSection = ({ title="Roles" subTitle="Select one or more of the pre-defined or custom roles to configure project permissions." > - + From e3eb14bfd9779a95aee7bb4da64555d81cb30aff Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Fri, 22 Nov 2024 13:09:47 -0800 Subject: [PATCH 2/2] fix: add custom slug check to user --- .../services/identity-project/identity-project-service.ts | 2 +- .../project-membership/project-membership-service.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/src/services/identity-project/identity-project-service.ts b/backend/src/services/identity-project/identity-project-service.ts index 10274f001f..7f9cf920e1 100644 --- a/backend/src/services/identity-project/identity-project-service.ts +++ b/backend/src/services/identity-project/identity-project-service.ts @@ -185,7 +185,7 @@ export const identityProjectServiceFactory = ({ ({ role }) => !Object.values(ProjectMembershipRole) // we don't want to include custom in this check; - // this unintentionally lets users set slug to custom which is reserved + // this unintentionally enables setting slug to custom which is reserved .filter((r) => r !== ProjectMembershipRole.Custom) .includes(role as ProjectMembershipRole) ); diff --git a/backend/src/services/project-membership/project-membership-service.ts b/backend/src/services/project-membership/project-membership-service.ts index 74b830c6df..b4826b54bf 100644 --- a/backend/src/services/project-membership/project-membership-service.ts +++ b/backend/src/services/project-membership/project-membership-service.ts @@ -280,7 +280,12 @@ export const projectMembershipServiceFactory = ({ // validate custom roles input const customInputRoles = roles.filter( - ({ role }) => !Object.values(ProjectMembershipRole).includes(role as ProjectMembershipRole) + ({ role }) => + !Object.values(ProjectMembershipRole) + // we don't want to include custom in this check; + // this unintentionally enables setting slug to custom which is reserved + .filter((r) => r !== ProjectMembershipRole.Custom) + .includes(role as ProjectMembershipRole) ); const hasCustomRole = Boolean(customInputRoles.length); if (hasCustomRole) {