feat: implemented user role impersonation

This commit is contained in:
=
2025-04-21 18:43:21 +05:30
parent eba12912f8
commit 7219ba3b46
40 changed files with 750 additions and 51 deletions
@@ -0,0 +1 @@
export { useAssumeProjectPrivileges, useRemoveAssumeProjectPrivilege } from "./mutations";
@@ -0,0 +1,26 @@
import { useMutation } from "@tanstack/react-query";
import { TProjectAssumePrivilegesDTO } from "./types";
import { apiRequest } from "@app/config/request";
export const useAssumeProjectPrivileges = () =>
useMutation({
mutationFn: async ({ projectId, actorId, actorType }: TProjectAssumePrivilegesDTO) => {
const { data } = await apiRequest.post<{ message: string }>(
`/api/v1/workspace/${projectId}/assume-privileges`,
{ actorId, actorType }
);
return data;
}
});
export const useRemoveAssumeProjectPrivilege = () =>
useMutation({
mutationFn: async ({ projectId }: { projectId: string }) => {
const { data } = await apiRequest.delete<{ message: string }>(
`/api/v1/workspace/${projectId}/assume-privileges`
);
return data;
}
});
@@ -0,0 +1,7 @@
import { ActorType } from "../auditLogs/enums";
export type TProjectAssumePrivilegesDTO = {
projectId: string;
actorType: ActorType;
actorId: string;
};
+1
View File
@@ -1,4 +1,5 @@
export * from "./accessApproval";
export * from "./assumePrivileges";
export * from "./admin";
export * from "./apiKeys";
export * from "./auditLogs";
+7
View File
@@ -18,6 +18,7 @@ import {
TPermission,
TProjectRole
} from "./types";
import { ActorType } from "../auditLogs/enums";
const $glob: FieldInstruction<string> = {
type: "field",
@@ -137,6 +138,12 @@ export const fetchUserProjectPermissions = async ({
data: {
permissions: PackRule<RawRuleOf<MongoAbility<OrgPermissionSet>>>[];
membership: Omit<TProjectMembership, "roles"> & { roles: { role: string }[] };
impersonation?: {
actorId: string;
actorType: ActorType;
actorEmail: string;
actorName: string;
};
};
}>(`/api/v1/workspace/${workspaceId}/permissions`, {});