mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 03:29:35 +00:00
Add API specs to groups endpoints, convert projectId groups endpoints to be slug-based
This commit is contained in:
@@ -40,7 +40,7 @@ export const workspaceKeys = {
|
||||
getWorkspaceIdentityMemberships: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-identity-memberships"] as const,
|
||||
getWorkspaceGroupMemberships: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-group-memberships"] as const
|
||||
[{ workspaceId }, "workspace-groups"] as const
|
||||
};
|
||||
|
||||
const fetchWorkspaceById = async (workspaceId: string) => {
|
||||
@@ -460,25 +460,25 @@ export const useAddGroupToWorkspace = () => {
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
groupSlug,
|
||||
workspaceId,
|
||||
projectSlug,
|
||||
role
|
||||
}: {
|
||||
groupSlug: string;
|
||||
workspaceId: string;
|
||||
projectSlug: string;
|
||||
role?: string;
|
||||
}) => {
|
||||
const {
|
||||
data: { groupMembership }
|
||||
} = await apiRequest.post(
|
||||
`/api/v2/workspace/${workspaceId}/group-memberships/${groupSlug}`,
|
||||
`/api/v2/workspace/${projectSlug}/groups/${groupSlug}`,
|
||||
{
|
||||
role
|
||||
}
|
||||
);
|
||||
return groupMembership;
|
||||
},
|
||||
onSuccess: (_, { workspaceId }) => {
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceGroupMemberships(workspaceId));
|
||||
onSuccess: (_, { projectSlug }) => {
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceGroupMemberships(projectSlug));
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -486,20 +486,19 @@ export const useAddGroupToWorkspace = () => {
|
||||
export const useUpdateGroupWorkspaceRole = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({ groupSlug, workspaceId, roles }: TUpdateWorkspaceGroupRoleDTO) => {
|
||||
mutationFn: async ({ groupSlug, projectSlug, roles }: TUpdateWorkspaceGroupRoleDTO) => {
|
||||
const {
|
||||
data: { groupMembership }
|
||||
} = await apiRequest.patch(
|
||||
`/api/v2/workspace/${workspaceId}/group-memberships/${groupSlug}`,
|
||||
{
|
||||
`/api/v2/workspace/${projectSlug}/groups/${groupSlug}`, {
|
||||
roles
|
||||
}
|
||||
);
|
||||
|
||||
return groupMembership;
|
||||
},
|
||||
onSuccess: (_, { workspaceId }) => {
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceGroupMemberships(workspaceId));
|
||||
onSuccess: (_, { projectSlug }) => {
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceGroupMemberships(projectSlug));
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -509,32 +508,32 @@ export const useDeleteGroupFromWorkspace = () => {
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
groupSlug,
|
||||
workspaceId
|
||||
projectSlug
|
||||
}: {
|
||||
groupSlug: string;
|
||||
workspaceId: string;
|
||||
projectSlug: string;
|
||||
}) => {
|
||||
const {
|
||||
data: { groupMembership }
|
||||
} = await apiRequest.delete(
|
||||
`/api/v2/workspace/${workspaceId}/group-memberships/${groupSlug}`
|
||||
`/api/v2/workspace/${projectSlug}/groups/${groupSlug}`
|
||||
);
|
||||
return groupMembership;
|
||||
},
|
||||
onSuccess: (_, { workspaceId }) => {
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceGroupMemberships(workspaceId));
|
||||
onSuccess: (_, { projectSlug }) => {
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceGroupMemberships(projectSlug));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetWorkspaceGroupMemberships = (workspaceId: string) => {
|
||||
export const useGetWorkspaceGroupMemberships = (projectSlug: string) => {
|
||||
return useQuery({
|
||||
queryKey: workspaceKeys.getWorkspaceGroupMemberships(workspaceId),
|
||||
queryKey: workspaceKeys.getWorkspaceGroupMemberships(projectSlug),
|
||||
queryFn: async () => {
|
||||
const {
|
||||
data: { groupMemberships }
|
||||
} = await apiRequest.get<{ groupMemberships: TGroupMembership[] }>(
|
||||
`/api/v2/workspace/${workspaceId}/group-memberships`
|
||||
`/api/v2/workspace/${projectSlug}/groups`
|
||||
);
|
||||
return groupMemberships;
|
||||
},
|
||||
|
||||
@@ -114,7 +114,7 @@ export type TUpdateWorkspaceIdentityRoleDTO = {
|
||||
|
||||
export type TUpdateWorkspaceGroupRoleDTO = {
|
||||
groupSlug: string;
|
||||
workspaceId: string;
|
||||
projectSlug: string;
|
||||
roles: (
|
||||
| {
|
||||
role: string;
|
||||
|
||||
+2
-2
@@ -48,7 +48,7 @@ export const GroupModal = ({
|
||||
const workspaceId = currentWorkspace?.id || "";
|
||||
|
||||
const { data: groups } = useGetOrganizationGroups(orgId);
|
||||
const { data: groupMemberships } = useGetWorkspaceGroupMemberships(workspaceId);
|
||||
const { data: groupMemberships } = useGetWorkspaceGroupMemberships(currentWorkspace?.slug || "");
|
||||
|
||||
const { data: roles } = useGetProjectRoles(workspaceId);
|
||||
|
||||
@@ -76,7 +76,7 @@ export const GroupModal = ({
|
||||
const onFormSubmit = async ({ slug, role }: FormData) => {
|
||||
try {
|
||||
await addGroupToWorkspaceMutateAsync({
|
||||
workspaceId,
|
||||
projectSlug: currentWorkspace?.slug || "",
|
||||
groupSlug: slug,
|
||||
role: role || undefined
|
||||
});
|
||||
|
||||
+1
-1
@@ -252,7 +252,7 @@ export const GroupRoles = ({
|
||||
|
||||
try {
|
||||
await updateGroupWorkspaceRole.mutateAsync({
|
||||
workspaceId,
|
||||
projectSlug: currentWorkspace?.slug || "",
|
||||
groupSlug,
|
||||
roles: selectedRoles
|
||||
});
|
||||
|
||||
+1
-3
@@ -17,8 +17,6 @@ import { GroupTable } from "./GroupsTable";
|
||||
export const GroupsSection = () => {
|
||||
const { currentWorkspace } = useWorkspace();
|
||||
|
||||
const workspaceId = currentWorkspace?.id ?? "";
|
||||
|
||||
const { mutateAsync: deleteMutateAsync } = useDeleteGroupFromWorkspace();
|
||||
|
||||
const { handlePopUpToggle, popUp, handlePopUpOpen, handlePopUpClose } = usePopUp([
|
||||
@@ -31,7 +29,7 @@ export const GroupsSection = () => {
|
||||
try {
|
||||
await deleteMutateAsync({
|
||||
groupSlug,
|
||||
workspaceId
|
||||
projectSlug: currentWorkspace?.slug || ""
|
||||
});
|
||||
|
||||
createNotification({
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ type Props = {
|
||||
|
||||
export const GroupTable = ({ handlePopUpOpen }: Props) => {
|
||||
const { currentWorkspace } = useWorkspace();
|
||||
const { data, isLoading } = useGetWorkspaceGroupMemberships(currentWorkspace?.id || "");
|
||||
const { data, isLoading } = useGetWorkspaceGroupMemberships(currentWorkspace?.slug || "");
|
||||
return (
|
||||
<TableContainer>
|
||||
<Table>
|
||||
|
||||
Reference in New Issue
Block a user