feat(infisical-pg): new org role routes completed

This commit is contained in:
Akhil Mohan
2024-01-27 12:38:22 +05:30
parent 9a4b2f7d81
commit 3670b16657
13 changed files with 157 additions and 42 deletions
+20
View File
@@ -13,6 +13,8 @@ import {
TGetRolesDTO,
TGetUserOrgPermissionsDTO,
TGetUserProjectPermissionDTO,
TOrgRole,
TPermission,
TRole
} from "./types";
@@ -36,6 +38,7 @@ const conditionsMatcher = buildMongoQueryMatcher({ $glob }, { glob });
export const roleQueryKeys = {
getRoles: ({ orgId, workspaceId }: TGetRolesDTO) => ["roles", { orgId, workspaceId }] as const,
getOrgRoles: (orgId: string) => ["org-roles", { orgId }] as const,
getUserOrgPermissions: ({ orgId }: TGetUserOrgPermissionsDTO) =>
["user-permissions", { orgId }] as const,
getUserProjectPermissions: ({ workspaceId }: TGetUserProjectPermissionDTO) =>
@@ -63,6 +66,23 @@ export const useGetRoles = ({ orgId, workspaceId }: TGetRolesDTO) =>
enabled: Boolean(orgId)
});
const getOrgRoles = async (orgId: string) => {
const { data } = await apiRequest.get<{
data: { roles: Array<Omit<TOrgRole, "permissions"> & { permissions: unknown }> };
}>(`/api/ee/v1/organization/${orgId}/roles`);
return data.data.roles.map(({ permissions, ...el }) => ({
...el,
permissions: unpackRules(permissions as PackRule<TPermission>[])
}));
};
export const useGetOrgRoles = (orgId: string, enable = true) =>
useQuery({
queryKey: roleQueryKeys.getOrgRoles(orgId),
queryFn: () => getOrgRoles(orgId),
enabled: Boolean(orgId) && enable
});
const getUserOrgPermissions = async ({ orgId }: TGetUserOrgPermissionsDTO) => {
if (orgId === "") return { permissions: [], membership: null };