Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Merge branch 'main' into feature/policies-ui-update

Victor Santos71503b0b3c41
diff --cc frontend/src/pages/project/RoleDetailsBySlugPage/components/GeneralPermissionPolicies.tsx
index ec2a852d5d,bc9095eb39..63da2b9a57
--- a/frontend/src/pages/project/RoleDetailsBySlugPage/components/GeneralPermissionPolicies.tsx
+++ b/frontend/src/pages/project/RoleDetailsBySlugPage/components/GeneralPermissionPolicies.tsx
@@@ -1,27 -1,19 +1,27 @@@
- import { cloneElement, useMemo, useState } from "react";
-import { cloneElement, ReactNode } from "react";
++import { cloneElement, useMemo } from "react";
import { Control, Controller, useFieldArray, useFormContext, useWatch } from "react-hook-form";
-import {
- faChevronDown,
- faChevronRight,
- faDiagramProject,
- faInfoCircle,
- faPlus,
- faTrash
-} from "@fortawesome/free-solid-svg-icons";
-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import { components, MultiValueProps, MultiValueRemoveProps, OptionProps } from "react-select";
- import { CheckIcon, GripVerticalIcon, NetworkIcon, PlusIcon, TrashIcon } from "lucide-react";
++import { CheckIcon, NetworkIcon, PlusIcon, TrashIcon } from "lucide-react";
import { twMerge } from "tailwind-merge";
-import { Button, Checkbox, IconButton, Select, SelectItem, Tag, Tooltip } from "@app/components/v2";
+import {
+ Badge,
+ Button,
+ FilterableSelect,
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+ UnstableAccordionContent,
+ UnstableAccordionItem,
+ UnstableAccordionTrigger,
+ UnstableIconButton
+} from "@app/components/v3";
import { ProjectPermissionSub } from "@app/context";
-import { useToggle } from "@app/hooks";
import {
isConditionalSubjects,
@@@ -193,169 -87,185 +193,118 @@@ export const GeneralPermissionPolicies
name: `permissions.${subject}`
});
- const [draggedItem, setDraggedItem] = useState<number | null>(null);
- const [dragOverItem, setDragOverItem] = useState<number | null>(null);
- const [isOpen, setIsOpen] = useToggle();
--
if (!watchFields || !Array.isArray(watchFields) || watchFields.length === 0) return null;
- const handleDragStart = (_: React.DragEvent, index: number) => {
- setDraggedItem(index);
- };
-
- const handleDragOver = (e: React.DragEvent, index: number) => {
- e.preventDefault();
- setDragOverItem(index);
- };
-
- const handleDrop = (e: React.DragEvent) => {
- e.preventDefault();
-
- if (draggedItem === null || dragOverItem === null || draggedItem === dragOverItem) {
- setDraggedItem(null);
- setDragOverItem(null);
- return;
- }
-
- move(draggedItem, dragOverItem);
-
- setDraggedItem(null);
- setDragOverItem(null);
- };
-
- const handleDragEnd = () => {
- setDraggedItem(null);
- setDragOverItem(null);
- };
-
return (
- <div className="overflow-clip border border-mineshaft-600 bg-mineshaft-800 first:rounded-t-md last:rounded-b-md hover:bg-mineshaft-700">
- <div
- className="flex h-14 cursor-pointer items-center px-5 py-4 text-sm text-gray-300"
- role="button"
- tabIndex={0}
- onClick={() => setIsOpen.toggle()}
- onKeyDown={(e) => {
- if (e.key === "Enter") {
- setIsOpen.toggle();
- }
- }}
- >
- <FontAwesomeIcon className="mr-6 w-4" icon={isOpen ? faChevronDown : faChevronRight} />
-
- <div className="grow text-base select-none">{title}</div>
- {fields.length > 1 && (
- <div>
- <Tag size="xs" className="mr-2 px-2">
- {fields.length} Rules
- </Tag>
+ <UnstableAccordionItem value={subject}>
+ <UnstableAccordionTrigger className="min-h-14 px-5 py-4 hover:bg-container-hover">
+ <div className="flex flex-1 items-center gap-2 text-left">
+ <div className="flex grow flex-col">
+ <span className="text-base select-none">{title}</span>
+ <span className="text-sm text-muted">{description}</span>
</div>
- )}
- {isOpen && onShowAccessTree && (
- <Button
- leftIcon={<FontAwesomeIcon icon={faDiagramProject} />}
- variant="outline_bg"
- size="xs"
- className="ml-2"
- onClick={(e) => {
- e.stopPropagation();
- onShowAccessTree(subject);
- }}
- >
- Visualize Access
- </Button>
- )}
- {!isDisabled && isOpen && isConditionalSubjects(subject) && (
- <Button
- leftIcon={<FontAwesomeIcon icon={faPlus} />}
- variant="outline_bg"
- className="ml-2"
- size="xs"
- onClick={(e) => {
- e.stopPropagation();
- insert(fields.length, [
- { read: false, edit: false, create: false, delete: false } as any
- ]);
- }}
- isDisabled={isDisabled}
- >
- Add Rule
- </Button>
- )}
- </div>
- {isOpen && (
- <div key={`select-${subject}-type`} className="flex flex-col space-y-3 bg-bunker-700 p-3">
+ {fields.length > 1 && (
+ <Badge variant="neutral" className="mr-2">
+ {fields.length} Rules
+ </Badge>
+ )}
+ {isOpen && (
+ <div className="flex items-center gap-2">
+ {onShowAccessTree && (
+ <Button
+ type="button"
+ variant="outline"
+ size="xs"
+ onClick={(e) => {
+ e.stopPropagation();
+ onShowAccessTree(subject);
+ }}
+ >
+ <NetworkIcon className="size-4" />
+ Visualize Access
+ </Button>
+ )}
+ {!isDisabled && isConditionalSubjects(subject) && (
+ <Button
+ type="button"
+ variant="outline"
+ size="xs"
+ onClick={(e) => {
+ e.stopPropagation();
+ insert(fields.length, [
+ { read: false, edit: false, create: false, delete: false } as any
+ ]);
+ }}
+ isDisabled={isDisabled}
+ >
+ <PlusIcon className="size-4" />
+ Add Rule
+ </Button>
+ )}
+ </div>
+ )}
+ </div>
+ </UnstableAccordionTrigger>
+ <UnstableAccordionContent className="!p-0">
+ <div key={`select-${subject}-type`} className="flex flex-col space-y-3 bg-container p-3">
{fields.map((el, rootIndex) => {
- let isFullReadAccessEnabled = false;
-
- if (subject === ProjectPermissionSub.Secrets) {
- isFullReadAccessEnabled = watch(`permissions.${subject}.${rootIndex}.read` as any);
- }
-
const isInverted = watch(`permissions.${subject}.${rootIndex}.inverted` as any);
return (
<div
key={el.id}
className={twMerge(
- "relative rounded-md border-l-[6px] bg-mineshaft-800 px-5 py-4 transition-colors duration-300",
+ "relative rounded-md border border-l-[6px] border-border bg-card px-5 py-4 transition-colors duration-300",
- isInverted ? "border-l-red-600/50" : "border-l-green-600/50",
- dragOverItem === rootIndex ? "border-2 border-primary/50" : "",
- draggedItem === rootIndex ? "opacity-50" : ""
+ isInverted ? "border-l-red-600/50" : "border-l-green-600/50"
)}
- onDragOver={(e) => handleDragOver(e, rootIndex)}
- onDrop={handleDrop}
>
- {isConditionalSubjects(subject) && (
- <div className="mb-4 flex items-center gap-3">
- <div className="flex w-full items-center text-gray-300">
- <div className="mr-3">Permission</div>
- <Controller
- defaultValue={false as any}
- name={`permissions.${subject}.${rootIndex}.inverted`}
- render={({ field }) => (
- <Select
- value={String(field.value)}
- onValueChange={(val) => field.onChange(val === "true")}
- containerClassName="w-40"
- className="w-full"
- isDisabled={isDisabled}
- position="popper"
- >
+ <div className="flex items-center gap-3">
+ {isConditionalSubjects(subject) && (
+ <Controller
+ defaultValue={false as any}
+ name={`permissions.${subject}.${rootIndex}.inverted`}
+ render={({ field }) => (
+ <Select
+ value={String(field.value)}
+ onValueChange={(val) => field.onChange(val === "true")}
+ disabled={isDisabled}
+ >
+ <SelectTrigger className="w-32">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent position="popper">
<SelectItem value="false">Allow</SelectItem>
<SelectItem value="true">Forbid</SelectItem>
- </Select>
- )}
- />
- <Tooltip
- asChild
- content={
- <>
- <p>
- Whether to allow or forbid the selected actions when the following
- conditions (if any) are met.
- </p>
- <p className="mt-2">Forbid rules must come after allow rules.</p>
- </>
- }
- >
- <FontAwesomeIcon
- icon={faInfoCircle}
- size="sm"
- className="ml-2 text-bunker-400"
- />
- </Tooltip>
- {!isDisabled && (
- <Tooltip content="Remove Rule">
- <IconButton
- ariaLabel="Remove rule"
- colorSchema="danger"
- variant="plain"
- size="xs"
- className="mr-3 ml-auto rounded-sm"
- onClick={() => remove(rootIndex)}
- isDisabled={isDisabled}
- >
- <FontAwesomeIcon icon={faTrash} />
- </IconButton>
- </Tooltip>
+ </SelectContent>
+ </Select>
)}
- </div>
+ />
+ )}
+ <div className="flex-1">
+ <ActionsMultiSelect
+ subject={subject}
+ rootIndex={rootIndex}
+ actions={actions}
+ isDisabled={isDisabled}
+ control={control}
+ />
</div>
- )}
- <div className="flex flex-col text-gray-300">
- <div className="flex w-full justify-between">
- <div className="mb-2">Actions</div>
- {!isDisabled && !isConditionalSubjects(subject) && (
- <Tooltip content="Remove Rule">
- <IconButton
- ariaLabel="Remove rule"
- colorSchema="danger"
- variant="plain"
+ {!isDisabled && (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <UnstableIconButton
+ aria-label="Remove rule"
+ variant="danger"
size="xs"
- className="ml-auto rounded-sm"
onClick={() => remove(rootIndex)}
isDisabled={isDisabled}
>
- <FontAwesomeIcon icon={faTrash} />
- </IconButton>
- </Tooltip>
- )}
- </div>
- <div className="flex grow flex-wrap justify-start gap-x-8 gap-y-4">
- {actions.map(({ label, value }, index) => {
- if (typeof value !== "string") return undefined;
-
- if (
- subject === ProjectPermissionSub.Secrets &&
- value === "read" &&
- !isFullReadAccessEnabled
- ) {
- return null;
- }
-
- return (
- <ActionCheckbox
- key={`${el.id}-${index + 1}`}
- value={value}
- label={label}
- rootIndex={rootIndex}
- control={control}
- subject={subject}
- isDisabled={isDisabled}
- />
- );
- })}
- </div>
+ <TrashIcon className="size-4" />
+ </UnstableIconButton>
+ </TooltipTrigger>
+ <TooltipContent side="top">Remove Rule</TooltipContent>
+ </Tooltip>
+ )}
- {!isDisabled && isConditionalSubjects(subject) && (
- <Tooltip>
- <TooltipTrigger asChild>
- <div
- draggable
- onDragStart={(e) => handleDragStart(e, rootIndex)}
- onDragEnd={handleDragEnd}
- className="cursor-move text-muted hover:text-foreground"
- >
- <GripVerticalIcon className="size-4" />
- </div>
- </TooltipTrigger>
- <TooltipContent side="top">Drag to reorder permission</TooltipContent>
- </Tooltip>
- )}
</div>
{children &&
cloneElement(children, {