mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 07:27:58 +00:00
feat(frontend): remove SecretApprovalPolicyList
This commit is contained in:
@@ -4,13 +4,11 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|||||||
|
|
||||||
import { Tab, TabList, TabPanel, Tabs } from "@app/components/v2";
|
import { Tab, TabList, TabPanel, Tabs } from "@app/components/v2";
|
||||||
import { Badge } from "@app/components/v2/Badge";
|
import { Badge } from "@app/components/v2/Badge";
|
||||||
import { Divider } from "@app/components/v2/Divider";
|
|
||||||
import { useWorkspace } from "@app/context";
|
import { useWorkspace } from "@app/context";
|
||||||
import { useGetAccessRequestsCount, useGetSecretApprovalRequestCount } from "@app/hooks/api";
|
import { useGetAccessRequestsCount, useGetSecretApprovalRequestCount } from "@app/hooks/api";
|
||||||
|
|
||||||
import { AccessApprovalRequest } from "./components/AccessApprovalRequest";
|
import { AccessApprovalRequest } from "./components/AccessApprovalRequest";
|
||||||
import { ApprovalPolicyList } from "./components/ApprovalPolicyList";
|
import { ApprovalPolicyList } from "./components/ApprovalPolicyList";
|
||||||
import { SecretApprovalPolicyList } from "./components/SecretApprovalPolicyList";
|
|
||||||
import { SecretApprovalRequest } from "./components/SecretApprovalRequest";
|
import { SecretApprovalRequest } from "./components/SecretApprovalRequest";
|
||||||
|
|
||||||
enum TabSection {
|
enum TabSection {
|
||||||
@@ -59,17 +57,12 @@ export const SecretApprovalPage = () => {
|
|||||||
Secret Requests
|
Secret Requests
|
||||||
{Boolean(secretApprovalReqCount?.open) && (<Badge className="ml-2">{secretApprovalReqCount?.open}</Badge>)}
|
{Boolean(secretApprovalReqCount?.open) && (<Badge className="ml-2">{secretApprovalReqCount?.open}</Badge>)}
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab value={TabSection.SecretPolicies}>Secret Policies</Tab>
|
|
||||||
<Divider />
|
|
||||||
<Tab value={TabSection.ResourceApprovalRequests}>
|
<Tab value={TabSection.ResourceApprovalRequests}>
|
||||||
Access Requests
|
Access Requests
|
||||||
{Boolean(accessApprovalRequestCount?.pendingCount) && <Badge className="ml-2">{accessApprovalRequestCount?.pendingCount}</Badge>}
|
{Boolean(accessApprovalRequestCount?.pendingCount) && <Badge className="ml-2">{accessApprovalRequestCount?.pendingCount}</Badge>}
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab value={TabSection.Policies}>Policies</Tab>
|
<Tab value={TabSection.Policies}>Policies</Tab>
|
||||||
</TabList>
|
</TabList>
|
||||||
<TabPanel value={TabSection.SecretPolicies}>
|
|
||||||
<SecretApprovalPolicyList workspaceId={projectId} />
|
|
||||||
</TabPanel>
|
|
||||||
<TabPanel value={TabSection.SecretApprovalRequests}>
|
<TabPanel value={TabSection.SecretApprovalRequests}>
|
||||||
<SecretApprovalRequest />
|
<SecretApprovalRequest />
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
|
|||||||
-178
@@ -1,178 +0,0 @@
|
|||||||
import { faFileShield, faPlus } from "@fortawesome/free-solid-svg-icons";
|
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
||||||
|
|
||||||
import { createNotification } from "@app/components/notifications";
|
|
||||||
import { ProjectPermissionCan } from "@app/components/permissions";
|
|
||||||
import {
|
|
||||||
Button,
|
|
||||||
DeleteActionModal,
|
|
||||||
EmptyState,
|
|
||||||
Modal,
|
|
||||||
ModalContent,
|
|
||||||
Table,
|
|
||||||
TableContainer,
|
|
||||||
TableSkeleton,
|
|
||||||
TBody,
|
|
||||||
Td,
|
|
||||||
Th,
|
|
||||||
THead,
|
|
||||||
Tr,
|
|
||||||
UpgradePlanModal
|
|
||||||
} from "@app/components/v2";
|
|
||||||
import {
|
|
||||||
ProjectPermissionActions,
|
|
||||||
ProjectPermissionSub,
|
|
||||||
useProjectPermission,
|
|
||||||
useSubscription
|
|
||||||
} from "@app/context";
|
|
||||||
import { usePopUp } from "@app/hooks";
|
|
||||||
import {
|
|
||||||
useDeleteSecretApprovalPolicy,
|
|
||||||
useGetSecretApprovalPolicies,
|
|
||||||
useGetWorkspaceUsers
|
|
||||||
} from "@app/hooks/api";
|
|
||||||
import { TSecretApprovalPolicy } from "@app/hooks/api/types";
|
|
||||||
|
|
||||||
import { SecretApprovalPolicyRow } from "./components/SecretApprovalPolicyRow";
|
|
||||||
import { SecretPolicyForm } from "./components/SecretPolicyForm";
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
workspaceId: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const SecretApprovalPolicyList = ({ workspaceId }: Props) => {
|
|
||||||
const { handlePopUpToggle, handlePopUpOpen, handlePopUpClose, popUp } = usePopUp([
|
|
||||||
"secretPolicyForm",
|
|
||||||
"deletePolicy",
|
|
||||||
"upgradePlan"
|
|
||||||
] as const);
|
|
||||||
const { permission } = useProjectPermission();
|
|
||||||
const { subscription } = useSubscription();
|
|
||||||
|
|
||||||
const { data: members } = useGetWorkspaceUsers(workspaceId);
|
|
||||||
const { data: policies, isLoading: isPoliciesLoading } = useGetSecretApprovalPolicies({
|
|
||||||
workspaceId,
|
|
||||||
options: {
|
|
||||||
enabled: permission.can(ProjectPermissionActions.Read, ProjectPermissionSub.SecretApproval)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const { mutateAsync: deleteSecretApprovalPolicy } = useDeleteSecretApprovalPolicy();
|
|
||||||
|
|
||||||
const handleDeletePolicy = async () => {
|
|
||||||
const { id } = popUp.deletePolicy.data as TSecretApprovalPolicy;
|
|
||||||
try {
|
|
||||||
await deleteSecretApprovalPolicy({
|
|
||||||
workspaceId,
|
|
||||||
id
|
|
||||||
});
|
|
||||||
createNotification({
|
|
||||||
type: "success",
|
|
||||||
text: "Successfully deleted policy"
|
|
||||||
});
|
|
||||||
handlePopUpClose("deletePolicy");
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err);
|
|
||||||
createNotification({
|
|
||||||
type: "error",
|
|
||||||
text: "Failed to delete policy"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<div className="mb-6 flex justify-between">
|
|
||||||
<div className="flex flex-col">
|
|
||||||
<span className="text-xl font-semibold text-mineshaft-100">Approval Policies</span>
|
|
||||||
<div className="mt-2 text-sm text-bunker-300">
|
|
||||||
Implement policies to prevent unauthorized secret changes.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<ProjectPermissionCan
|
|
||||||
I={ProjectPermissionActions.Create}
|
|
||||||
a={ProjectPermissionSub.SecretApproval}
|
|
||||||
>
|
|
||||||
{(isAllowed) => (
|
|
||||||
<Button
|
|
||||||
onClick={() => {
|
|
||||||
if (subscription && !subscription?.secretApproval) {
|
|
||||||
handlePopUpOpen("upgradePlan");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
handlePopUpOpen("secretPolicyForm");
|
|
||||||
}}
|
|
||||||
leftIcon={<FontAwesomeIcon icon={faPlus} />}
|
|
||||||
isDisabled={!isAllowed}
|
|
||||||
>
|
|
||||||
Create policy
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</ProjectPermissionCan>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<TableContainer>
|
|
||||||
<Table>
|
|
||||||
<THead>
|
|
||||||
<Tr>
|
|
||||||
<Th>Name</Th>
|
|
||||||
<Th>Environment</Th>
|
|
||||||
<Th>Secret Path</Th>
|
|
||||||
<Th>Eligible Approvers</Th>
|
|
||||||
<Th>Approval Required</Th>
|
|
||||||
</Tr>
|
|
||||||
</THead>
|
|
||||||
<TBody>
|
|
||||||
{isPoliciesLoading && (
|
|
||||||
<TableSkeleton columns={4} innerKey="secret-policies" className="bg-mineshaft-700" />
|
|
||||||
)}
|
|
||||||
{!isPoliciesLoading && !policies?.length && (
|
|
||||||
<Tr>
|
|
||||||
<Td colSpan={5}>
|
|
||||||
<EmptyState title="No policies found" icon={faFileShield} />
|
|
||||||
</Td>
|
|
||||||
</Tr>
|
|
||||||
)}
|
|
||||||
{policies?.map((policy) => (
|
|
||||||
<SecretApprovalPolicyRow
|
|
||||||
workspaceId={workspaceId}
|
|
||||||
policy={policy}
|
|
||||||
key={policy.id}
|
|
||||||
members={members}
|
|
||||||
onEdit={() => handlePopUpOpen("secretPolicyForm", policy)}
|
|
||||||
onDelete={() => handlePopUpOpen("deletePolicy", policy)}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</TBody>
|
|
||||||
</Table>
|
|
||||||
</TableContainer>
|
|
||||||
<Modal
|
|
||||||
isOpen={popUp.secretPolicyForm.isOpen}
|
|
||||||
onOpenChange={(isOpen) => handlePopUpToggle("secretPolicyForm", isOpen)}
|
|
||||||
>
|
|
||||||
<ModalContent title={popUp.secretPolicyForm.data ? "Edit policy" : "Create policy"}>
|
|
||||||
<SecretPolicyForm
|
|
||||||
workspaceId={workspaceId}
|
|
||||||
isOpen={popUp.secretPolicyForm.isOpen}
|
|
||||||
onToggle={(isOpen) => handlePopUpToggle("secretPolicyForm", isOpen)}
|
|
||||||
members={members}
|
|
||||||
editValues={popUp.secretPolicyForm.data as TSecretApprovalPolicy}
|
|
||||||
/>
|
|
||||||
</ModalContent>
|
|
||||||
</Modal>
|
|
||||||
<DeleteActionModal
|
|
||||||
isOpen={popUp.deletePolicy.isOpen}
|
|
||||||
deleteKey="remove"
|
|
||||||
title="Do you want to remove this polciy?"
|
|
||||||
onChange={(isOpen) => handlePopUpToggle("deletePolicy", isOpen)}
|
|
||||||
onDeleteApproved={handleDeletePolicy}
|
|
||||||
/>
|
|
||||||
<UpgradePlanModal
|
|
||||||
isOpen={popUp.upgradePlan.isOpen}
|
|
||||||
onOpenChange={(isOpen) => handlePopUpToggle("upgradePlan", isOpen)}
|
|
||||||
text="You can add secret approval policy if you switch to Infisical's Enterprise plan."
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
-148
@@ -1,148 +0,0 @@
|
|||||||
import { useState } from "react";
|
|
||||||
import { faCheckCircle, faPencil, faTrash } from "@fortawesome/free-solid-svg-icons";
|
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
||||||
|
|
||||||
import { ProjectPermissionCan } from "@app/components/permissions";
|
|
||||||
import {
|
|
||||||
DropdownMenu,
|
|
||||||
DropdownMenuContent,
|
|
||||||
DropdownMenuItem,
|
|
||||||
DropdownMenuLabel,
|
|
||||||
DropdownMenuTrigger,
|
|
||||||
IconButton,
|
|
||||||
Input,
|
|
||||||
Td,
|
|
||||||
Tr
|
|
||||||
} from "@app/components/v2";
|
|
||||||
import { ProjectPermissionActions, ProjectPermissionSub, useProjectPermission } from "@app/context";
|
|
||||||
import { useUpdateSecretApprovalPolicy } from "@app/hooks/api";
|
|
||||||
import { TSecretApprovalPolicy } from "@app/hooks/api/types";
|
|
||||||
import { TWorkspaceUser } from "@app/hooks/api/users/types";
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
policy: TSecretApprovalPolicy;
|
|
||||||
members?: TWorkspaceUser[];
|
|
||||||
workspaceId: string;
|
|
||||||
onEdit: () => void;
|
|
||||||
onDelete: () => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const SecretApprovalPolicyRow = ({
|
|
||||||
policy,
|
|
||||||
members = [],
|
|
||||||
workspaceId,
|
|
||||||
onEdit,
|
|
||||||
onDelete
|
|
||||||
}: Props) => {
|
|
||||||
const [selectedApprovers, setSelectedApprovers] = useState<string[]>([]);
|
|
||||||
const { mutate: updateSecretApprovalPolicy, isLoading } = useUpdateSecretApprovalPolicy();
|
|
||||||
const { permission } = useProjectPermission();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Tr>
|
|
||||||
<Td>{policy.name}</Td>
|
|
||||||
<Td>{policy.environment.slug}</Td>
|
|
||||||
<Td>{policy.secretPath || "*"}</Td>
|
|
||||||
<Td>
|
|
||||||
<DropdownMenu
|
|
||||||
onOpenChange={(isOpen) => {
|
|
||||||
if (!isOpen) {
|
|
||||||
updateSecretApprovalPolicy(
|
|
||||||
{
|
|
||||||
workspaceId,
|
|
||||||
id: policy.id,
|
|
||||||
approvers: selectedApprovers
|
|
||||||
},
|
|
||||||
{
|
|
||||||
onSettled: () => {
|
|
||||||
setSelectedApprovers([]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
setSelectedApprovers(policy.userApprovers.map(({ userId }) => userId));
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<DropdownMenuTrigger
|
|
||||||
asChild
|
|
||||||
disabled={
|
|
||||||
isLoading ||
|
|
||||||
permission.cannot(ProjectPermissionActions.Edit, ProjectPermissionSub.SecretApproval)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Input
|
|
||||||
isReadOnly
|
|
||||||
value={
|
|
||||||
policy?.userApprovers.length ? `${policy.userApprovers.length} selected` : "None"
|
|
||||||
}
|
|
||||||
className="text-left"
|
|
||||||
/>
|
|
||||||
</DropdownMenuTrigger>
|
|
||||||
<DropdownMenuContent
|
|
||||||
style={{ width: "var(--radix-dropdown-menu-trigger-width)" }}
|
|
||||||
align="start"
|
|
||||||
>
|
|
||||||
<DropdownMenuLabel>
|
|
||||||
Select members that are allowed to approve changes
|
|
||||||
</DropdownMenuLabel>
|
|
||||||
{members?.map(({ user }) => {
|
|
||||||
const isChecked = selectedApprovers.includes(user.id);
|
|
||||||
return (
|
|
||||||
<DropdownMenuItem
|
|
||||||
onClick={(evt) => {
|
|
||||||
evt.preventDefault();
|
|
||||||
setSelectedApprovers((state) =>
|
|
||||||
isChecked ? state.filter((el) => el !== user.id) : [...state, user.id]
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
key={`create-policy-members-${user.id}`}
|
|
||||||
iconPos="right"
|
|
||||||
icon={isChecked && <FontAwesomeIcon icon={faCheckCircle} />}
|
|
||||||
>
|
|
||||||
{user.username}
|
|
||||||
</DropdownMenuItem>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</Td>
|
|
||||||
<Td>{policy.approvals}</Td>
|
|
||||||
<Td>
|
|
||||||
<div className="flex items-center justify-end space-x-4">
|
|
||||||
<ProjectPermissionCan
|
|
||||||
I={ProjectPermissionActions.Edit}
|
|
||||||
a={ProjectPermissionSub.SecretApproval}
|
|
||||||
renderTooltip
|
|
||||||
allowedLabel="Edit"
|
|
||||||
>
|
|
||||||
{(isAllowed) => (
|
|
||||||
<IconButton variant="plain" ariaLabel="edit" onClick={onEdit} isDisabled={!isAllowed}>
|
|
||||||
<FontAwesomeIcon icon={faPencil} size="lg" />
|
|
||||||
</IconButton>
|
|
||||||
)}
|
|
||||||
</ProjectPermissionCan>
|
|
||||||
<ProjectPermissionCan
|
|
||||||
I={ProjectPermissionActions.Delete}
|
|
||||||
a={ProjectPermissionSub.SecretApproval}
|
|
||||||
renderTooltip
|
|
||||||
allowedLabel="Delete"
|
|
||||||
>
|
|
||||||
{(isAllowed) => (
|
|
||||||
<IconButton
|
|
||||||
variant="plain"
|
|
||||||
colorSchema="danger"
|
|
||||||
size="lg"
|
|
||||||
ariaLabel="edit"
|
|
||||||
onClick={onDelete}
|
|
||||||
isDisabled={!isAllowed}
|
|
||||||
>
|
|
||||||
<FontAwesomeIcon icon={faTrash} />
|
|
||||||
</IconButton>
|
|
||||||
)}
|
|
||||||
</ProjectPermissionCan>
|
|
||||||
</div>
|
|
||||||
</Td>
|
|
||||||
</Tr>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
-262
@@ -1,262 +0,0 @@
|
|||||||
import { Controller, useForm } from "react-hook-form";
|
|
||||||
import { faCheckCircle } from "@fortawesome/free-solid-svg-icons";
|
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
|
||||||
import { z } from "zod";
|
|
||||||
|
|
||||||
import { createNotification } from "@app/components/notifications";
|
|
||||||
import {
|
|
||||||
Button,
|
|
||||||
DropdownMenu,
|
|
||||||
DropdownMenuContent,
|
|
||||||
DropdownMenuItem,
|
|
||||||
DropdownMenuLabel,
|
|
||||||
DropdownMenuTrigger,
|
|
||||||
FormControl,
|
|
||||||
Input,
|
|
||||||
Select,
|
|
||||||
SelectItem
|
|
||||||
} from "@app/components/v2";
|
|
||||||
import { SecretPathInput } from "@app/components/v2/SecretPathInput";
|
|
||||||
import { useWorkspace } from "@app/context";
|
|
||||||
import { useCreateSecretApprovalPolicy, useUpdateSecretApprovalPolicy } from "@app/hooks/api";
|
|
||||||
import { TSecretApprovalPolicy } from "@app/hooks/api/types";
|
|
||||||
import { TWorkspaceUser } from "@app/hooks/api/users/types";
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
isOpen?: boolean;
|
|
||||||
onToggle: (isOpen: boolean) => void;
|
|
||||||
members?: TWorkspaceUser[];
|
|
||||||
workspaceId: string;
|
|
||||||
editValues?: TSecretApprovalPolicy;
|
|
||||||
};
|
|
||||||
|
|
||||||
const formSchema = z
|
|
||||||
.object({
|
|
||||||
environment: z.string(),
|
|
||||||
name: z.string().optional(),
|
|
||||||
secretPath: z.string().optional().nullable(),
|
|
||||||
approvals: z.number().min(1),
|
|
||||||
approvers: z.string().array().min(1)
|
|
||||||
})
|
|
||||||
.refine((data) => data.approvals <= data.approvers.length, {
|
|
||||||
path: ["approvals"],
|
|
||||||
message: "The number of approvals should be lower than the number of approvers."
|
|
||||||
});
|
|
||||||
|
|
||||||
type TFormSchema = z.infer<typeof formSchema>;
|
|
||||||
|
|
||||||
export const SecretPolicyForm = ({
|
|
||||||
onToggle,
|
|
||||||
members = [],
|
|
||||||
workspaceId,
|
|
||||||
editValues
|
|
||||||
}: Props) => {
|
|
||||||
const {
|
|
||||||
control,
|
|
||||||
handleSubmit,
|
|
||||||
watch,
|
|
||||||
formState: { isSubmitting }
|
|
||||||
} = useForm<TFormSchema>({
|
|
||||||
resolver: zodResolver(formSchema),
|
|
||||||
values: editValues
|
|
||||||
? {
|
|
||||||
...editValues,
|
|
||||||
approvers: editValues.userApprovers.map(({ userId }) => userId),
|
|
||||||
environment: editValues.environment.slug
|
|
||||||
}
|
|
||||||
: undefined
|
|
||||||
});
|
|
||||||
const { currentWorkspace } = useWorkspace();
|
|
||||||
const selectedEnvironment = watch("environment");
|
|
||||||
|
|
||||||
const environments = currentWorkspace?.environments || [];
|
|
||||||
|
|
||||||
const isEditMode = Boolean(editValues);
|
|
||||||
|
|
||||||
const { mutateAsync: createSecretApprovalPolicy } = useCreateSecretApprovalPolicy();
|
|
||||||
const { mutateAsync: updateSecretApprovalPolicy } = useUpdateSecretApprovalPolicy();
|
|
||||||
|
|
||||||
const handleCreatePolicy = async (data: TFormSchema) => {
|
|
||||||
try {
|
|
||||||
await createSecretApprovalPolicy({
|
|
||||||
...data,
|
|
||||||
workspaceId
|
|
||||||
});
|
|
||||||
createNotification({
|
|
||||||
type: "success",
|
|
||||||
text: "Successfully created policy"
|
|
||||||
});
|
|
||||||
onToggle(false);
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err);
|
|
||||||
createNotification({
|
|
||||||
type: "error",
|
|
||||||
text: "Failed to create policy"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleUpdatePolicy = async (data: TFormSchema) => {
|
|
||||||
if (!editValues?.id) return;
|
|
||||||
try {
|
|
||||||
await updateSecretApprovalPolicy({
|
|
||||||
id: editValues?.id,
|
|
||||||
...data,
|
|
||||||
secretPath: data.secretPath || null,
|
|
||||||
workspaceId
|
|
||||||
});
|
|
||||||
createNotification({
|
|
||||||
type: "success",
|
|
||||||
text: "Successfully updated policy"
|
|
||||||
});
|
|
||||||
onToggle(false);
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err);
|
|
||||||
createNotification({
|
|
||||||
type: "error",
|
|
||||||
text: "failed to update policy"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleFormSubmit = async (data: TFormSchema) => {
|
|
||||||
if (isEditMode) {
|
|
||||||
await handleUpdatePolicy(data);
|
|
||||||
} else {
|
|
||||||
await handleCreatePolicy(data);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<form onSubmit={handleSubmit(handleFormSubmit)}>
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name="name"
|
|
||||||
render={({ field, fieldState: { error } }) => (
|
|
||||||
<FormControl label="Policy Name" isError={Boolean(error)} errorText={error?.message}>
|
|
||||||
<Input {...field} value={field.value || ""} />
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name="environment"
|
|
||||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
|
||||||
<FormControl
|
|
||||||
label="Environment"
|
|
||||||
isRequired
|
|
||||||
className="mt-4"
|
|
||||||
isError={Boolean(error)}
|
|
||||||
errorText={error?.message}
|
|
||||||
>
|
|
||||||
<Select
|
|
||||||
isDisabled={isEditMode}
|
|
||||||
value={value}
|
|
||||||
onValueChange={(val) => onChange(val)}
|
|
||||||
className="w-full border border-mineshaft-500"
|
|
||||||
>
|
|
||||||
{environments.map((sourceEnvironment) => (
|
|
||||||
<SelectItem
|
|
||||||
value={sourceEnvironment.slug}
|
|
||||||
key={`azure-key-vault-environment-${sourceEnvironment.slug}`}
|
|
||||||
>
|
|
||||||
{sourceEnvironment.name}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name="secretPath"
|
|
||||||
render={({ field, fieldState: { error } }) => (
|
|
||||||
<FormControl label="Secret Path" isError={Boolean(error)} errorText={error?.message}>
|
|
||||||
<SecretPathInput
|
|
||||||
{...field}
|
|
||||||
value={field.value || ""}
|
|
||||||
environment={selectedEnvironment}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name="approvers"
|
|
||||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
|
||||||
<FormControl
|
|
||||||
label="Approvers Required"
|
|
||||||
isError={Boolean(error)}
|
|
||||||
errorText={error?.message}
|
|
||||||
>
|
|
||||||
<DropdownMenu>
|
|
||||||
<DropdownMenuTrigger asChild>
|
|
||||||
<Input
|
|
||||||
isReadOnly
|
|
||||||
value={value?.length ? `${value.length} selected` : "None"}
|
|
||||||
className="text-left"
|
|
||||||
/>
|
|
||||||
</DropdownMenuTrigger>
|
|
||||||
<DropdownMenuContent
|
|
||||||
style={{ width: "var(--radix-dropdown-menu-trigger-width)" }}
|
|
||||||
align="start"
|
|
||||||
>
|
|
||||||
<DropdownMenuLabel>
|
|
||||||
Select members that are allowed to approve changes
|
|
||||||
</DropdownMenuLabel>
|
|
||||||
{members.map(({ user }) => {
|
|
||||||
const isChecked = value?.includes(user.id);
|
|
||||||
return (
|
|
||||||
<DropdownMenuItem
|
|
||||||
onClick={(evt) => {
|
|
||||||
evt.preventDefault();
|
|
||||||
onChange(
|
|
||||||
isChecked
|
|
||||||
? value?.filter((el) => el !== user.id)
|
|
||||||
: [...(value || []), user.id]
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
key={`create-policy-members-${user.id}`}
|
|
||||||
iconPos="right"
|
|
||||||
icon={isChecked && <FontAwesomeIcon icon={faCheckCircle} />}
|
|
||||||
>
|
|
||||||
{user.username}
|
|
||||||
</DropdownMenuItem>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name="approvals"
|
|
||||||
defaultValue={1}
|
|
||||||
render={({ field, fieldState: { error } }) => (
|
|
||||||
<FormControl
|
|
||||||
label="Approvals Required"
|
|
||||||
isError={Boolean(error)}
|
|
||||||
errorText={error?.message}
|
|
||||||
>
|
|
||||||
<Input
|
|
||||||
{...field}
|
|
||||||
type="number"
|
|
||||||
onChange={(el) => field.onChange(parseInt(el.target.value, 10))}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<div className="mt-8 flex items-center space-x-4">
|
|
||||||
<Button type="submit" isLoading={isSubmitting} isDisabled={isSubmitting}>
|
|
||||||
Save
|
|
||||||
</Button>
|
|
||||||
<Button onClick={() => onToggle(false)} variant="outline_bg">
|
|
||||||
Close
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export { SecretApprovalPolicyList } from "./SecretApprovalPolicyList";
|
|
||||||
Reference in New Issue
Block a user