mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 12:38:36 +00:00
resolve merge conflict
This commit is contained in:
@@ -2,7 +2,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { userKeys } from "../users/queries";
|
||||
import { userKeys } from "../users";
|
||||
import {
|
||||
APIKeyDataV2,
|
||||
CreateAPIKeyDataV2DTO,
|
||||
|
||||
@@ -4,28 +4,28 @@ import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { Actor, AuditLog, AuditLogFilters } from "./types";
|
||||
|
||||
export const workspaceKeys = {
|
||||
getAuditLogs: (workspaceId: string, filters: AuditLogFilters) =>
|
||||
export const auditLogKeys = {
|
||||
getAuditLogs: (workspaceId: string | null, filters: AuditLogFilters) =>
|
||||
[{ workspaceId, filters }, "audit-logs"] as const,
|
||||
getAuditLogActorFilterOpts: (workspaceId: string) =>
|
||||
[{ workspaceId }, "audit-log-actor-filters"] as const
|
||||
};
|
||||
|
||||
export const useGetAuditLogs = (workspaceId: string, filters: AuditLogFilters) => {
|
||||
export const useGetAuditLogs = (filters: AuditLogFilters, workspaceId: string | null) => {
|
||||
return useInfiniteQuery({
|
||||
queryKey: workspaceKeys.getAuditLogs(workspaceId, filters),
|
||||
queryKey: auditLogKeys.getAuditLogs(workspaceId, filters),
|
||||
queryFn: async ({ pageParam }) => {
|
||||
const { data } = await apiRequest.get<{ auditLogs: AuditLog[] }>(
|
||||
`/api/v1/workspace/${workspaceId}/audit-logs`,
|
||||
{
|
||||
params: {
|
||||
...filters,
|
||||
offset: pageParam,
|
||||
startDate: filters?.startDate?.toISOString(),
|
||||
endDate: filters?.endDate?.toISOString()
|
||||
}
|
||||
const auditLogEndpoint = workspaceId
|
||||
? `/api/v1/workspace/${workspaceId}/audit-logs`
|
||||
: "/api/v1/organization/audit-logs";
|
||||
const { data } = await apiRequest.get<{ auditLogs: AuditLog[] }>(auditLogEndpoint, {
|
||||
params: {
|
||||
...filters,
|
||||
offset: pageParam,
|
||||
startDate: filters?.startDate?.toISOString(),
|
||||
endDate: filters?.endDate?.toISOString()
|
||||
}
|
||||
);
|
||||
});
|
||||
return data.auditLogs;
|
||||
},
|
||||
getNextPageParam: (lastPage, pages) =>
|
||||
@@ -35,7 +35,7 @@ export const useGetAuditLogs = (workspaceId: string, filters: AuditLogFilters) =
|
||||
|
||||
export const useGetAuditLogActorFilterOpts = (workspaceId: string) => {
|
||||
return useQuery({
|
||||
queryKey: workspaceKeys.getAuditLogActorFilterOpts(workspaceId),
|
||||
queryKey: auditLogKeys.getAuditLogActorFilterOpts(workspaceId),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<{ actors: Actor[] }>(
|
||||
`/api/v1/workspace/${workspaceId}/audit-logs/filters/actors`
|
||||
|
||||
@@ -851,6 +851,10 @@ export type AuditLog = {
|
||||
userAgentType: UserAgentType;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
project: {
|
||||
name: string;
|
||||
slug: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type AuditLogFilters = {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { apiRequest } from "@app/config/request";
|
||||
import { setAuthToken } from "@app/reactQuery";
|
||||
|
||||
import { organizationKeys } from "../organization/queries";
|
||||
import { workspaceKeys } from "../workspace/queries";
|
||||
import { workspaceKeys } from "../workspace";
|
||||
import {
|
||||
ChangePasswordDTO,
|
||||
CompleteAccountDTO,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { workspaceKeys } from "../workspace/queries";
|
||||
import { workspaceKeys } from "../workspace";
|
||||
import { caKeys } from "./queries";
|
||||
import {
|
||||
TCertificateAuthority,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { caKeys } from "../ca/queries";
|
||||
import { workspaceKeys } from "../workspace/queries";
|
||||
import { workspaceKeys } from "../workspace";
|
||||
import { certTemplateKeys } from "./queries";
|
||||
import {
|
||||
TCertificateTemplate,
|
||||
@@ -54,7 +54,9 @@ export const useDeleteCertTemplate = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TCertificateTemplate, {}, TDeleteCertificateTemplateDTO>({
|
||||
mutationFn: async (data) => {
|
||||
const { data: certificateTemplate } = await apiRequest.delete<TCertificateTemplate>(`/api/v1/pki/certificate-templates/${data.id}`);
|
||||
const { data: certificateTemplate } = await apiRequest.delete<TCertificateTemplate>(
|
||||
`/api/v1/pki/certificate-templates/${data.id}`
|
||||
);
|
||||
return certificateTemplate;
|
||||
},
|
||||
onSuccess: ({ caId }, { projectId, id }) => {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { workspaceKeys } from "../workspace/queries";
|
||||
import { workspaceKeys } from "../workspace";
|
||||
import { TCertificate, TDeleteCertDTO, TRevokeCertDTO } from "./types";
|
||||
|
||||
export const useDeleteCert = () => {
|
||||
|
||||
@@ -3,128 +3,104 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { organizationKeys } from "../organization/queries";
|
||||
import { userKeys } from "../users/query-keys";
|
||||
import { groupKeys } from "./queries";
|
||||
import { TGroup } from "./types";
|
||||
|
||||
export const useCreateGroup = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
name,
|
||||
slug,
|
||||
role
|
||||
}: {
|
||||
name: string;
|
||||
slug: string;
|
||||
organizationId: string;
|
||||
role?: string;
|
||||
}) => {
|
||||
const {
|
||||
data: group
|
||||
} = await apiRequest.post<TGroup>("/api/v1/groups", {
|
||||
name,
|
||||
slug,
|
||||
role
|
||||
});
|
||||
|
||||
return group;
|
||||
},
|
||||
onSuccess: (_, { organizationId }) => {
|
||||
queryClient.invalidateQueries(organizationKeys.getOrgGroups(organizationId));
|
||||
}
|
||||
});
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
name,
|
||||
slug,
|
||||
role
|
||||
}: {
|
||||
name: string;
|
||||
slug: string;
|
||||
organizationId: string;
|
||||
role?: string;
|
||||
}) => {
|
||||
const { data: group } = await apiRequest.post<TGroup>("/api/v1/groups", {
|
||||
name,
|
||||
slug,
|
||||
role
|
||||
});
|
||||
|
||||
return group;
|
||||
},
|
||||
onSuccess: (_, { organizationId }) => {
|
||||
queryClient.invalidateQueries(organizationKeys.getOrgGroups(organizationId));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateGroup = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
currentSlug,
|
||||
name,
|
||||
slug,
|
||||
role
|
||||
}: {
|
||||
currentSlug: string;
|
||||
name?: string;
|
||||
slug?: string;
|
||||
role?: string;
|
||||
}) => {
|
||||
const {
|
||||
data: group
|
||||
} = await apiRequest.patch<TGroup>(`/api/v1/groups/${currentSlug}`, {
|
||||
name,
|
||||
slug,
|
||||
role
|
||||
});
|
||||
|
||||
return group;
|
||||
},
|
||||
onSuccess: ({ orgId }) => {
|
||||
queryClient.invalidateQueries(organizationKeys.getOrgGroups(orgId));
|
||||
}
|
||||
});
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
currentSlug,
|
||||
name,
|
||||
slug,
|
||||
role
|
||||
}: {
|
||||
currentSlug: string;
|
||||
name?: string;
|
||||
slug?: string;
|
||||
role?: string;
|
||||
}) => {
|
||||
const { data: group } = await apiRequest.patch<TGroup>(`/api/v1/groups/${currentSlug}`, {
|
||||
name,
|
||||
slug,
|
||||
role
|
||||
});
|
||||
|
||||
return group;
|
||||
},
|
||||
onSuccess: ({ orgId }) => {
|
||||
queryClient.invalidateQueries(organizationKeys.getOrgGroups(orgId));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteGroup = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
slug
|
||||
}: {
|
||||
slug: string;
|
||||
}) => {
|
||||
const {
|
||||
data: group
|
||||
} = await apiRequest.delete<TGroup>(`/api/v1/groups/${slug}`);
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({ slug }: { slug: string }) => {
|
||||
const { data: group } = await apiRequest.delete<TGroup>(`/api/v1/groups/${slug}`);
|
||||
|
||||
return group;
|
||||
},
|
||||
onSuccess: ({ orgId }) => {
|
||||
queryClient.invalidateQueries(organizationKeys.getOrgGroups(orgId));
|
||||
}
|
||||
});
|
||||
return group;
|
||||
},
|
||||
onSuccess: ({ orgId }) => {
|
||||
queryClient.invalidateQueries(organizationKeys.getOrgGroups(orgId));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useAddUserToGroup = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
slug,
|
||||
username
|
||||
}: {
|
||||
slug: string;
|
||||
username: string;
|
||||
}) => {
|
||||
const {
|
||||
data
|
||||
} = await apiRequest.post<TGroup>(`/api/v1/groups/${slug}/users/${username}`);
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({ slug, username }: { slug: string; username: string }) => {
|
||||
const { data } = await apiRequest.post<TGroup>(`/api/v1/groups/${slug}/users/${username}`);
|
||||
|
||||
return data;
|
||||
},
|
||||
onSuccess: (_, { slug }) => {
|
||||
queryClient.invalidateQueries(groupKeys.forGroupUserMemberships(slug));
|
||||
}
|
||||
});
|
||||
return data;
|
||||
},
|
||||
onSuccess: (_, { slug }) => {
|
||||
queryClient.invalidateQueries(groupKeys.forGroupUserMemberships(slug));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useRemoveUserFromGroup = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
slug,
|
||||
username
|
||||
}: {
|
||||
slug: string;
|
||||
username: string;
|
||||
}) => {
|
||||
const {
|
||||
data
|
||||
} = await apiRequest.delete<TGroup>(`/api/v1/groups/${slug}/users/${username}`);
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({ slug, username }: { slug: string; username: string }) => {
|
||||
const { data } = await apiRequest.delete<TGroup>(`/api/v1/groups/${slug}/users/${username}`);
|
||||
|
||||
return data;
|
||||
},
|
||||
onSuccess: (_, { slug }) => {
|
||||
queryClient.invalidateQueries(groupKeys.forGroupUserMemberships(slug));
|
||||
}
|
||||
});
|
||||
};
|
||||
return data;
|
||||
},
|
||||
onSuccess: (_, { slug, username }) => {
|
||||
queryClient.invalidateQueries(groupKeys.forGroupUserMemberships(slug));
|
||||
queryClient.invalidateQueries(userKeys.listUserGroupMemberships(username));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@ import { TOrgRole } from "../roles/types";
|
||||
|
||||
export type TGroupOrgMembership = TGroup & {
|
||||
customRole?: TOrgRole;
|
||||
}
|
||||
};
|
||||
|
||||
export type TGroup = {
|
||||
id: string;
|
||||
@@ -33,4 +33,11 @@ export type TGroupMembership = {
|
||||
}[];
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type TGroupWithProjectMemberships = {
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
orgId: string;
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { workspaceKeys } from "../workspace/queries";
|
||||
import { workspaceKeys } from "../workspace";
|
||||
import {
|
||||
App,
|
||||
BitBucketWorkspace,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { workspaceKeys } from "../workspace/queries";
|
||||
import { workspaceKeys } from "../workspace";
|
||||
import { TCloudIntegration } from "./types";
|
||||
|
||||
export const integrationQueryKeys = {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { workspaceKeys } from "../workspace/queries";
|
||||
import { workspaceKeys } from "../workspace";
|
||||
import { pkiAlertKeys } from "./queries";
|
||||
import { TCreatePkiAlertDTO, TDeletePkiAlertDTO, TPkiAlert, TUpdatePkiAlertDTO } from "./types";
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { workspaceKeys } from "../workspace/queries";
|
||||
import { workspaceKeys } from "../workspace";
|
||||
import { pkiCollectionKeys } from "./queries";
|
||||
import {
|
||||
TAddItemToPkiCollectionDTO,
|
||||
@@ -11,7 +11,8 @@ import {
|
||||
TPkiCollection,
|
||||
TPkiCollectionItem,
|
||||
TRemoveItemFromPkiCollectionDTO,
|
||||
TUpdatePkiCollectionTO} from "./types";
|
||||
TUpdatePkiCollectionTO
|
||||
} from "./types";
|
||||
|
||||
export const useCreatePkiCollection = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -21,6 +21,7 @@ export {
|
||||
useGetOrgUsers,
|
||||
useGetUser,
|
||||
useGetUserAction,
|
||||
useListUserGroupMemberships,
|
||||
useLogoutUser,
|
||||
useRegisterUserAction,
|
||||
useRevokeMySessions,
|
||||
@@ -28,3 +29,4 @@ export {
|
||||
useUpdateOrgMembership,
|
||||
useUpdateUserAuthMethods
|
||||
} from "./queries";
|
||||
export { userKeys } from "./query-keys";
|
||||
|
||||
@@ -6,8 +6,8 @@ import {
|
||||
} from "@app/components/utilities/cryptography/crypto";
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { workspaceKeys } from "../workspace/queries";
|
||||
import { userKeys } from "./queries";
|
||||
import { workspaceKeys } from "../workspace";
|
||||
import { userKeys } from "./query-keys";
|
||||
import { AddUserToWsDTOE2EE, AddUserToWsDTONonE2EE } from "./types";
|
||||
|
||||
export const useAddUserToWsE2EE = () => {
|
||||
@@ -51,9 +51,10 @@ export const useAddUserToWsNonE2EE = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<{}, {}, AddUserToWsDTONonE2EE>({
|
||||
mutationFn: async ({ projectId, usernames }) => {
|
||||
mutationFn: async ({ projectId, usernames, roleSlugs }) => {
|
||||
const { data } = await apiRequest.post(`/api/v2/workspace/${projectId}/memberships`, {
|
||||
usernames
|
||||
usernames,
|
||||
roleSlugs
|
||||
});
|
||||
return data;
|
||||
},
|
||||
|
||||
@@ -5,6 +5,9 @@ import { SessionStorageKeys } from "@app/const";
|
||||
import { setAuthToken } from "@app/reactQuery";
|
||||
|
||||
import { APIKeyDataV2 } from "../apiKeys/types";
|
||||
import { TGroupWithProjectMemberships } from "../groups/types";
|
||||
import { workspaceKeys } from "../workspace";
|
||||
import { userKeys } from "./query-keys";
|
||||
import {
|
||||
AddUserToOrgDTO,
|
||||
APIKeyData,
|
||||
@@ -20,28 +23,6 @@ import {
|
||||
UserEnc
|
||||
} from "./types";
|
||||
|
||||
export const userKeys = {
|
||||
getUser: ["user"] as const,
|
||||
getPrivateKey: ["user"] as const,
|
||||
userAction: ["user-action"] as const,
|
||||
userProjectFavorites: (orgId: string) => [{ orgId }, "user-project-favorites"] as const,
|
||||
getOrgMembership: (orgId: string, orgMembershipId: string) =>
|
||||
[{ orgId, orgMembershipId }, "org-membership"] as const,
|
||||
allOrgMembershipProjectMemberships: (orgId: string) => [orgId, "all-user-memberships"] as const,
|
||||
forOrgMembershipProjectMemberships: (orgId: string, orgMembershipId: string) =>
|
||||
[...userKeys.allOrgMembershipProjectMemberships(orgId), { orgMembershipId }] as const,
|
||||
getOrgMembershipProjectMemberships: (orgId: string, username: string) =>
|
||||
[{ orgId, username }, "org-membership-project-memberships"] as const,
|
||||
getOrgUsers: (orgId: string) => [{ orgId }, "user"],
|
||||
myIp: ["ip"] as const,
|
||||
myAPIKeys: ["api-keys"] as const,
|
||||
myAPIKeysV2: ["api-keys-v2"] as const,
|
||||
mySessions: ["sessions"] as const,
|
||||
listUsers: ["user-list"] as const,
|
||||
|
||||
myOrganizationProjects: (orgId: string) => [{ orgId }, "organization-projects"] as const
|
||||
};
|
||||
|
||||
export const fetchUserDetails = async () => {
|
||||
const { data } = await apiRequest.get<{ user: User & UserEnc }>("/api/v1/user");
|
||||
|
||||
@@ -173,8 +154,15 @@ export const useAddUsersToOrg = () => {
|
||||
mutationFn: (dto) => {
|
||||
return apiRequest.post("/api/v1/invite-org/signup", dto);
|
||||
},
|
||||
onSuccess: (_, { organizationId }) => {
|
||||
onSuccess: (_, { organizationId, projects }) => {
|
||||
queryClient.invalidateQueries(userKeys.getOrgUsers(organizationId));
|
||||
|
||||
projects?.forEach((project) => {
|
||||
if (project.slug) {
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceGroupMemberships(project.slug));
|
||||
}
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceUsers(project.id));
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -444,3 +432,16 @@ export const fetchMyPrivateKey = async () => {
|
||||
|
||||
return privateKey;
|
||||
};
|
||||
|
||||
export const useListUserGroupMemberships = (username: string) => {
|
||||
return useQuery({
|
||||
queryKey: userKeys.listUserGroupMemberships(username),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<TGroupWithProjectMemberships[]>(
|
||||
`/api/v1/user/me/${username}/groups`
|
||||
);
|
||||
|
||||
return data;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
export const userKeys = {
|
||||
getUser: ["user"] as const,
|
||||
getPrivateKey: ["user"] as const,
|
||||
userAction: ["user-action"] as const,
|
||||
userProjectFavorites: (orgId: string) => [{ orgId }, "user-project-favorites"] as const,
|
||||
getOrgMembership: (orgId: string, orgMembershipId: string) =>
|
||||
[{ orgId, orgMembershipId }, "org-membership"] as const,
|
||||
allOrgMembershipProjectMemberships: (orgId: string) => [orgId, "all-user-memberships"] as const,
|
||||
forOrgMembershipProjectMemberships: (orgId: string, orgMembershipId: string) =>
|
||||
[...userKeys.allOrgMembershipProjectMemberships(orgId), { orgMembershipId }] as const,
|
||||
getOrgMembershipProjectMemberships: (orgId: string, username: string) =>
|
||||
[{ orgId, username }, "org-membership-project-memberships"] as const,
|
||||
getOrgUsers: (orgId: string) => [{ orgId }, "user"],
|
||||
myIp: ["ip"] as const,
|
||||
myAPIKeys: ["api-keys"] as const,
|
||||
myAPIKeysV2: ["api-keys-v2"] as const,
|
||||
mySessions: ["sessions"] as const,
|
||||
listUsers: ["user-list"] as const,
|
||||
listUserGroupMemberships: (username: string) => [{ username }, "user-group-memberships"] as const,
|
||||
myOrganizationProjects: (orgId: string) => [{ orgId }, "organization-projects"] as const
|
||||
};
|
||||
@@ -133,6 +133,7 @@ export type AddUserToWsDTOE2EE = {
|
||||
export type AddUserToWsDTONonE2EE = {
|
||||
projectId: string;
|
||||
usernames: string[];
|
||||
roleSlugs?: string[];
|
||||
orgId: string;
|
||||
};
|
||||
|
||||
@@ -150,9 +151,11 @@ export type DeletOrgMembershipDTO = {
|
||||
|
||||
export type AddUserToOrgDTO = {
|
||||
inviteeEmails: string[];
|
||||
projects?: { id: string; projectRoleSlug: string[] }[];
|
||||
organizationRoleSlug: string;
|
||||
organizationId: string;
|
||||
|
||||
// We need the slug in order to invalidate the groups query. `slug` is only used for invalidation purposes.
|
||||
projects?: { id: string; slug?: string; projectRoleSlug: string[] }[];
|
||||
};
|
||||
|
||||
export type CreateAPIKeyRes = {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { workspaceKeys } from "../workspace/queries";
|
||||
import { workspaceKeys } from "../workspace/query-keys";
|
||||
import { workflowIntegrationKeys } from "./queries";
|
||||
import {
|
||||
TDeleteSlackIntegrationDTO,
|
||||
|
||||
@@ -38,3 +38,4 @@ export {
|
||||
useUpdateWsEnvironment,
|
||||
useUpgradeProject
|
||||
} from "./queries";
|
||||
export { workspaceKeys } from "./query-keys";
|
||||
|
||||
@@ -2,7 +2,8 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { workspaceKeys } from "./queries";
|
||||
import { userKeys } from "../users/query-keys";
|
||||
import { workspaceKeys } from "./query-keys";
|
||||
import { TUpdateWorkspaceGroupRoleDTO } from "./types";
|
||||
|
||||
export const useAddGroupToWorkspace = () => {
|
||||
@@ -51,14 +52,25 @@ export const useUpdateGroupWorkspaceRole = () => {
|
||||
export const useDeleteGroupFromWorkspace = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({ groupSlug, projectSlug }: { groupSlug: string; projectSlug: string }) => {
|
||||
mutationFn: async ({
|
||||
groupSlug,
|
||||
projectSlug
|
||||
}: {
|
||||
groupSlug: string;
|
||||
projectSlug: string;
|
||||
username?: string;
|
||||
}) => {
|
||||
const {
|
||||
data: { groupMembership }
|
||||
} = await apiRequest.delete(`/api/v2/workspace/${projectSlug}/groups/${groupSlug}`);
|
||||
return groupMembership;
|
||||
},
|
||||
onSuccess: (_, { projectSlug }) => {
|
||||
onSuccess: (_, { projectSlug, username }) => {
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceGroupMemberships(projectSlug));
|
||||
|
||||
if (username) {
|
||||
queryClient.invalidateQueries(userKeys.listUserGroupMemberships(username));
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -15,9 +15,10 @@ import { TIntegration } from "../integrations/types";
|
||||
import { TPkiAlert } from "../pkiAlerts/types";
|
||||
import { TPkiCollection } from "../pkiCollections/types";
|
||||
import { EncryptedSecret } from "../secrets/types";
|
||||
import { userKeys } from "../users/queries";
|
||||
import { userKeys } from "../users/query-keys";
|
||||
import { TWorkspaceUser } from "../users/types";
|
||||
import { ProjectSlackConfig } from "../workflowIntegrations/types";
|
||||
import { workspaceKeys } from "./query-keys";
|
||||
import {
|
||||
CreateEnvironmentDTO,
|
||||
CreateWorkspaceDTO,
|
||||
@@ -37,55 +38,6 @@ import {
|
||||
Workspace
|
||||
} from "./types";
|
||||
|
||||
export const workspaceKeys = {
|
||||
getWorkspaceById: (workspaceId: string) => [{ workspaceId }, "workspace"] as const,
|
||||
getWorkspaceSecrets: (workspaceId: string) => [{ workspaceId }, "workspace-secrets"] as const,
|
||||
getWorkspaceIndexStatus: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-index-status"] as const,
|
||||
getProjectUpgradeStatus: (workspaceId: string) => [{ workspaceId }, "workspace-upgrade-status"],
|
||||
getWorkspaceMemberships: (orgId: string) => [{ orgId }, "workspace-memberships"],
|
||||
getWorkspaceAuthorization: (workspaceId: string) => [{ workspaceId }, "workspace-authorizations"],
|
||||
getWorkspaceIntegrations: (workspaceId: string) => [{ workspaceId }, "workspace-integrations"],
|
||||
getAllUserWorkspace: ["workspaces"] as const,
|
||||
getWorkspaceAuditLogs: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-audit-logs"] as const,
|
||||
getWorkspaceUsers: (workspaceId: string) => [{ workspaceId }, "workspace-users"] as const,
|
||||
getWorkspaceIdentityMemberships: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-identity-memberships"] as const,
|
||||
// allows invalidation using above key without knowing params
|
||||
getWorkspaceIdentityMembershipsWithParams: ({
|
||||
workspaceId,
|
||||
...params
|
||||
}: TListProjectIdentitiesDTO) =>
|
||||
[...workspaceKeys.getWorkspaceIdentityMemberships(workspaceId), params] as const,
|
||||
getWorkspaceGroupMemberships: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-groups"] as const,
|
||||
getWorkspaceCas: ({ projectSlug }: { projectSlug: string }) =>
|
||||
[{ projectSlug }, "workspace-cas"] as const,
|
||||
specificWorkspaceCas: ({ projectSlug, status }: { projectSlug: string; status?: CaStatus }) =>
|
||||
[...workspaceKeys.getWorkspaceCas({ projectSlug }), { status }] as const,
|
||||
allWorkspaceCertificates: () => ["workspace-certificates"] as const,
|
||||
forWorkspaceCertificates: (slug: string) =>
|
||||
[...workspaceKeys.allWorkspaceCertificates(), slug] as const,
|
||||
specificWorkspaceCertificates: ({
|
||||
slug,
|
||||
offset,
|
||||
limit
|
||||
}: {
|
||||
slug: string;
|
||||
offset: number;
|
||||
limit: number;
|
||||
}) => [...workspaceKeys.forWorkspaceCertificates(slug), { offset, limit }] as const,
|
||||
getWorkspacePkiAlerts: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-pki-alerts"] as const,
|
||||
getWorkspacePkiCollections: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-pki-collections"] as const,
|
||||
getWorkspaceCertificateTemplates: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-certificate-templates"] as const,
|
||||
getWorkspaceSlackConfig: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-slack-config"] as const
|
||||
};
|
||||
|
||||
const fetchWorkspaceById = async (workspaceId: string) => {
|
||||
const { data } = await apiRequest.get<{ workspace: Workspace }>(
|
||||
`/api/v1/workspace/${workspaceId}`
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import { TListProjectIdentitiesDTO } from "@app/hooks/api/workspace/types";
|
||||
|
||||
import type { CaStatus } from "../ca";
|
||||
|
||||
export const workspaceKeys = {
|
||||
getWorkspaceById: (workspaceId: string) => [{ workspaceId }, "workspace"] as const,
|
||||
getWorkspaceSecrets: (workspaceId: string) => [{ workspaceId }, "workspace-secrets"] as const,
|
||||
getWorkspaceIndexStatus: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-index-status"] as const,
|
||||
getProjectUpgradeStatus: (workspaceId: string) => [{ workspaceId }, "workspace-upgrade-status"],
|
||||
getWorkspaceMemberships: (orgId: string) => [{ orgId }, "workspace-memberships"],
|
||||
getWorkspaceAuthorization: (workspaceId: string) => [{ workspaceId }, "workspace-authorizations"],
|
||||
getWorkspaceIntegrations: (workspaceId: string) => [{ workspaceId }, "workspace-integrations"],
|
||||
getAllUserWorkspace: ["workspaces"] as const,
|
||||
getWorkspaceAuditLogs: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-audit-logs"] as const,
|
||||
getWorkspaceUsers: (workspaceId: string) => [{ workspaceId }, "workspace-users"] as const,
|
||||
getWorkspaceIdentityMemberships: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-identity-memberships"] as const,
|
||||
// allows invalidation using above key without knowing params
|
||||
getWorkspaceIdentityMembershipsWithParams: ({
|
||||
workspaceId,
|
||||
...params
|
||||
}: TListProjectIdentitiesDTO) =>
|
||||
[...workspaceKeys.getWorkspaceIdentityMemberships(workspaceId), params] as const,
|
||||
getWorkspaceGroupMemberships: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-groups"] as const,
|
||||
getWorkspaceCas: ({ projectSlug }: { projectSlug: string }) =>
|
||||
[{ projectSlug }, "workspace-cas"] as const,
|
||||
specificWorkspaceCas: ({ projectSlug, status }: { projectSlug: string; status?: CaStatus }) =>
|
||||
[...workspaceKeys.getWorkspaceCas({ projectSlug }), { status }] as const,
|
||||
allWorkspaceCertificates: () => ["workspace-certificates"] as const,
|
||||
forWorkspaceCertificates: (slug: string) =>
|
||||
[...workspaceKeys.allWorkspaceCertificates(), slug] as const,
|
||||
specificWorkspaceCertificates: ({
|
||||
slug,
|
||||
offset,
|
||||
limit
|
||||
}: {
|
||||
slug: string;
|
||||
offset: number;
|
||||
limit: number;
|
||||
}) => [...workspaceKeys.forWorkspaceCertificates(slug), { offset, limit }] as const,
|
||||
getWorkspacePkiAlerts: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-pki-alerts"] as const,
|
||||
getWorkspacePkiCollections: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-pki-collections"] as const,
|
||||
getWorkspaceCertificateTemplates: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-certificate-templates"] as const,
|
||||
getWorkspaceSlackConfig: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-slack-config"] as const
|
||||
};
|
||||
Reference in New Issue
Block a user