mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
feat(ui): hook for new user additional privilege
This commit is contained in:
@@ -12,6 +12,7 @@ export * from "./integrations";
|
|||||||
export * from "./keys";
|
export * from "./keys";
|
||||||
export * from "./ldapConfig";
|
export * from "./ldapConfig";
|
||||||
export * from "./organization";
|
export * from "./organization";
|
||||||
|
export * from "./projectUserAdditionalPrivilege";
|
||||||
export * from "./roles";
|
export * from "./roles";
|
||||||
export * from "./scim";
|
export * from "./scim";
|
||||||
export * from "./secretApproval";
|
export * from "./secretApproval";
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
export {
|
||||||
|
useCreateProjectUserAdditionalPrivilege,
|
||||||
|
useDeleteProjectUserAdditionalPrivilege,
|
||||||
|
useUpdateProjectUserAdditionalPrivilege
|
||||||
|
} from "./mutation";
|
||||||
|
export { useGetProjectUserPrivilegeDetails } from "./queries";
|
||||||
|
export type { TProjectUserPrivilege } from "./types";
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import { packRules } from "@casl/ability/extra";
|
||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
|
||||||
|
import { apiRequest } from "@app/config/request";
|
||||||
|
|
||||||
|
import { workspaceKeys } from "../workspace/queries";
|
||||||
|
import {
|
||||||
|
TCreateProjectUserPrivilegeDTO,
|
||||||
|
TDeleteProjectUserPrivilegeDTO,
|
||||||
|
TProjectUserPrivilege,
|
||||||
|
TUpdateProjectUserPrivlegeDTO
|
||||||
|
} from "./types";
|
||||||
|
|
||||||
|
export const useCreateProjectUserAdditionalPrivilege = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation<{ privilege: TProjectUserPrivilege }, {}, TCreateProjectUserPrivilegeDTO>({
|
||||||
|
mutationFn: async (dto) => {
|
||||||
|
const { data } = await apiRequest.post("/api/v1/additional-privilege/users", {
|
||||||
|
...dto,
|
||||||
|
permissions: packRules(dto.permissions)
|
||||||
|
});
|
||||||
|
return data.privilege;
|
||||||
|
},
|
||||||
|
onSuccess: (_, { workspaceId }) => {
|
||||||
|
queryClient.invalidateQueries(workspaceKeys.getWorkspaceUsers(workspaceId));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useUpdateProjectUserAdditionalPrivilege = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation<{ privilege: TProjectUserPrivilege }, {}, TUpdateProjectUserPrivlegeDTO>({
|
||||||
|
mutationFn: async (dto) => {
|
||||||
|
const { data } = await apiRequest.patch(
|
||||||
|
`/api/v1/additional-privilege/users/${dto.privilegeId}`,
|
||||||
|
{ ...dto, permissions: dto.permissions ? packRules(dto.permissions) : undefined }
|
||||||
|
);
|
||||||
|
return data.privilege;
|
||||||
|
},
|
||||||
|
onSuccess: (_, { workspaceId }) => {
|
||||||
|
queryClient.invalidateQueries(workspaceKeys.getWorkspaceUsers(workspaceId));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useDeleteProjectUserAdditionalPrivilege = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation<{ privilege: TProjectUserPrivilege }, {}, TDeleteProjectUserPrivilegeDTO>({
|
||||||
|
mutationFn: async (dto) => {
|
||||||
|
const { data } = await apiRequest.delete(
|
||||||
|
`/api/v1/additional-privilege/users/${dto.privilegeId}`
|
||||||
|
);
|
||||||
|
return data.privilege;
|
||||||
|
},
|
||||||
|
onSuccess: (_, { workspaceId }) => {
|
||||||
|
queryClient.invalidateQueries(workspaceKeys.getWorkspaceUsers(workspaceId));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { PackRule, unpackRules } from "@casl/ability/extra";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
|
||||||
|
import { apiRequest } from "@app/config/request";
|
||||||
|
|
||||||
|
import { TProjectPermission } from "../roles/types";
|
||||||
|
import { TProjectUserPrivilege } from "./types";
|
||||||
|
|
||||||
|
export const projectUserPrivilegeKeys = {
|
||||||
|
details: (privilegeId: string) => ["project-user-privilege", { privilegeId }] as const
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchProjectUserPrivilegeDetails = async (privilegeId: string) => {
|
||||||
|
const {
|
||||||
|
data: { privilege }
|
||||||
|
} = await apiRequest.get<{
|
||||||
|
privilege: Omit<TProjectUserPrivilege, "permissions"> & { permissions: unknown };
|
||||||
|
}>(`/api/v1/additional-privilege/users/${privilegeId}`);
|
||||||
|
return {
|
||||||
|
...privilege,
|
||||||
|
permissions: unpackRules(privilege.permissions as PackRule<TProjectPermission>[])
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useGetProjectUserPrivilegeDetails = (privilegeId: string) => {
|
||||||
|
return useQuery({
|
||||||
|
enabled: Boolean(privilegeId),
|
||||||
|
queryKey: projectUserPrivilegeKeys.details(privilegeId),
|
||||||
|
queryFn: () => fetchProjectUserPrivilegeDetails(privilegeId)
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import { TProjectPermission } from "../roles/types";
|
||||||
|
|
||||||
|
export enum ProjectUserAdditionalPrivilegeTemporaryMode {
|
||||||
|
Relative = "relative"
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TProjectUserPrivilege = {
|
||||||
|
projectMembershipId: string;
|
||||||
|
slug: string;
|
||||||
|
name: string;
|
||||||
|
isTemporary: boolean;
|
||||||
|
id: string;
|
||||||
|
createdAt: Date;
|
||||||
|
updatedAt: Date;
|
||||||
|
description?: string | null | undefined;
|
||||||
|
temporaryMode?: string | null | undefined;
|
||||||
|
temporaryRange?: string | null | undefined;
|
||||||
|
temporaryAccessStartTime?: string | null | undefined;
|
||||||
|
temporaryAccessEndTime?: Date | null | undefined;
|
||||||
|
permissions?: TProjectPermission[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TCreateProjectUserPrivilegeDTO = {
|
||||||
|
projectMembershipId: string;
|
||||||
|
slug: string;
|
||||||
|
name: string;
|
||||||
|
workspaceId: string;
|
||||||
|
description?: string;
|
||||||
|
isTemporary?: boolean;
|
||||||
|
temporaryMode?: ProjectUserAdditionalPrivilegeTemporaryMode;
|
||||||
|
temporaryRange?: string;
|
||||||
|
temporaryAccessStartTime?: string;
|
||||||
|
permissions: TProjectPermission[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TUpdateProjectUserPrivlegeDTO = {
|
||||||
|
privilegeId: string;
|
||||||
|
workspaceId: string;
|
||||||
|
} & Partial<Omit<TCreateProjectUserPrivilegeDTO, "projectMembershipId">>;
|
||||||
|
|
||||||
|
export type TDeleteProjectUserPrivilegeDTO = {
|
||||||
|
privilegeId: string;
|
||||||
|
workspaceId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TGetProejctUserPrivilegeDetails = {
|
||||||
|
privilegeId: string;
|
||||||
|
};
|
||||||
@@ -76,6 +76,18 @@ export type TWorkspaceUser = {
|
|||||||
};
|
};
|
||||||
inviteEmail: string;
|
inviteEmail: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
|
additionalPrivileges: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description: string | null | undefined;
|
||||||
|
slug: string;
|
||||||
|
temporaryRange: string | null | undefined;
|
||||||
|
temporaryMode: string | null | undefined;
|
||||||
|
temporaryAccessEndTime: string | null | undefined;
|
||||||
|
temporaryAccessStartTime: string | null | undefined;
|
||||||
|
isTemporary: boolean;
|
||||||
|
createdAt: string;
|
||||||
|
}[];
|
||||||
roles: {
|
roles: {
|
||||||
id: string;
|
id: string;
|
||||||
role: "owner" | "admin" | "member" | "no-access" | "custom";
|
role: "owner" | "admin" | "member" | "no-access" | "custom";
|
||||||
|
|||||||
@@ -315,6 +315,13 @@ export const useGetWorkspaceUsers = (workspaceId: string) => {
|
|||||||
);
|
);
|
||||||
return users;
|
return users;
|
||||||
},
|
},
|
||||||
|
select: (data) =>
|
||||||
|
data.map((el) => ({
|
||||||
|
...el,
|
||||||
|
additionalPrivileges: el.additionalPrivileges.sort((a, b) =>
|
||||||
|
a.createdAt.localeCompare(b.createdAt)
|
||||||
|
)
|
||||||
|
})),
|
||||||
enabled: true
|
enabled: true
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user