mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-12 07:29:35 +00:00
feat: almost done with most ts stuff
This commit is contained in:
@@ -39,7 +39,7 @@ export const useGetIdentityAuthTemplates = (dto: GetIdentityAuthTemplatesDTO) =>
|
||||
});
|
||||
return data;
|
||||
},
|
||||
enabled: Boolean(dto.organizationId)
|
||||
enabled: Boolean(dto.organizationId && !dto.isDisabled)
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ export interface GetIdentityAuthTemplatesDTO {
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
search?: string;
|
||||
isDisabled?: boolean;
|
||||
}
|
||||
|
||||
export interface MachineAuthTemplateUsage {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { packRules } from "@casl/ability/extra";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
@@ -71,14 +70,10 @@ export const useCreateOrgRole = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<TOrgRole, object, TCreateOrgRoleDTO>({
|
||||
mutationFn: async ({ orgId, permissions, ...dto }: TCreateOrgRoleDTO) => {
|
||||
mutationFn: async ({ orgId, ...dto }: TCreateOrgRoleDTO) => {
|
||||
const {
|
||||
data: { role }
|
||||
} = await apiRequest.post(`/api/v1/organization/${orgId}/roles`, {
|
||||
...dto,
|
||||
// TODO(simp): removing packing
|
||||
permissions: permissions.length ? packRules(permissions) : []
|
||||
});
|
||||
} = await apiRequest.post(`/api/v1/organization/${orgId}/roles`, dto);
|
||||
|
||||
return role;
|
||||
},
|
||||
@@ -92,13 +87,10 @@ export const useUpdateOrgRole = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<TOrgRole, object, TUpdateOrgRoleDTO>({
|
||||
mutationFn: async ({ id, orgId, permissions, ...dto }: TUpdateOrgRoleDTO) => {
|
||||
mutationFn: async ({ id, orgId, ...dto }: TUpdateOrgRoleDTO) => {
|
||||
const {
|
||||
data: { role }
|
||||
} = await apiRequest.patch(`/api/v1/organization/${orgId}/roles/${id}`, {
|
||||
...dto,
|
||||
permissions: permissions ? packRules(permissions) : undefined
|
||||
});
|
||||
} = await apiRequest.patch(`/api/v1/organization/${orgId}/roles/${id}`, dto);
|
||||
|
||||
return role;
|
||||
},
|
||||
|
||||
@@ -80,10 +80,7 @@ const getOrgRoles = async (orgId: string) => {
|
||||
const { data } = await apiRequest.get<{
|
||||
data: { roles: Array<Omit<TOrgRole, "permissions"> & { permissions: unknown }> };
|
||||
}>(`/api/v1/organization/${orgId}/roles`);
|
||||
return data.data.roles.map(({ permissions, ...el }) => ({
|
||||
...el,
|
||||
permissions: unpackRules(permissions as PackRule<TPermission>[])
|
||||
}));
|
||||
return data.data.roles;
|
||||
};
|
||||
|
||||
export const useGetOrgRoles = (orgId: string, enable = true) =>
|
||||
@@ -102,7 +99,7 @@ export const useGetOrgRole = (orgId: string, roleId: string) =>
|
||||
}>(`/api/v1/organization/${orgId}/roles/${roleId}`);
|
||||
return {
|
||||
...data.role,
|
||||
permissions: unpackRules(data.role.permissions as PackRule<TPermission>[])
|
||||
permissions: data.role.permissions as PackRule<TPermission>[]
|
||||
};
|
||||
},
|
||||
enabled: Boolean(orgId && roleId)
|
||||
|
||||
+12
-3
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
faArrowDown,
|
||||
faArrowUp,
|
||||
faBan,
|
||||
faEdit,
|
||||
faEllipsisV,
|
||||
faEye,
|
||||
@@ -30,7 +31,7 @@ import {
|
||||
THead,
|
||||
Tr
|
||||
} from "@app/components/v2";
|
||||
import { OrgPermissionSubjects, useOrganization } from "@app/context";
|
||||
import { OrgPermissionSubjects, useOrganization, useSubscription } from "@app/context";
|
||||
import { OrgPermissionMachineIdentityAuthTemplateActions } from "@app/context/OrgPermissionContext/types";
|
||||
import {
|
||||
getUserTablePreference,
|
||||
@@ -86,12 +87,14 @@ export const IdentityAuthTemplatesTable = ({ handlePopUpOpen }: Props) => {
|
||||
};
|
||||
|
||||
const organizationId = currentOrg?.id || "";
|
||||
const { subscription } = useSubscription();
|
||||
|
||||
const { data, isPending, isFetching } = useGetIdentityAuthTemplates({
|
||||
organizationId,
|
||||
limit,
|
||||
offset,
|
||||
search: debouncedSearch
|
||||
search: debouncedSearch,
|
||||
isDisabled: !subscription.machineIdentityAuthTemplates
|
||||
});
|
||||
|
||||
const { templates = [], totalCount = 0 } = data ?? {};
|
||||
@@ -172,7 +175,10 @@ export const IdentityAuthTemplatesTable = ({ handlePopUpOpen }: Props) => {
|
||||
</Tr>
|
||||
</THead>
|
||||
<TBody>
|
||||
{isPending && <TableSkeleton columns={4} innerKey="identity-auth-templates" />}
|
||||
{subscription.machineIdentityAuthTemplates && isPending && (
|
||||
<TableSkeleton columns={4} innerKey="identity-auth-templates" />
|
||||
)}
|
||||
|
||||
{!isPending &&
|
||||
templates?.map((template) => (
|
||||
<Tr
|
||||
@@ -265,6 +271,9 @@ export const IdentityAuthTemplatesTable = ({ handlePopUpOpen }: Props) => {
|
||||
onChangePerPage={handlePerPageChange}
|
||||
/>
|
||||
)}
|
||||
{!subscription.machineIdentityAuthTemplates && (
|
||||
<EmptyState title="This feature is not yet activated for your license." icon={faBan} />
|
||||
)}
|
||||
{!isPending && templates.length === 0 && (
|
||||
<EmptyState
|
||||
title={
|
||||
|
||||
Reference in New Issue
Block a user