Restructure MIs to more generic Identity

This commit is contained in:
Tuan Dang
2023-12-09 22:18:38 +07:00
parent 89d0c0e3c3
commit 50ef23e8a0
102 changed files with 3652 additions and 2981 deletions
+4 -4
View File
@@ -1,9 +1,9 @@
export {
useAddMachineToWorkspace,
useAddIdentityToWorkspace,
useAddUserToWorkspace,
useCreateWorkspace,
useCreateWsEnvironment,
useDeleteMachineFromWorkspace,
useDeleteIdentityFromWorkspace,
useDeleteUserFromWorkspace,
useDeleteWorkspace,
useDeleteWsEnvironment,
@@ -11,15 +11,15 @@ export {
useGetUserWorkspaces,
useGetWorkspaceAuthorizations,
useGetWorkspaceById,
useGetWorkspaceIdentityMemberships,
useGetWorkspaceIndexStatus,
useGetWorkspaceIntegrations,
useGetWorkspaceMachineMemberships,
useGetWorkspaceSecrets,
useGetWorkspaceUsers,
useNameWorkspaceSecrets,
useRenameWorkspace,
useReorderWsEnvironment,
useToggleAutoCapitalization,
useUpdateMachineWorkspaceRole,
useUpdateIdentityWorkspaceRole,
useUpdateUserWorkspaceRole,
useUpdateWsEnvironment} from "./queries";
+31 -36
View File
@@ -2,9 +2,9 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { IdentityMembership } from "../identities/types";
import { IntegrationAuth } from "../integrationAuth/types";
import { TIntegration } from "../integrations/types";
import { MachineMembership } from "../machineIdentities/types";
import { EncryptedSecret } from "../secrets/types";
import { TWorkspaceUser } from "../users/types";
import {
@@ -31,7 +31,7 @@ export const workspaceKeys = {
getAllUserWorkspace: ["workspaces"] as const,
getWorkspaceAuditLogs: (workspaceId: string) => [{ workspaceId }] as const,
getWorkspaceUsers: (workspaceId: string) => [{ workspaceId }] as const,
getWorkspaceMachineMemberships: (workspaceId: string) => [{ workspaceId }, "workspace-machine-memberships"] as const
getWorkspaceIdentityMemberships: (workspaceId: string) => [{ workspaceId }, "workspace-identity-memberships"] as const
};
const fetchWorkspaceById = async (workspaceId: string) => {
@@ -356,97 +356,92 @@ export const useUpdateUserWorkspaceRole = () => {
});
};
export const useAddMachineToWorkspace = () => {
export const useAddIdentityToWorkspace = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async ({
machineId,
identityId,
workspaceId,
role
}: {
machineId: string;
identityId: string;
workspaceId: string;
role?: string;
}) => {
const {
data: { serviceMembership }
} = await apiRequest.post(`/api/v2/workspace/${workspaceId}/machine-memberships/${machineId}`, {
data: { identityMembership }
} = await apiRequest.post(`/api/v2/workspace/${workspaceId}/identity-memberships/${identityId}`, {
role
});
return serviceMembership;
return identityMembership;
},
onSuccess: (_, { workspaceId }) => {
queryClient.invalidateQueries(workspaceKeys.getWorkspaceMachineMemberships(workspaceId));
queryClient.invalidateQueries(workspaceKeys.getWorkspaceIdentityMemberships(workspaceId));
}
});
};
export const useUpdateMachineWorkspaceRole = () => {
export const useUpdateIdentityWorkspaceRole = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async ({
machineId,
identityId,
workspaceId,
role
}: {
machineId: string;
identityId: string;
workspaceId: string;
role?: string;
}) => {
const {
data: { serviceMembership }
} = await apiRequest.patch(`/api/v2/workspace/${workspaceId}/machine-memberships/${machineId}`, {
data: { identityMembership }
} = await apiRequest.patch(`/api/v2/workspace/${workspaceId}/identity-memberships/${identityId}`, {
role
});
return serviceMembership;
return identityMembership;
},
onSuccess: (_, { workspaceId }) => {
queryClient.invalidateQueries(workspaceKeys.getWorkspaceMachineMemberships(workspaceId));
queryClient.invalidateQueries(workspaceKeys.getWorkspaceIdentityMemberships(workspaceId));
}
});
};
export const useDeleteMachineFromWorkspace = () => {
export const useDeleteIdentityFromWorkspace = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async ({
machineId,
identityId,
workspaceId,
}: {
machineId: string;
identityId: string;
workspaceId: string;
}) => {
const {
data: { serviceMembership }
} = await apiRequest.delete(`/api/v2/workspace/${workspaceId}/machine-memberships/${machineId}`);
return serviceMembership;
data: { identityMembership }
} = await apiRequest.delete(`/api/v2/workspace/${workspaceId}/identity-memberships/${identityId}`);
return identityMembership;
},
onSuccess: (_, { workspaceId }) => {
queryClient.invalidateQueries(workspaceKeys.getWorkspaceMachineMemberships(workspaceId));
queryClient.invalidateQueries(workspaceKeys.getWorkspaceIdentityMemberships(workspaceId));
}
});
};
export const useGetWorkspaceMachineMemberships = (workspaceId: string) => {
export const useGetWorkspaceIdentityMemberships = (workspaceId: string) => {
return useQuery({
queryKey: workspaceKeys.getWorkspaceMachineMemberships(workspaceId),
queryKey: workspaceKeys.getWorkspaceIdentityMemberships(workspaceId),
queryFn: async () => {
const {
data: { machineMemberships }
} = await apiRequest.get<{ machineMemberships: MachineMembership[] }>(
`/api/v2/workspace/${workspaceId}/machine-memberships`
data: { identityMemberships }
} = await apiRequest.get<{ identityMemberships: IdentityMembership[] }>(
`/api/v2/workspace/${workspaceId}/identity-memberships`
);
return machineMemberships;
return identityMemberships;
},
enabled: true
});
};
};