From f7183347dcdb217c72a2440fb061bade0521449f Mon Sep 17 00:00:00 2001 From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com> Date: Mon, 22 Apr 2024 21:08:57 +0200 Subject: [PATCH] Fix: Project roles --- frontend/src/hooks/api/roles/queries.tsx | 12 +++++-- frontend/src/hooks/api/users/types.ts | 46 ++++++++++++------------ 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/frontend/src/hooks/api/roles/queries.tsx b/frontend/src/hooks/api/roles/queries.tsx index 8647353cb..d0bf0df57 100644 --- a/frontend/src/hooks/api/roles/queries.tsx +++ b/frontend/src/hooks/api/roles/queries.tsx @@ -106,7 +106,7 @@ const getUserProjectPermissions = async ({ workspaceId }: TGetUserProjectPermiss const { data } = await apiRequest.get<{ data: { permissions: PackRule>>[]; - membership: TProjectMembership; + membership: Omit & { roles: { role: string }[] }; }; }>(`/api/v1/workspace/${workspaceId}/permissions`, {}); @@ -121,6 +121,14 @@ export const useGetUserProjectPermissions = ({ workspaceId }: TGetUserProjectPer select: (data) => { const rule = unpackRules>>(data.permissions); const ability = createMongoAbility(rule, { conditionsMatcher }); - return { permission: ability, membership: data.membership }; + + const membership = { + ...data.membership, + roles: data.membership.roles.map(({ role }) => { + return role; + }) + }; + + return { permission: ability, membership }; } }); diff --git a/frontend/src/hooks/api/users/types.ts b/frontend/src/hooks/api/users/types.ts index 845030e9f..572296e75 100644 --- a/frontend/src/hooks/api/users/types.ts +++ b/frontend/src/hooks/api/users/types.ts @@ -62,7 +62,7 @@ export type TProjectMembership = { createdAt: string; updatedAt: string; projectId: string; - roleId: string; + roles: string[]; }; export type TWorkspaceUser = { @@ -79,29 +79,29 @@ export type TWorkspaceUser = { organization: string; roles: ( | { - id: string; - role: "owner" | "admin" | "member" | "no-access" | "custom"; - customRoleId: string; - customRoleName: string; - customRoleSlug: string; - isTemporary: false; - temporaryRange: null; - temporaryMode: null; - temporaryAccessEndTime: null; - temporaryAccessStartTime: null; - } + id: string; + role: "owner" | "admin" | "member" | "no-access" | "custom"; + customRoleId: string; + customRoleName: string; + customRoleSlug: string; + isTemporary: false; + temporaryRange: null; + temporaryMode: null; + temporaryAccessEndTime: null; + temporaryAccessStartTime: null; + } | { - id: string; - role: "owner" | "admin" | "member" | "no-access" | "custom"; - customRoleId: string; - customRoleName: string; - customRoleSlug: string; - isTemporary: true; - temporaryRange: string; - temporaryMode: string; - temporaryAccessEndTime: string; - temporaryAccessStartTime: string; - } + id: string; + role: "owner" | "admin" | "member" | "no-access" | "custom"; + customRoleId: string; + customRoleName: string; + customRoleSlug: string; + isTemporary: true; + temporaryRange: string; + temporaryMode: string; + temporaryAccessEndTime: string; + temporaryAccessStartTime: string; + } )[]; status: "invited" | "accepted" | "verified" | "completed"; deniedPermissions: any[];