mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 08:34:52 +00:00
Continue ST V3 roles
This commit is contained in:
@@ -14,6 +14,7 @@ export {
|
||||
useGetOrgPlansTable,
|
||||
useGetOrgPlanTable,
|
||||
useGetOrgPmtMethods,
|
||||
useGetOrgServiceMemberships,
|
||||
useGetOrgTaxIds,
|
||||
useGetOrgTrialUrl,
|
||||
useRenameOrg,
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { ServiceMembershipOrg } from "../serviceTokens/types";
|
||||
import {
|
||||
BillingDetails,
|
||||
Invoice,
|
||||
@@ -15,7 +16,7 @@ import {
|
||||
TaxID
|
||||
} from "./types";
|
||||
|
||||
const organizationKeys = {
|
||||
export const organizationKeys = {
|
||||
getUserOrganizations: ["organization"] as const,
|
||||
getOrgPlanBillingInfo: (orgId: string) => [{ orgId }, "organization-plan-billing"] as const,
|
||||
getOrgPlanTable: (orgId: string) => [{ orgId }, "organization-plan-table"] as const,
|
||||
@@ -25,7 +26,8 @@ const organizationKeys = {
|
||||
getOrgPmtMethods: (orgId: string) => [{ orgId }, "organization-pmt-methods"] as const,
|
||||
getOrgTaxIds: (orgId: string) => [{ orgId }, "organization-tax-ids"] as const,
|
||||
getOrgInvoices: (orgId: string) => [{ orgId }, "organization-invoices"] as const,
|
||||
getOrgLicenses: (orgId: string) => [{ orgId }, "organization-licenses"] as const
|
||||
getOrgLicenses: (orgId: string) => [{ orgId }, "organization-licenses"] as const,
|
||||
getOrgServiceMemberships: (orgId: string) => [{ orgId }, "organization-service-memberships"] as const,
|
||||
};
|
||||
|
||||
export const fetchOrganizations = async () => {
|
||||
@@ -349,6 +351,22 @@ export const useGetOrgLicenses = (organizationId: string) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetOrgServiceMemberships = (organizationId: string) => {
|
||||
return useQuery({
|
||||
queryKey: organizationKeys.getOrgServiceMemberships(organizationId),
|
||||
queryFn: async () => {
|
||||
const {
|
||||
data: { serviceMemberships }
|
||||
} = await apiRequest.get<{ serviceMemberships: ServiceMembershipOrg[] }>(
|
||||
`/api/v2/organizations/${organizationId}/service-memberships`
|
||||
);
|
||||
|
||||
return serviceMemberships;
|
||||
},
|
||||
enabled: true
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteOrgById = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { workspaceKeys } from "../workspace/queries";
|
||||
import { organizationKeys } from "../organization/queries";
|
||||
import {
|
||||
CreateServiceTokenDataV3DTO,
|
||||
CreateServiceTokenDataV3Res,
|
||||
@@ -74,7 +74,7 @@ export const useCreateServiceTokenV3 = () => {
|
||||
return data;
|
||||
},
|
||||
onSuccess: ({ serviceTokenData }) => {
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceServiceTokenDataV3(serviceTokenData.workspace));
|
||||
queryClient.invalidateQueries(organizationKeys.getOrgServiceMemberships(serviceTokenData.organization));
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -104,8 +104,8 @@ export const useUpdateServiceTokenV3 = () => {
|
||||
|
||||
return serviceTokenData;
|
||||
},
|
||||
onSuccess: ({ workspace }) => {
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceServiceTokenDataV3(workspace));
|
||||
onSuccess: ({ organization }) => {
|
||||
queryClient.invalidateQueries(organizationKeys.getOrgServiceMemberships(organization));
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -119,8 +119,8 @@ export const useDeleteServiceTokenV3 = () => {
|
||||
const { data: { serviceTokenData } } = await apiRequest.delete(`/api/v3/service-token/${serviceTokenDataId}`);
|
||||
return serviceTokenData;
|
||||
},
|
||||
onSuccess: ({ workspace }) => {
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceServiceTokenDataV3(workspace));
|
||||
onSuccess: ({ organization }) => {
|
||||
queryClient.invalidateQueries(organizationKeys.getOrgServiceMemberships(organization));
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -1,3 +1,5 @@
|
||||
import { TRole } from "../roles/types";
|
||||
|
||||
export type ServiceTokenScope = {
|
||||
environment: string;
|
||||
secretPath: string;
|
||||
@@ -46,12 +48,7 @@ export type ServiceTokenV3TrustedIp = {
|
||||
export type ServiceTokenDataV3 = {
|
||||
_id: string;
|
||||
name: string;
|
||||
role: string;
|
||||
customRole?: {
|
||||
name: string;
|
||||
slug: string;
|
||||
};
|
||||
workspace: string;
|
||||
organization: string;
|
||||
isActive: boolean;
|
||||
refreshTokenLastUsed?: string;
|
||||
accessTokenLastUsed?: string;
|
||||
@@ -65,18 +62,35 @@ export type ServiceTokenDataV3 = {
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type ServiceMembershipOrg = {
|
||||
_id: string;
|
||||
service: ServiceTokenDataV3;
|
||||
organization: string;
|
||||
role: "admin" | "member" | "viewer" | "custom";
|
||||
customRole?: TRole;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export type ServiceMembership = {
|
||||
_id: string;
|
||||
service: ServiceTokenDataV3;
|
||||
organization: string;
|
||||
role: "admin" | "member" | "viewer" | "custom";
|
||||
customRole?: TRole;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export type CreateServiceTokenDataV3DTO = {
|
||||
name: string;
|
||||
organizationId: string;
|
||||
role?: string;
|
||||
workspaceId: string;
|
||||
publicKey: string;
|
||||
trustedIps: {
|
||||
ipAddress: string;
|
||||
}[];
|
||||
expiresIn?: number;
|
||||
accessTokenTTL: number;
|
||||
encryptedKey: string;
|
||||
nonce: string;
|
||||
isRefreshTokenRotationEnabled: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
export {
|
||||
useAddServiceToWorkspace,
|
||||
useAddUserToWorkspace,
|
||||
useCreateWorkspace,
|
||||
useCreateWsEnvironment,
|
||||
useDeleteServiceFromWorkspace,
|
||||
useDeleteUserFromWorkspace,
|
||||
useDeleteWorkspace,
|
||||
useDeleteWsEnvironment,
|
||||
@@ -12,11 +14,12 @@ export {
|
||||
useGetWorkspaceIndexStatus,
|
||||
useGetWorkspaceIntegrations,
|
||||
useGetWorkspaceSecrets,
|
||||
useGetWorkspaceServiceTokenDataV3,
|
||||
useGetWorkspaceServiceMemberships,
|
||||
useGetWorkspaceUsers,
|
||||
useNameWorkspaceSecrets,
|
||||
useRenameWorkspace,
|
||||
useReorderWsEnvironment,
|
||||
useToggleAutoCapitalization,
|
||||
useUpdateUserWorkspaceRole,
|
||||
useUpdateWsEnvironment} from "./queries";
|
||||
useUpdateWsEnvironment,
|
||||
} from "./queries";
|
||||
|
||||
@@ -5,7 +5,7 @@ import { apiRequest } from "@app/config/request";
|
||||
import { IntegrationAuth } from "../integrationAuth/types";
|
||||
import { TIntegration } from "../integrations/types";
|
||||
import { EncryptedSecret } from "../secrets/types";
|
||||
import { ServiceTokenDataV3 } from "../serviceTokens/types";
|
||||
import { ServiceMembership } from "../serviceTokens/types";
|
||||
import { TWorkspaceUser } from "../users/types";
|
||||
import {
|
||||
CreateEnvironmentDTO,
|
||||
@@ -32,7 +32,8 @@ export const workspaceKeys = {
|
||||
getWorkspaceAuditLogs: (workspaceId: string) => [{ workspaceId }] as const,
|
||||
getWorkspaceUsers: (workspaceId: string) => [{ workspaceId }] as const,
|
||||
getWorkspaceServiceTokenDataV3: (workspaceId: string) =>
|
||||
[{ workspaceId }, "workspace-service-token-data-v3"] as const
|
||||
[{ workspaceId }, "workspace-service-token-data-v3"] as const,
|
||||
getWorkspaceServiceMemberships: (workspaceId: string) => [{ workspaceId }, "organization-service-memberships"] as const
|
||||
};
|
||||
|
||||
const fetchWorkspaceById = async (workspaceId: string) => {
|
||||
@@ -356,17 +357,69 @@ export const useUpdateUserWorkspaceRole = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetWorkspaceServiceTokenDataV3 = (workspaceId: string) => {
|
||||
return useQuery({
|
||||
queryKey: workspaceKeys.getWorkspaceServiceTokenDataV3(workspaceId),
|
||||
queryFn: async () => {
|
||||
export const useAddServiceToWorkspace = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
serviceId,
|
||||
workspaceId,
|
||||
role
|
||||
}: {
|
||||
serviceId: string;
|
||||
workspaceId: string;
|
||||
role?: string;
|
||||
}) => {
|
||||
|
||||
const {
|
||||
data: { serviceTokenData }
|
||||
} = await apiRequest.get<{ serviceTokenData: ServiceTokenDataV3[] }>(
|
||||
`/api/v3/workspaces/${workspaceId}/service-token`
|
||||
data: { serviceMembership }
|
||||
} = await apiRequest.post(`/api/v2/workspace/${workspaceId}/service-memberships`, {
|
||||
serviceId,
|
||||
role
|
||||
});
|
||||
|
||||
return serviceMembership;
|
||||
},
|
||||
onSuccess: (_, { workspaceId }) => {
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceServiceMemberships(workspaceId));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteServiceFromWorkspace = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
serviceId,
|
||||
workspaceId,
|
||||
}: {
|
||||
serviceId: string;
|
||||
workspaceId: string;
|
||||
}) => {
|
||||
|
||||
const {
|
||||
data: { serviceMembership }
|
||||
} = await apiRequest.delete(`/api/v2/workspace/${workspaceId}/service-memberships/${serviceId}`);
|
||||
|
||||
return serviceMembership;
|
||||
},
|
||||
onSuccess: (_, { workspaceId }) => {
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceServiceMemberships(workspaceId));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetWorkspaceServiceMemberships = (workspaceId: string) => {
|
||||
return useQuery({
|
||||
queryKey: workspaceKeys.getWorkspaceServiceMemberships(workspaceId),
|
||||
queryFn: async () => {
|
||||
|
||||
const {
|
||||
data: { serviceMemberships }
|
||||
} = await apiRequest.get<{ serviceMemberships: ServiceMembership[] }>(
|
||||
`/api/v2/workspace/${workspaceId}/service-memberships`
|
||||
);
|
||||
|
||||
return serviceTokenData;
|
||||
return serviceMemberships;
|
||||
},
|
||||
enabled: true
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user