Skip to content

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

improvement: re-vamp additional privileges and adding policies, add add priv from access insights, and fix add priv resolution

Scott Wilson357e9e4a5b1b
diff --git a/backend/src/ee/services/permission/permission-dal.ts b/backend/src/ee/services/permission/permission-dal.ts
index e4a0f47366..4fea4530d7 100644
--- a/backend/src/ee/services/permission/permission-dal.ts
+++ b/backend/src/ee/services/permission/permission-dal.ts
@@ -486,8 +486,8 @@ export const permissionDALFactory = (db: TDbClient): TPermissionDALFactory => {
.leftJoin(TableName.Role, `${TableName.MembershipRole}.customRoleId`, `${TableName.Role}.id`)
.leftJoin(TableName.AdditionalPrivilege, (qb) => {
qb.on(`${TableName.Membership}.actorUserId`, `${TableName.AdditionalPrivilege}.actorUserId`).andOn(
- `${TableName.Membership}.scopeOrgId`,
- `${TableName.AdditionalPrivilege}.orgId`
+ `${TableName.Membership}.scopeProjectId`,
+ `${TableName.AdditionalPrivilege}.projectId`
);
})
.leftJoin(TableName.IdentityMetadata, (queryBuilder) => {
@@ -677,8 +677,8 @@ export const permissionDALFactory = (db: TDbClient): TPermissionDALFactory => {
.leftJoin(TableName.Role, `${TableName.MembershipRole}.customRoleId`, `${TableName.Role}.id`)
.leftJoin(TableName.AdditionalPrivilege, (qb) => {
qb.on(`${TableName.Membership}.actorIdentityId`, `${TableName.AdditionalPrivilege}.actorIdentityId`).andOn(
- `${TableName.Membership}.scopeOrgId`,
- `${TableName.AdditionalPrivilege}.orgId`
+ `${TableName.Membership}.scopeProjectId`,
+ `${TableName.AdditionalPrivilege}.projectId`
);
})
.join(TableName.Identity, `${TableName.Identity}.id`, `${TableName.Membership}.actorIdentityId`)
diff --git a/frontend/src/components/features/TtlFormLabel.tsx b/frontend/src/components/features/TtlFormLabel.tsx
index 83f058c7ae..ff7b4f6c17 100644
--- a/frontend/src/components/features/TtlFormLabel.tsx
+++ b/frontend/src/components/features/TtlFormLabel.tsx
@@ -1,38 +1,29 @@
-import { faArrowUpRightFromSquare, faQuestionCircle } from "@fortawesome/free-solid-svg-icons";
-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import { CircleHelpIcon, ExternalLinkIcon } from "lucide-react";
-import { FormLabel, Tooltip } from "../v2";
+import { Tooltip, TooltipContent, TooltipTrigger } from "../v3";
// To give users example of possible values of TTL
export const TtlFormLabel = ({ label }: { label: string }) => (
- <div>
- <FormLabel
- label={label}
- icon={
- <Tooltip
- className="max-w-lg"
- content={
- <span>
- Examples: 30m, 1h, 3d, etc.{" "}
- <a
- href="https://github.com/vercel/ms?tab=readme-ov-file#examples"
- target="_blank"
- rel="noopener noreferrer"
- className="text-primary-500 hover:text-mineshaft-100"
- >
- See More Examples{" "}
- <FontAwesomeIcon size="xs" className="mt-0.5" icon={faArrowUpRightFromSquare} />
- </a>
- </span>
- }
- >
- <FontAwesomeIcon
- icon={faQuestionCircle}
- size="sm"
- className="relative right-1 mt-0.5 text-mineshaft-300"
- />
- </Tooltip>
- }
- />
- </div>
+ <span className="inline-flex items-center gap-1">
+ {label}
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <CircleHelpIcon className="size-3.5 text-muted" />
+ </TooltipTrigger>
+ <TooltipContent className="max-w-lg">
+ <span>
+ Examples: 30m, 1h, 3d, etc.{" "}
+ <a
+ href="https://github.com/vercel/ms?tab=readme-ov-file#examples"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="font-medium"
+ >
+ <span className="underline underline-offset-2">See More Examples</span>{" "}
+ <ExternalLinkIcon className="mb-0.5 inline size-3" />
+ </a>
+ </span>
+ </TooltipContent>
+ </Tooltip>
+ </span>
);
diff --git a/frontend/src/components/v2/Modal/Modal.tsx b/frontend/src/components/v2/Modal/Modal.tsx
index 6f6a4b416c..cb26bf23c2 100644
--- a/frontend/src/components/v2/Modal/Modal.tsx
+++ b/frontend/src/components/v2/Modal/Modal.tsx
@@ -37,7 +37,7 @@ export const ModalContent = forwardRef<HTMLDivElement, ModalContentProps>(
) => (
<DialogPrimitive.Portal>
<DialogPrimitive.Overlay
- className={twMerge("animate-fade-in fixed inset-0 z-30 h-full w-full", overlayClassName)}
+ className={twMerge("animate-fade-in fixed inset-0 z-[60] h-full w-full", overlayClassName)}
style={{ backgroundColor: "rgba(0, 0, 0, 0.7)" }}
/>
<DialogPrimitive.Content
@@ -60,7 +60,7 @@ export const ModalContent = forwardRef<HTMLDivElement, ModalContentProps>(
<Card
isRounded
className={twMerge(
- "animate-pop-in fixed top-1/2 left-1/2 z-30 thin-scrollbar max-w-xl -translate-x-2/4 -translate-y-2/4 border border-mineshaft-600 drop-shadow-2xl dark:scheme-dark",
+ "animate-pop-in fixed top-1/2 left-1/2 z-[60] thin-scrollbar max-w-xl -translate-x-2/4 -translate-y-2/4 border border-mineshaft-600 drop-shadow-2xl dark:scheme-dark",
className
)}
style={{ maxHeight: "90%" }}
diff --git a/frontend/src/components/v3/generic/Popover/Popover.tsx b/frontend/src/components/v3/generic/Popover/Popover.tsx
index 4b209e810f..91ed8d812d 100644
--- a/frontend/src/components/v3/generic/Popover/Popover.tsx
+++ b/frontend/src/components/v3/generic/Popover/Popover.tsx
@@ -17,10 +17,13 @@ function PopoverContent({
className,
align = "center",
sideOffset = 4,
+ container,
...props
-}: React.ComponentProps<typeof PopoverPrimitive.Content>) {
+}: React.ComponentProps<typeof PopoverPrimitive.Content> & {
+ container?: React.ComponentProps<typeof PopoverPrimitive.Portal>["container"];
+}) {
return (
- <PopoverPrimitive.Portal>
+ <PopoverPrimitive.Portal container={container}>
<PopoverPrimitive.Content
data-slot="popover-content"
align={align}
diff --git a/frontend/src/hooks/api/identityProjectAdditionalPrivilege/mutation.tsx b/frontend/src/hooks/api/identityProjectAdditionalPrivilege/mutation.tsx
index 96b0c420a0..f876dd9fa0 100644
--- a/frontend/src/hooks/api/identityProjectAdditionalPrivilege/mutation.tsx
+++ b/frontend/src/hooks/api/identityProjectAdditionalPrivilege/mutation.tsx
@@ -22,6 +22,7 @@ export const useCreateIdentityProjectAdditionalPrivilege = () => {
queryClient.invalidateQueries({
queryKey: identitiyProjectPrivilegeKeys.list({ projectId, identityId })
});
+ queryClient.invalidateQueries({ queryKey: ["secret-access-list"] });
}
});
};
@@ -48,6 +49,7 @@ export const useUpdateIdentityProjectAdditionalPrivilege = () => {
queryClient.invalidateQueries({
queryKey: identitiyProjectPrivilegeKeys.list({ projectId, identityId })
});
+ queryClient.invalidateQueries({ queryKey: ["secret-access-list"] });
}
});
};
@@ -73,6 +75,7 @@ export const useDeleteIdentityProjectAdditionalPrivilege = () => {
queryClient.invalidateQueries({
queryKey: identitiyProjectPrivilegeKeys.list({ projectId, identityId })
});
+ queryClient.invalidateQueries({ queryKey: ["secret-access-list"] });
}
});
};
diff --git a/frontend/src/hooks/api/projectUserAdditionalPrivilege/mutation.tsx b/frontend/src/hooks/api/projectUserAdditionalPrivilege/mutation.tsx
index 79d7d7f23d..ea0dc7dd41 100644
--- a/frontend/src/hooks/api/projectUserAdditionalPrivilege/mutation.tsx
+++ b/frontend/src/hooks/api/projectUserAdditionalPrivilege/mutation.tsx
@@ -22,6 +22,7 @@ export const useCreateProjectUserAdditionalPrivilege = () => {
queryClient.invalidateQueries({
queryKey: projectUserPrivilegeKeys.list(projectMembershipId)
});
+ queryClient.invalidateQueries({ queryKey: ["secret-access-list"] });
}
});
};
@@ -41,6 +42,7 @@ export const useUpdateProjectUserAdditionalPrivilege = () => {
queryClient.invalidateQueries({
queryKey: projectUserPrivilegeKeys.list(projectMembershipId)
});
+ queryClient.invalidateQueries({ queryKey: ["secret-access-list"] });
}
});
};
@@ -59,6 +61,7 @@ export const useDeleteProjectUserAdditionalPrivilege = () => {
queryClient.invalidateQueries({
queryKey: projectUserPrivilegeKeys.list(projectMembershipId)
});
+ queryClient.invalidateQueries({ queryKey: ["secret-access-list"] });
}
});
};
diff --git a/frontend/src/index.css b/frontend/src/index.css
index f887ad1e1f..158a04a44d 100644
--- a/frontend/src/index.css
+++ b/frontend/src/index.css
@@ -34,7 +34,7 @@
caret-color: var(--color-foreground);
transition: background-color 5000s ease-in-out 0s;
}
-
+
/* NordPass autofill override */
input[data-np-input-autofilled],
input[data-np-input-autofilled]:hover,
@@ -300,7 +300,7 @@
background-color: gray;
}
scrollbar-width: thin;
- scrollbar-color: gray transparent;
+ scrollbar-color: #39393d transparent;
}
@layer utilities {
diff --git a/frontend/src/pages/project/IdentityDetailsByIDPage/components/IdentityProjectAdditionalPrivilegeSection/IdentityProjectAdditionalPrivilegeModifySection.tsx b/frontend/src/pages/project/IdentityDetailsByIDPage/components/IdentityProjectAdditionalPrivilegeSection/IdentityProjectAdditionalPrivilegeModifySection.tsx
index 4de2d0312f..2b9021985f 100644
--- a/frontend/src/pages/project/IdentityDetailsByIDPage/components/IdentityProjectAdditionalPrivilegeSection/IdentityProjectAdditionalPrivilegeModifySection.tsx
+++ b/frontend/src/pages/project/IdentityDetailsByIDPage/components/IdentityProjectAdditionalPrivilegeSection/IdentityProjectAdditionalPrivilegeModifySection.tsx
@@ -5,21 +5,27 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { format, formatDistance } from "date-fns";
import { ChevronDownIcon, ClockIcon, SaveIcon } from "lucide-react";
import ms from "ms";
-import { twMerge } from "tailwind-merge";
import { z } from "zod";
import { TtlFormLabel } from "@app/components/features";
import { createNotification } from "@app/components/notifications";
import {
- FormControl,
- FormLabel,
- Input,
+ Badge,
+ Button,
+ Field,
+ FieldError,
+ FieldLabel,
Popover,
PopoverContent,
PopoverTrigger,
- Tooltip
-} from "@app/components/v2";
-import { Badge, Button, UnstableAccordion, UnstableSeparator } from "@app/components/v3";
+ SheetFooter,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+ UnstableAccordion,
+ UnstableInput,
+ UnstableSeparator
+} from "@app/components/v3";
import {
ProjectPermissionIdentityActions,
ProjectPermissionSub,
@@ -53,6 +59,7 @@ type Props = {
onGoBack: () => void;
isDisabled?: boolean;
menuPortalContainerRef?: React.RefObject<HTMLElement | null>;
+ initialPermissions?: z.infer<typeof formSchema>["permissions"];
};
export const formSchema = z.object({
@@ -80,10 +87,17 @@ export const IdentityProjectAdditionalPrivilegeModifySection = ({
onGoBack,
identityId,
isDisabled,
- menuPortalContainerRef
+ menuPortalContainerRef,
+ initialPermissions
}: Props) => {
const isCreate = !privilegeId;
- const [openPolicies, setOpenPolicies] = useState<string[]>([]);
+ const [openPolicies, setOpenPolicies] = useState<string[]>(() =>
+ initialPermissions
+ ? Object.keys(initialPermissions).filter(
+ (k) => (initialPermissions as Record<string, unknown[]>)[k]?.length > 0
+ )
+ : []
+ );
const { currentProject } = useProject();
const projectId = currentProject?.id || "";
const { data: privilegeDetails, isPending } = useGetIdentityProjectPrivilegeDetails({
@@ -127,7 +141,7 @@ export const IdentityProjectAdditionalPrivilegeModifySection = ({
defaultValues: {
slug: "",
temporaryAccess: { isTemporary: false },
- permissions: {}
+ permissions: initialPermissions ?? {}
}
});
@@ -219,14 +233,17 @@ export const IdentityProjectAdditionalPrivilegeModifySection = ({
const isExpired =
privilegeTemporaryAccess?.isTemporary &&
new Date() > new Date(privilegeTemporaryAccess.temporaryAccessEndTime || "");
+ let durationVariant: "outline" | "warning" | "danger" = "outline";
let text = "Permanent";
let toolTipText = "Non-Expiring Access";
if (isTemporary) {
if (isExpired) {
+ durationVariant = "danger";
text = "Access Expired";
toolTipText = "Timed Access Expired";
} else {
+ durationVariant = "warning";
text = formatDistance(
new Date(privilegeTemporaryAccess.temporaryAccessEndTime || ""),
new Date()
@@ -239,207 +256,210 @@ export const IdentityProjectAdditionalPrivilegeModifySection = ({
}
return (
- <form className="flex flex-col gap-y-4" onSubmit={handleFormSubmit}>
+ <form className="flex min-h-0 flex-1 flex-col" onSubmit={handleFormSubmit}>
<FormProvider {...form}>
- <div>
- <div className="flex items-end space-x-6">
- <div className="w-full max-w-md">
- <Controller
- control={form.control}
- name="slug"
- render={({ field }) => (
- <FormControl label="Privilege Name" isOptional className="mb-0">
- <Input {...field} />
- </FormControl>
- )}
- />
+ <div className="thin-scrollbar flex-1 overflow-y-auto p-4">
+ <div className="flex flex-col gap-y-4">
+ <div>
+ <div className="flex items-end space-x-6">
+ <div className="w-full max-w-md">
+ <Controller
+ control={form.control}
+ name="slug"
+ render={({ field }) => (
+ <Field>
+ <FieldLabel>
+ Privilege Name <span className="text-muted">(optional)</span>
+ </FieldLabel>
+ <UnstableInput {...field} />
+ </Field>
+ )}
+ />
+ </div>
+ <div>
+ <Popover>
+ <PopoverTrigger disabled={isIdentityEditDisabled} asChild>
+ <div className="w-full max-w-md grow">
+ <FieldLabel>Duration</FieldLabel>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button
+ type="button"
+ variant={durationVariant}
+ disabled={isIdentityEditDisabled}
+ className="w-full py-2.5 capitalize"
+ >
+ {isTemporary && <ClockIcon className="size-4" />}
+ {text}
+ <ChevronDownIcon className="ml-2 size-4" />
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>{toolTipText}</TooltipContent>
+ </Tooltip>
+ </div>
+ </PopoverTrigger>
+ <PopoverContent side="right" onWheel={(e) => e.stopPropagation()}>
+ <div className="flex flex-col space-y-4">
+ <div className="border-b border-b-border pb-2 text-sm text-muted">
+ Configure Timed Access
+ </div>
+ {isExpired && <Badge variant="danger">Expired</Badge>}
+ <Controller
+ control={form.control}
+ defaultValue="1h"
+ name="temporaryAccess.temporaryRange"
+ render={({ field, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel>
+ <TtlFormLabel label="Validity" />
+ </FieldLabel>
+ <UnstableInput {...field} isError={Boolean(error?.message)} />
+ {error?.message && <FieldError>{error.message}</FieldError>}
+ </Field>
+ )}
+ />
+ <div className="flex items-center space-x-2">
+ <Button
+ size="xs"
+ variant="outline"
+ onClick={() => {
+ const temporaryRange = form.getValues(
+ "temporaryAccess.temporaryRange"
+ );
+ if (!temporaryRange) {
+ form.setError(
+ "temporaryAccess.temporaryRange",
+ { type: "required", message: "Required" },
+ { shouldFocus: true }
+ );
+ return;
+ }
+ form.clearErrors("temporaryAccess.temporaryRange");
+ form.setValue(
+ "temporaryAccess",
+ {
+ isTemporary: true,
+ temporaryAccessStartTime: new Date().toISOString(),
+ temporaryRange,
+ temporaryAccessEndTime: new Date(
+ new Date().getTime() + ms(temporaryRange)
+ ).toISOString()
+ },
+ { shouldDirty: true }
+ );
+ }}
+ >
+ {isTemporary ? "Restart" : "Configure"}
+ </Button>
+ {isTemporary && (
+ <Button
+ size="xs"
+ variant="danger"
+ onClick={() => {
+ form.setValue(
+ "temporaryAccess",
+ {
+ isTemporary: false
+ },
+ { shouldDirty: true }
+ );
+ }}
+ >
+ Remove Duration
+ </Button>
+ )}
+ </div>
+ </div>
+ </PopoverContent>
+ </Popover>
+ </div>
+ </div>
</div>
+ <UnstableSeparator />
<div>
- <Popover>
- <PopoverTrigger disabled={isIdentityEditDisabled} asChild>
- <div className="w-full max-w-md grow">
- <FormLabel label="Duration" />
- <Tooltip content={toolTipText}>
- <Button
- type="button"
- variant="outline"
- disabled={isIdentityEditDisabled}
- className={twMerge(
- "w-full border-none bg-mineshaft-600 py-2.5 text-xs capitalize hover:bg-mineshaft-500",
- isTemporary && "text-primary",
- isExpired && "text-red-600"
- )}
- >
- {isTemporary && <ClockIcon className="size-4" />}
- {text}
- <ChevronDownIcon className="ml-2 size-4" />
- </Button>
- </Tooltip>
- </div>
- </PopoverTrigger>
- <PopoverContent
- arrowClassName="fill-gray-600"
- side="right"
- sideOffset={12}
- hideCloseBtn
- className="border border-gray-600 pt-4"
- >
- <div className="flex flex-col space-y-4">
- <div className="border-b border-b-gray-700 pb-2 text-sm text-mineshaft-300">
- Configure Timed Access
- </div>
- {isExpired && <Badge variant="danger">Expired</Badge>}
- <Controller
- control={form.control}
- defaultValue="1h"
- name="temporaryAccess.temporaryRange"
- render={({ field, fieldState: { error } }) => (
- <FormControl
- label={<TtlFormLabel label="Validity" />}
- isError={Boolean(error?.message)}
- errorText={error?.message}
- >
- <Input {...field} />
- </FormControl>
- )}
+ <div className="mb-3 flex w-full items-center justify-between">
+ <div className="text-lg">Policies</div>
+ <div className="flex items-center gap-2">
+ {isDirty && (
+ <Button
+ type="button"
+ className="mr-4 text-muted"
+ variant="ghost"
+ disabled={isSubmitting}
+ onClick={() => {
+ if (privilegeDetails) {
+ reset({
+ ...privilegeDetails,
+ permissions: rolePermission2Form(privilegeDetails.permissions),
+ temporaryAccess: privilegeDetails.isTemporary
+ ? {
+ isTemporary: true,
+ temporaryRange: privilegeDetails.temporaryRange || "",
+ temporaryAccessEndTime:
+ privilegeDetails.temporaryAccessEndTime || "",
+ temporaryAccessStartTime:
+ privilegeDetails.temporaryAccessStartTime || ""
+ }
+ : { isTemporary: false }
+ });
+ } else {
+ reset({
+ slug: "",
+ temporaryAccess: { isTemporary: false },
+ permissions: {}
+ });
+ }
+ }}
+ >
+ Discard
+ </Button>
+ )}
+ {currentProject && (
+ <AddPoliciesButton
+ isDisabled={isDisabled}
+ projectType={currentProject.type}
+ projectId={projectId}
+ allowedSubjects={filteredPermissionSubjects}
+ portalContainer={menuPortalContainerRef}
/>
- <div className="flex items-center space-x-2">
- <Button
- size="xs"
- variant="outline"
- onClick={() => {
- const temporaryRange = form.getValues("temporaryAccess.temporaryRange");
- if (!temporaryRange) {
- form.setError(
- "temporaryAccess.temporaryRange",
- { type: "required", message: "Required" },
- { shouldFocus: true }
- );
- return;
- }
- form.clearErrors("temporaryAccess.temporaryRange");
- form.setValue(
- "temporaryAccess",
- {
- isTemporary: true,
- temporaryAccessStartTime: new Date().toISOString(),
- temporaryRange,
- temporaryAccessEndTime: new Date(
- new Date().getTime() + ms(temporaryRange)
- ).toISOString()
- },
- { shouldDirty: true }
- );
- }}
- >
- {isTemporary ? "Restart" : "Grant"}
- </Button>
- {isTemporary && (
- <Button
- size="xs"
- variant="danger"
- onClick={() => {
- form.setValue(
- "temporaryAccess",
- {
- isTemporary: false
- },
- { shouldDirty: true }
- );
- }}
+ )}
+ </div>
+ </div>
+ {(isCreate || !isPending) && !hasPermissions && <PermissionEmptyState />}
+ {hasPermissions && (
+ <div className="thin-scrollbar overflow-y-auto">
+ <UnstableAccordion
+ type="multiple"
+ value={openPolicies}
+ onValueChange={setOpenPolicies}
+ className="overflow-clip rounded-md border border-border bg-container"
+ >
+ {filteredPermissionSubjects.map((permissionSubject) => {
+ const filteredActions = getFilteredActionsForSubject(permissionSubject);
+ if (filteredActions.length === 0) return null;
+
+ return (
+ <GeneralPermissionPolicies
+ subject={permissionSubject}
+ actions={filteredActions}
+ title={PROJECT_PERMISSION_OBJECT[permissionSubject].title}
+ description={PROJECT_PERMISSION_OBJECT[permissionSubject].description}
+ key={`project-permission-${permissionSubject}`}
+ isDisabled={isDisabled}
+ isOpen={openPolicies.includes(permissionSubject)}
+ menuPortalContainerRef={menuPortalContainerRef}
>
- Revoke Access
- </Button>
- )}
- </div>
- </div>
- </PopoverContent>
- </Popover>
- </div>
- </div>
- </div>
- <UnstableSeparator />
- <div>
- <div className="mb-3 flex w-full items-center justify-between">
- <div className="text-lg">Policies</div>
- <div className="flex items-center gap-2">
- {isDirty && (
- <Button
- type="button"
- className="mr-4 text-muted"
- variant="ghost"
- disabled={isSubmitting}
- onClick={() => {
- if (privilegeDetails) {
- reset({
- ...privilegeDetails,
- permissions: rolePermission2Form(privilegeDetails.permissions),
- temporaryAccess: privilegeDetails.isTemporary
- ? {
- isTemporary: true,
- temporaryRange: privilegeDetails.temporaryRange || "",
- temporaryAccessEndTime: privilegeDetails.temporaryAccessEndTime || "",
- temporaryAccessStartTime:
- privilegeDetails.temporaryAccessStartTime || ""
- }
- : { isTemporary: false }
- });
- } else {
- reset({
- slug: "",
- temporaryAccess: { isTemporary: false },
- permissions: {}
- });
- }
- }}
- >
- Discard
- </Button>
- )}
- {currentProject && (
- <AddPoliciesButton
- isDisabled={isDisabled}
- projectType={currentProject.type}
- projectId={projectId}
- allowedSubjects={filteredPermissionSubjects}
- />
+ {renderConditionalComponents(permissionSubject, isDisabled)}
+ </GeneralPermissionPolicies>
+ );
+ })}
+ </UnstableAccordion>
+ </div>
)}
</div>
</div>
- {(isCreate || !isPending) && !hasPermissions && <PermissionEmptyState />}
- {hasPermissions && (
- <div className="scrollbar-thin max-h-[50vh] overflow-y-auto">
- <UnstableAccordion
- type="multiple"
- value={openPolicies}
- onValueChange={setOpenPolicies}
- className="overflow-clip rounded-md border border-border bg-container"
- >
- {filteredPermissionSubjects.map((permissionSubject) => {
- const filteredActions = getFilteredActionsForSubject(permissionSubject);
- if (filteredActions.length === 0) return null;
-
- return (
- <GeneralPermissionPolicies
- subject={permissionSubject}
- actions={filteredActions}
- title={PROJECT_PERMISSION_OBJECT[permissionSubject].title}
- description={PROJECT_PERMISSION_OBJECT[permissionSubject].description}
- key={`project-permission-${permissionSubject}`}
- isDisabled={isDisabled}
- isOpen={openPolicies.includes(permissionSubject)}
- menuPortalContainerRef={menuPortalContainerRef}
- >
- {renderConditionalComponents(permissionSubject, isDisabled)}
- </GeneralPermissionPolicies>
- );
- })}
- </UnstableAccordion>
- </div>
- )}
</div>
- <UnstableSeparator />
- <div className="flex w-full items-center justify-end gap-x-2">
+ <SheetFooter className="justify-end border-t">
<Button variant="ghost" onClick={onGoBack}>
Cancel
</Button>
@@ -447,7 +467,7 @@ export const IdentityProjectAdditionalPrivilegeModifySection = ({
<SaveIcon />
Save
</Button>
- </div>
+ </SheetFooter>
</FormProvider>
</form>
);
diff --git a/frontend/src/pages/project/IdentityDetailsByIDPage/components/IdentityProjectAdditionalPrivilegeSection/IdentityProjectAdditionalPrivilegeSection.tsx b/frontend/src/pages/project/IdentityDetailsByIDPage/components/IdentityProjectAdditionalPrivilegeSection/IdentityProjectAdditionalPrivilegeSection.tsx
index 26e58ab645..41f670c88e 100644
--- a/frontend/src/pages/project/IdentityDetailsByIDPage/components/IdentityProjectAdditionalPrivilegeSection/IdentityProjectAdditionalPrivilegeSection.tsx
+++ b/frontend/src/pages/project/IdentityDetailsByIDPage/components/IdentityProjectAdditionalPrivilegeSection/IdentityProjectAdditionalPrivilegeSection.tsx
@@ -5,10 +5,15 @@ import { ClockAlertIcon, ClockIcon, EllipsisIcon, PlusIcon } from "lucide-react"
import { createNotification } from "@app/components/notifications";
import { ProjectPermissionCan } from "@app/components/permissions";
-import { DeleteActionModal, Lottie, Modal, ModalContent } from "@app/components/v2";
+import { DeleteActionModal, Lottie } from "@app/components/v2";
import {
Badge,
Button,
+ Sheet,
+ SheetContent,
+ SheetDescription,
+ SheetHeader,
+ SheetTitle,
Tooltip,
TooltipContent,
TooltipTrigger,
@@ -58,7 +63,7 @@ type Props = {
};
export const IdentityProjectAdditionalPrivilegeSection = ({ identityMembershipDetails }: Props) => {
- const modalContainerRef = useRef<HTMLDivElement>(null);
+ const sheetContainerRef = useRef<HTMLDivElement>(null);
const { popUp, handlePopUpOpen, handlePopUpToggle, handlePopUpClose } = usePopUp([
"deletePrivilege",
"modifyPrivilege"
@@ -327,16 +332,17 @@ export const IdentityProjectAdditionalPrivilegeSection = ({ identityMembershipDe
)}
</UnstableCardContent>
</UnstableCard>
- <Modal
- isOpen={popUp.modifyPrivilege.isOpen}
+ <Sheet
+ open={popUp.modifyPrivilege.isOpen}
onOpenChange={(isOpen) => handlePopUpToggle("modifyPrivilege", isOpen)}
>
- <ModalContent
- ref={modalContainerRef}
- className="max-w-6xl"
- title="Additional Privileges"
- subTitle="Additional privileges take precedence over roles when permissions conflict"
- >
+ <SheetContent ref={sheetContainerRef} className="flex h-full flex-col gap-y-0 sm:max-w-6xl">
+ <SheetHeader className="border-b">
+ <SheetTitle>Additional Privileges</SheetTitle>
+ <SheetDescription>
+ Additional privileges take precedence over roles when permissions conflict
+ </SheetDescription>
+ </SheetHeader>
<IdentityProjectAdditionalPrivilegeModifySection
onGoBack={() => handlePopUpClose("modifyPrivilege")}
identityId={identityId}
@@ -349,10 +355,10 @@ export const IdentityProjectAdditionalPrivilegeSection = ({ identityMembershipDe
})
) || !canModifyIdentityPrivileges
}
- menuPortalContainerRef={modalContainerRef}
+ menuPortalContainerRef={sheetContainerRef}
/>
- </ModalContent>
- </Modal>
+ </SheetContent>
+ </Sheet>
<DeleteActionModal
isOpen={popUp.deletePrivilege.isOpen}
deleteKey="remove"
diff --git a/frontend/src/pages/project/MemberDetailsByIDPage/components/MemberProjectAdditionalPrivilegeSection/MemberProjectAdditionalPrivilegeSection.tsx b/frontend/src/pages/project/MemberDetailsByIDPage/components/MemberProjectAdditionalPrivilegeSection/MemberProjectAdditionalPrivilegeSection.tsx
index e9890a3b36..4190a926fc 100644
--- a/frontend/src/pages/project/MemberDetailsByIDPage/components/MemberProjectAdditionalPrivilegeSection/MemberProjectAdditionalPrivilegeSection.tsx
+++ b/frontend/src/pages/project/MemberDetailsByIDPage/components/MemberProjectAdditionalPrivilegeSection/MemberProjectAdditionalPrivilegeSection.tsx
@@ -5,10 +5,15 @@ import picomatch from "picomatch";
import { createNotification } from "@app/components/notifications";
import { ProjectPermissionCan } from "@app/components/permissions";
-import { DeleteActionModal, Lottie, Modal, ModalContent } from "@app/components/v2";
+import { DeleteActionModal, Lottie } from "@app/components/v2";
import {
Badge,
Button,
+ Sheet,
+ SheetContent,
+ SheetDescription,
+ SheetHeader,
+ SheetTitle,
Tooltip,
TooltipContent,
TooltipTrigger,
@@ -60,7 +65,7 @@ type Props = {
};
export const MemberProjectAdditionalPrivilegeSection = ({ membershipDetails }: Props) => {
- const modalContainerRef = useRef<HTMLDivElement>(null);
+ const sheetContainerRef = useRef<HTMLDivElement>(null);
const { user } = useUser();
const userId = user?.id;
const { popUp, handlePopUpOpen, handlePopUpToggle, handlePopUpClose } = usePopUp([
@@ -335,16 +340,17 @@ export const MemberProjectAdditionalPrivilegeSection = ({ membershipDetails }: P
)}
</UnstableCardContent>
</UnstableCard>
- <Modal
- isOpen={popUp.modifyPrivilege.isOpen}
+ <Sheet
+ open={popUp.modifyPrivilege.isOpen}
onOpenChange={(isOpen) => handlePopUpToggle("modifyPrivilege", isOpen)}
>
- <ModalContent
- ref={modalContainerRef}
- className="max-w-6xl"
- title="Additional Privileges"
- subTitle="Additional privileges take precedence over roles when permissions conflict"
- >
+ <SheetContent ref={sheetContainerRef} className="flex h-full flex-col gap-y-0 sm:max-w-6xl">
+ <SheetHeader className="border-b">
+ <SheetTitle>Additional Privileges</SheetTitle>
+ <SheetDescription>
+ Additional privileges take precedence over roles when permissions conflict
+ </SheetDescription>
+ </SheetHeader>
<MembershipProjectAdditionalPrivilegeModifySection
onGoBack={() => handlePopUpClose("modifyPrivilege")}
projectMembershipId={membershipDetails?.id}
@@ -353,10 +359,10 @@ export const MemberProjectAdditionalPrivilegeSection = ({ membershipDetails }: P
isOwnProjectMembershipDetails ||
permission.cannot(ProjectPermissionMemberActions.Edit, ProjectPermissionSub.Member)
}
- menuPortalContainerRef={modalContainerRef}
+ menuPortalContainerRef={sheetContainerRef}
/>
- </ModalContent>
- </Modal>
+ </SheetContent>
+ </Sheet>
<DeleteActionModal
isOpen={popUp.deletePrivilege.isOpen}
deleteKey="remove"
diff --git a/frontend/src/pages/project/MemberDetailsByIDPage/components/MemberProjectAdditionalPrivilegeSection/MembershipProjectAdditionalPrivilegeModifySection.tsx b/frontend/src/pages/project/MemberDetailsByIDPage/components/MemberProjectAdditionalPrivilegeSection/MembershipProjectAdditionalPrivilegeModifySection.tsx
index 23d3ef4106..75961e1935 100644
--- a/frontend/src/pages/project/MemberDetailsByIDPage/components/MemberProjectAdditionalPrivilegeSection/MembershipProjectAdditionalPrivilegeModifySection.tsx
+++ b/frontend/src/pages/project/MemberDetailsByIDPage/components/MemberProjectAdditionalPrivilegeSection/MembershipProjectAdditionalPrivilegeModifySection.tsx
@@ -4,21 +4,27 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { format, formatDistance } from "date-fns";
import { ChevronDownIcon, ClockIcon, SaveIcon } from "lucide-react";
import ms from "ms";
-import { twMerge } from "tailwind-merge";
import { z } from "zod";
import { TtlFormLabel } from "@app/components/features";
import { createNotification } from "@app/components/notifications";
import {
- FormControl,
- FormLabel,
- Input,
+ Badge,
+ Button,
+ Field,
+ FieldError,
+ FieldLabel,
Popover,
PopoverContent,
PopoverTrigger,
- Tooltip
-} from "@app/components/v2";
-import { Badge, Button, UnstableAccordion, UnstableSeparator } from "@app/components/v3";
+ SheetFooter,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+ UnstableAccordion,
+ UnstableInput,
+ UnstableSeparator
+} from "@app/components/v3";
import {
ProjectPermissionMemberActions,
ProjectPermissionSub,
@@ -52,6 +58,7 @@ type Props = {
onGoBack: () => void;
isDisabled?: boolean;
menuPortalContainerRef?: React.RefObject<HTMLElement | null>;
+ initialPermissions?: z.infer<typeof formSchema>["permissions"];
};
export const formSchema = z.object({
@@ -79,10 +86,17 @@ export const MembershipProjectAdditionalPrivilegeModifySection = ({
onGoBack,
projectMembershipId,
isDisabled,
- menuPortalContainerRef
+ menuPortalContainerRef,
+ initialPermissions
}: Props) => {
const isCreate = !privilegeId;
- const [openPolicies, setOpenPolicies] = useState<string[]>([]);
+ const [openPolicies, setOpenPolicies] = useState<string[]>(() =>
+ initialPermissions
+ ? Object.keys(initialPermissions).filter(
+ (k) => (initialPermissions as Record<string, unknown[]>)[k]?.length > 0
+ )
+ : []
+ );
const { currentProject } = useProject();
const projectId = currentProject?.id || "";
const { data: privilegeDetails, isPending } = useGetProjectUserPrivilegeDetails(
@@ -125,7 +139,7 @@ export const MembershipProjectAdditionalPrivilegeModifySection = ({
defaultValues: {
slug: "",
temporaryAccess: { isTemporary: false },
- permissions: {}
+ permissions: initialPermissions ?? {}
}
});
@@ -215,14 +229,17 @@ export const MembershipProjectAdditionalPrivilegeModifySection = ({
const isExpired =
privilegeTemporaryAccess?.isTemporary &&
new Date() > new Date(privilegeTemporaryAccess.temporaryAccessEndTime || "");
+ let durationVariant: "outline" | "warning" | "danger" = "outline";
let text = "Permanent";
let toolTipText = "Non-Expiring Access";
if (isTemporary) {
if (isExpired) {
+ durationVariant = "danger";
text = "Access Expired";
toolTipText = "Timed Access Expired";
} else {
+ durationVariant = "warning";
text = formatDistance(
new Date(privilegeTemporaryAccess.temporaryAccessEndTime || ""),
new Date()
@@ -235,207 +252,210 @@ export const MembershipProjectAdditionalPrivilegeModifySection = ({
}
return (
- <form className="flex flex-col gap-y-4" onSubmit={handleFormSubmit}>
+ <form className="flex min-h-0 flex-1 flex-col" onSubmit={handleFormSubmit}>
<FormProvider {...form}>
- <div>
- <div className="flex items-end space-x-6">
- <div className="w-full max-w-md">
- <Controller
- control={form.control}
- name="slug"
- render={({ field }) => (
- <FormControl label="Privilege Name" isOptional className="mb-0">
- <Input {...field} />
- </FormControl>
- )}
- />
+ <div className="thin-scrollbar flex-1 overflow-y-auto p-4">
+ <div className="flex flex-col gap-y-4">
+ <div>
+ <div className="flex items-end space-x-6">
+ <div className="w-full max-w-md">
+ <Controller
+ control={form.control}
+ name="slug"
+ render={({ field }) => (
+ <Field>
+ <FieldLabel>
+ Privilege Name <span className="text-muted">(optional)</span>
+ </FieldLabel>
+ <UnstableInput {...field} />
+ </Field>
+ )}
+ />
+ </div>
+ <div>
+ <Popover>
+ <PopoverTrigger disabled={isMemberEditDisabled} asChild>
+ <div className="w-full max-w-md grow">
+ <FieldLabel>Duration</FieldLabel>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button
+ type="button"
+ variant={durationVariant}
+ disabled={isMemberEditDisabled}
+ className="w-full capitalize"
+ >
+ {isTemporary && <ClockIcon className="size-4" />}
+ {text}
+ <ChevronDownIcon className="ml-2 size-4" />
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>{toolTipText}</TooltipContent>
+ </Tooltip>
+ </div>
+ </PopoverTrigger>
+ <PopoverContent side="right" onWheel={(e) => e.stopPropagation()}>
+ <div className="flex flex-col space-y-4">
+ <div className="border-b border-b-border pb-2 text-sm text-muted">
+ Configure Timed Access
+ </div>
+ {isExpired && <Badge variant="danger">Expired</Badge>}
+ <Controller
+ control={form.control}
+ defaultValue="1h"
+ name="temporaryAccess.temporaryRange"
+ render={({ field, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel>
+ <TtlFormLabel label="Validity" />
+ </FieldLabel>
+ <UnstableInput {...field} isError={Boolean(error?.message)} />
+ {error?.message && <FieldError>{error.message}</FieldError>}
+ </Field>
+ )}
+ />
+ <div className="flex items-center space-x-2">
+ <Button
+ size="xs"
+ variant="outline"
+ onClick={() => {
+ const temporaryRange = form.getValues(
+ "temporaryAccess.temporaryRange"
+ );
+ if (!temporaryRange) {
+ form.setError(
+ "temporaryAccess.temporaryRange",
+ { type: "required", message: "Required" },
+ { shouldFocus: true }
+ );
+ return;
+ }
+ form.clearErrors("temporaryAccess.temporaryRange");
+ form.setValue(
+ "temporaryAccess",
+ {
+ isTemporary: true,
+ temporaryAccessStartTime: new Date().toISOString(),
+ temporaryRange,
+ temporaryAccessEndTime: new Date(
+ new Date().getTime() + ms(temporaryRange)
+ ).toISOString()
+ },
+ { shouldDirty: true }
+ );
+ }}
+ >
+ {isTemporary ? "Restart" : "Configure"}
+ </Button>
+ {isTemporary && (
+ <Button
+ size="xs"
+ variant="danger"
+ onClick={() => {
+ form.setValue(
+ "temporaryAccess",
+ {
+ isTemporary: false
+ },
+ { shouldDirty: true }
+ );
+ }}
+ >
+ Remove Duration
+ </Button>
+ )}
+ </div>
+ </div>
+ </PopoverContent>
+ </Popover>
+ </div>
+ </div>
</div>
+ <UnstableSeparator />
<div>
- <Popover>
- <PopoverTrigger disabled={isMemberEditDisabled} asChild>
- <div className="w-full max-w-md grow">
- <FormLabel label="Duration" />
- <Tooltip content={toolTipText}>
- <Button
- type="button"
- variant="outline"
- disabled={isMemberEditDisabled}
- className={twMerge(
- "w-full border-none bg-mineshaft-600 py-2.5 text-xs capitalize hover:bg-mineshaft-500",
- isTemporary && "text-primary",
- isExpired && "text-red-600"
- )}
- >
- {isTemporary && <ClockIcon className="size-4" />}
- {text}
- <ChevronDownIcon className="ml-2 size-4" />
- </Button>
- </Tooltip>
- </div>
- </PopoverTrigger>
- <PopoverContent
- arrowClassName="fill-gray-600"
- side="right"
- sideOffset={12}
- hideCloseBtn
- className="border border-gray-600 pt-4"
- >
- <div className="flex flex-col space-y-4">
- <div className="border-b border-b-gray-700 pb-2 text-sm text-mineshaft-300">
- Configure Timed Access
- </div>
- {isExpired && <Badge variant="danger">Expired</Badge>}
- <Controller
- control={form.control}
- defaultValue="1h"
- name="temporaryAccess.temporaryRange"
- render={({ field, fieldState: { error } }) => (
- <FormControl
- label={<TtlFormLabel label="Validity" />}
- isError={Boolean(error?.message)}
- errorText={error?.message}
- >
- <Input {...field} />
- </FormControl>
- )}
+ <div className="mb-3 flex w-full items-center justify-between">
+ <div className="text-lg">Policies</div>
+ <div className="flex items-center gap-2">
+ {isDirty && (
+ <Button
+ type="button"
+ className="mr-4 text-muted"
+ variant="ghost"
+ disabled={isSubmitting}
+ onClick={() => {
+ if (privilegeDetails) {
+ reset({
+ ...privilegeDetails,
+ permissions: rolePermission2Form(privilegeDetails.permissions),
+ temporaryAccess: privilegeDetails.isTemporary
+ ? {
+ isTemporary: true,
+ temporaryRange: privilegeDetails.temporaryRange || "",
+ temporaryAccessEndTime:
+ privilegeDetails.temporaryAccessEndTime || "",
+ temporaryAccessStartTime:
+ privilegeDetails.temporaryAccessStartTime || ""
+ }
+ : { isTemporary: false }
+ });
+ } else {
+ reset({
+ slug: "",
+ temporaryAccess: { isTemporary: false },
+ permissions: {}
+ });
+ }
+ }}
+ >
+ Discard
+ </Button>
+ )}
+ {currentProject && (
+ <AddPoliciesButton
+ isDisabled={isDisabled}
+ projectType={currentProject.type}
+ projectId={projectId}
+ allowedSubjects={filteredPermissionSubjects}
+ portalContainer={menuPortalContainerRef}
/>
- <div className="flex items-center space-x-2">
- <Button
- size="xs"
- variant="outline"
- onClick={() => {
- const temporaryRange = form.getValues("temporaryAccess.temporaryRange");
- if (!temporaryRange) {
- form.setError(
- "temporaryAccess.temporaryRange",
- { type: "required", message: "Required" },
- { shouldFocus: true }
- );
- return;
- }
- form.clearErrors("temporaryAccess.temporaryRange");
- form.setValue(
- "temporaryAccess",
- {
- isTemporary: true,
- temporaryAccessStartTime: new Date().toISOString(),
- temporaryRange,
- temporaryAccessEndTime: new Date(
- new Date().getTime() + ms(temporaryRange)
- ).toISOString()
- },
- { shouldDirty: true }
- );
- }}
- >
- {isTemporary ? "Restart" : "Grant"}
- </Button>
- {isTemporary && (
- <Button
- size="xs"
- variant="danger"
- onClick={() => {
- form.setValue(
- "temporaryAccess",
- {
- isTemporary: false
- },
- { shouldDirty: true }
- );
- }}
+ )}
+ </div>
+ </div>
+ {(isCreate || !isPending) && !hasPermissions && <PermissionEmptyState />}
+ {hasPermissions && (
+ <div className="thin-scrollbar overflow-y-auto">
+ <UnstableAccordion
+ type="multiple"
+ value={openPolicies}
+ onValueChange={setOpenPolicies}
+ className="overflow-clip rounded-md border border-border bg-container"
+ >
+ {filteredPermissionSubjects.map((permissionSubject) => {
+ const filteredActions = getFilteredActionsForSubject(permissionSubject);
+ if (filteredActions.length === 0) return null;
+
+ return (
+ <GeneralPermissionPolicies
+ subject={permissionSubject}
+ actions={filteredActions}
+ title={PROJECT_PERMISSION_OBJECT[permissionSubject].title}
+ description={PROJECT_PERMISSION_OBJECT[permissionSubject].description}
+ key={`project-permission-${permissionSubject}`}
+ isDisabled={isDisabled}
+ isOpen={openPolicies.includes(permissionSubject)}
+ menuPortalContainerRef={menuPortalContainerRef}
>
- Revoke Access
- </Button>
- )}
- </div>
- </div>
- </PopoverContent>
- </Popover>
- </div>
- </div>
- </div>
- <UnstableSeparator />
- <div>
- <div className="mb-3 flex w-full items-center justify-between">
- <div className="text-lg">Policies</div>
- <div className="flex items-center gap-2">
- {isDirty && (
- <Button
- type="button"
- className="mr-4 text-muted"
- variant="ghost"
- disabled={isSubmitting}
- onClick={() => {
- if (privilegeDetails) {
- reset({
- ...privilegeDetails,
- permissions: rolePermission2Form(privilegeDetails.permissions),
- temporaryAccess: privilegeDetails.isTemporary
- ? {
- isTemporary: true,
- temporaryRange: privilegeDetails.temporaryRange || "",
- temporaryAccessEndTime: privilegeDetails.temporaryAccessEndTime || "",
- temporaryAccessStartTime:
- privilegeDetails.temporaryAccessStartTime || ""
- }
- : { isTemporary: false }
- });
- } else {
- reset({
- slug: "",
- temporaryAccess: { isTemporary: false },
- permissions: {}
- });
- }
- }}
- >
- Discard
- </Button>
- )}
- {currentProject && (
- <AddPoliciesButton
- isDisabled={isDisabled}
- projectType={currentProject.type}
- projectId={projectId}
- allowedSubjects={filteredPermissionSubjects}
- />
+ {renderConditionalComponents(permissionSubject, isDisabled)}
+ </GeneralPermissionPolicies>
+ );
+ })}
+ </UnstableAccordion>
+ </div>
)}
</div>
</div>
- {(isCreate || !isPending) && !hasPermissions && <PermissionEmptyState />}
- {hasPermissions && (
- <div className="scrollbar-thin max-h-[50vh] overflow-y-auto">
- <UnstableAccordion
- type="multiple"
- value={openPolicies}
- onValueChange={setOpenPolicies}
- className="overflow-clip rounded-md border border-border bg-container"
- >
- {filteredPermissionSubjects.map((permissionSubject) => {
- const filteredActions = getFilteredActionsForSubject(permissionSubject);
- if (filteredActions.length === 0) return null;
-
- return (
- <GeneralPermissionPolicies
- subject={permissionSubject}
- actions={filteredActions}
- title={PROJECT_PERMISSION_OBJECT[permissionSubject].title}
- description={PROJECT_PERMISSION_OBJECT[permissionSubject].description}
- key={`project-permission-${permissionSubject}`}
- isDisabled={isDisabled}
- isOpen={openPolicies.includes(permissionSubject)}
- menuPortalContainerRef={menuPortalContainerRef}
- >
- {renderConditionalComponents(permissionSubject, isDisabled)}
- </GeneralPermissionPolicies>
- );
- })}
- </UnstableAccordion>
- </div>
- )}
</div>
- <UnstableSeparator />
- <div className="flex w-full items-center justify-end gap-x-2">
+ <SheetFooter className="justify-end border-t">
<Button variant="ghost" onClick={onGoBack}>
Cancel
</Button>
@@ -443,7 +463,7 @@ export const MembershipProjectAdditionalPrivilegeModifySection = ({
<SaveIcon />
Save
</Button>
- </div>
+ </SheetFooter>
</FormProvider>
</form>
);
diff --git a/frontend/src/pages/project/RoleDetailsBySlugPage/components/AddPoliciesButton.tsx b/frontend/src/pages/project/RoleDetailsBySlugPage/components/AddPoliciesButton.tsx
index 471af9f406..62174fa626 100644
--- a/frontend/src/pages/project/RoleDetailsBySlugPage/components/AddPoliciesButton.tsx
+++ b/frontend/src/pages/project/RoleDetailsBySlugPage/components/AddPoliciesButton.tsx
@@ -17,7 +17,7 @@ import { OrgMembershipRole } from "@app/helpers/roles";
import { usePopUp } from "@app/hooks";
import { useGetVaultExternalMigrationConfigs } from "@app/hooks/api/migration";
import { ProjectType } from "@app/hooks/api/projects/types";
-import { PolicySelectionModal } from "@app/pages/project/RoleDetailsBySlugPage/components/PolicySelectionModal";
+import { PolicySelectionPopover } from "@app/pages/project/RoleDetailsBySlugPage/components/PolicySelectionModal";
import { PolicyTemplateModal } from "@app/pages/project/RoleDetailsBySlugPage/components/PolicyTemplateModal";
import { VaultPolicyImportModal } from "@app/pages/project/RoleDetailsBySlugPage/components/VaultPolicyImportModal";
@@ -26,13 +26,15 @@ type Props = {
projectType: ProjectType;
projectId?: string;
allowedSubjects?: ProjectPermissionSub[];
+ portalContainer?: React.RefObject<HTMLElement | null>;
};
export const AddPoliciesButton = ({
isDisabled,
projectType,
projectId,
- allowedSubjects
+ allowedSubjects,
+ portalContainer
}: Props) => {
const { popUp, handlePopUpToggle, handlePopUpOpen, handlePopUpClose } = usePopUp([
"addPolicy",
@@ -50,16 +52,24 @@ export const AddPoliciesButton = ({
return (
<div>
<UnstableButtonGroup>
- <Button
- type="button"
- className="rounded-r-none"
- isDisabled={isDisabled}
- variant="outline"
- onClick={() => handlePopUpToggle("addPolicy")}
+ <PolicySelectionPopover
+ type={projectType}
+ isOpen={popUp.addPolicy.isOpen}
+ onOpenChange={(isOpen) => handlePopUpToggle("addPolicy", isOpen)}
+ projectId={projectId}
+ allowedSubjects={allowedSubjects}
+ portalContainer={portalContainer?.current}
>
- <PlusIcon />
- Add Policies
- </Button>
+ <Button
+ type="button"
+ className="rounded-r-none"
+ isDisabled={isDisabled}
+ variant="outline"
+ >
+ <PlusIcon />
+ Add Policies
+ </Button>
+ </PolicySelectionPopover>
<UnstableDropdownMenu
open={popUp.addPolicyOptions.isOpen}
onOpenChange={(isOpen) => handlePopUpToggle("addPolicyOptions", isOpen)}
@@ -102,13 +112,6 @@ export const AddPoliciesButton = ({
</UnstableDropdownMenuContent>
</UnstableDropdownMenu>
</UnstableButtonGroup>
- <PolicySelectionModal
- projectId={projectId}
- type={projectType}
- isOpen={popUp.addPolicy.isOpen}
- onOpenChange={(isOpen) => handlePopUpToggle("addPolicy", isOpen)}
- allowedSubjects={allowedSubjects}
- />
<PolicyTemplateModal
type={projectType}
isOpen={popUp.applyTemplate.isOpen}
diff --git a/frontend/src/pages/project/RoleDetailsBySlugPage/components/PolicySelectionModal.tsx b/frontend/src/pages/project/RoleDetailsBySlugPage/components/PolicySelectionModal.tsx
index d01cca8a50..24874926a3 100644
--- a/frontend/src/pages/project/RoleDetailsBySlugPage/components/PolicySelectionModal.tsx
+++ b/frontend/src/pages/project/RoleDetailsBySlugPage/components/PolicySelectionModal.tsx
@@ -1,30 +1,24 @@
-import { useState } from "react";
-import { Controller, useForm, useFormContext } from "react-hook-form";
-import { faCheck, faSearch, faXmark, faXmarkCircle } from "@fortawesome/free-solid-svg-icons";
-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import { useFormContext } from "react-hook-form";
+import { CheckIcon } from "lucide-react";
import {
- Button,
- EmptyState,
- IconButton,
- Input,
- Modal,
- ModalClose,
- ModalContent,
- Table,
- TableContainer,
- TBody,
- Td,
- Tooltip,
- Tr
-} from "@app/components/v2";
+ Command,
+ CommandEmpty,
+ CommandGroup,
+ CommandInput,
+ CommandItem,
+ CommandList,
+ Popover,
+ PopoverContent,
+ PopoverTrigger
+} from "@app/components/v3";
+import { cn } from "@app/components/v3/utils";
import { ProjectPermissionSub } from "@app/context";
import { useGetWorkspaceIntegrations } from "@app/hooks/api";
import { ProjectType } from "@app/hooks/api/projects/types";
import {
EXCLUDED_PERMISSION_SUBS,
- isConditionalSubjects,
PROJECT_PERMISSION_OBJECT,
ProjectTypePermissionSubjects,
TFormSchema
@@ -36,214 +30,117 @@ type Props = {
type: ProjectType;
projectId?: string;
allowedSubjects?: ProjectPermissionSub[];
+ children: React.ReactNode;
+ portalContainer?: HTMLElement | null;
};
-type ContentProps = {
- onClose: () => void;
-
- // note(daniel): we allow projectId to be undefined because we use this component for project templates, in which case no project ID will be present.
+const Content = ({
+ projectId,
+ type: projectType,
+ allowedSubjects
+}: {
projectId?: string;
type: ProjectType;
allowedSubjects?: ProjectPermissionSub[];
-};
-
-type TForm = { permissions: Record<ProjectPermissionSub, boolean> };
-
-const Content = ({ onClose, projectId, type: projectType, allowedSubjects }: ContentProps) => {
+}) => {
const rootForm = useFormContext<TFormSchema>();
- const [search, setSearch] = useState("");
const isSecretManagerProject = projectType === ProjectType.SecretManager;
const { data: integrations = [] } = useGetWorkspaceIntegrations(projectId ?? "", {
enabled: Boolean(isSecretManagerProject && projectId),
refetchInterval: false
});
- const {
- control,
- handleSubmit,
- formState: { isDirty },
- setValue,
- reset
- } = useForm<TForm>({
- defaultValues: {
- permissions: Object.fromEntries(
- Object.values(ProjectPermissionSub).map((subject) => [subject, false])
- )
- }
- });
-
const hasNativeIntegrations = integrations.length > 0;
const filteredPolicies = Object.entries(PROJECT_PERMISSION_OBJECT)
.filter(
- ([subject, { title }]) =>
+ ([subject]) =>
ProjectTypePermissionSubjects[projectType ?? ProjectType.SecretManager][
subject as ProjectPermissionSub
- ] && (search ? title.toLowerCase().includes(search.toLowerCase()) : true)
+ ]
)
.filter(([subject]) => !EXCLUDED_PERMISSION_SUBS.includes(subject as ProjectPermissionSub))
- .filter(
- ([subject]) =>
- // Hide Native Integrations policy if project has no integrations
- subject !== ProjectPermissionSub.Integrations || hasNativeIntegrations
- )
+ .filter(([subject]) => subject !== ProjectPermissionSub.Integrations || hasNativeIntegrations)
.filter(
([subject]) => !allowedSubjects || allowedSubjects.includes(subject as ProjectPermissionSub)
)
.sort((a, b) => a[1].title.localeCompare(b[1].title))
.map(([subject]) => subject);
- const onSubmit = () =>
- handleSubmit((form) => {
- Object.entries(form.permissions).forEach(([subject, add]) => {
- if (!add) return;
-
- const type = subject as ProjectPermissionSub;
-
- const rootPolicyValue = rootForm.getValues("permissions")?.[type];
+ const handleSelectPolicy = (subject: string) => {
+ const type = subject as ProjectPermissionSub;
+ const rootPolicyValue = rootForm.getValues("permissions")?.[type];
+ const hasExisting = rootPolicyValue && rootPolicyValue.length > 0;
- if (rootPolicyValue && isConditionalSubjects(subject as ProjectPermissionSub)) {
- rootForm.setValue(
- `permissions.${type}`,
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-ignore-error akhilmhdh: this is because of ts collision with both
- [...rootPolicyValue, {}],
- { shouldDirty: true, shouldTouch: true }
- );
- } else if (!rootPolicyValue?.length) {
- rootForm.setValue(
- `permissions.${type}`,
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-ignore-error akhilmhdh: this is because of ts collision with both
- [{}],
- {
- shouldDirty: true,
- shouldTouch: true
- }
- );
- }
+ if (hasExisting) {
+ rootForm.setValue(`permissions.${type}`, undefined as never, {
+ shouldDirty: true,
+ shouldTouch: true
});
- onClose();
- })();
+ } else {
+ rootForm.setValue(
+ `permissions.${type}`,
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ // @ts-ignore-error akhilmhdh: this is because of ts collision with both
+ [{}],
+ { shouldDirty: true, shouldTouch: true }
+ );
+ }
+ };
+
+ const currentPermissions = rootForm.watch("permissions");
return (
- <>
- <Input
- placeholder="Search policies..."
- value={search}
- onChange={(e) => setSearch(e.target.value)}
- leftIcon={<FontAwesomeIcon icon={faSearch} />}
- rightIcon={
- search ? (
- <IconButton ariaLabel="Clear search" variant="plain" onClick={() => setSearch("")}>
- <FontAwesomeIcon icon={faXmark} />
- </IconButton>
- ) : null
- }
- />
- <TableContainer className="mt-4 max-h-112 thin-scrollbar">
- <div className="sticky top-0 z-30 flex justify-between border-b border-b-mineshaft-600 bg-mineshaft-800 py-3 pr-4 pl-5 font-inter text-sm font-medium text-bunker-300">
- <span>Resource</span>
- <div className="flex gap-2">
- <Button
- variant="plain"
- className="p-0 text-mineshaft-400"
- size="xs"
- colorSchema="secondary"
- onClick={() => {
- setValue(
- "permissions",
- Object.fromEntries(
- filteredPolicies.map((subject) => [subject, true])
- ) as TForm["permissions"],
- { shouldDirty: true }
- );
- }}
- >
- Select All
- </Button>
- <Tooltip content="Clear selection">
- <IconButton
- ariaLabel="Clear selection"
- onClick={() => reset()}
- variant="plain"
- size="xs"
- className={`text-mineshaft-400 ${!isDirty ? "pointer-events-none opacity-50" : ""} hover:text-red`}
- isDisabled={!isDirty}
- >
- <FontAwesomeIcon icon={faXmarkCircle} />
- </IconButton>
- </Tooltip>
- </div>
- </div>
- <Table>
- <TBody>
- {filteredPolicies.map((subject) => (
- <Controller
- control={control}
+ <Command>
+ <CommandInput placeholder="Search policies..." />
+ <CommandList>
+ <CommandEmpty>No policies found.</CommandEmpty>
+ <CommandGroup>
+ {filteredPolicies.map((subject) => {
+ const hasPolicy = Boolean(
+ currentPermissions?.[subject as ProjectPermissionSub]?.length
+ );
+
+ return (
+ <CommandItem
key={`permission-add-${subject}`}
- render={({ field: { value, onChange } }) => (
- <Tr
- className={`${value ? "bg-mineshaft-600/30" : ""} cursor-pointer hover:bg-mineshaft-700`}
- onClick={() => onChange(!value)}
- >
- <Td className={`${value ? "text-mineshaft-100" : "text-mineshaft-300"} w-full`}>
- {PROJECT_PERMISSION_OBJECT[subject as ProjectPermissionSub].title}
- </Td>
- <Td>
- {value ? <FontAwesomeIcon className="text-green" icon={faCheck} /> : null}
- </Td>
- </Tr>
- )}
- name={`permissions.${subject as ProjectPermissionSub}`}
- />
- ))}
- </TBody>
- </Table>
- {!filteredPolicies.length && (
- <EmptyState
- iconSize="2x"
- icon={faSearch}
- className="pt-8! pb-4!"
- title="No policies match search"
- />
- )}
- </TableContainer>
- <div className="mt-8 flex space-x-4">
- <Button isDisabled={!isDirty} onClick={onSubmit}>
- Add Policies
- </Button>
- <ModalClose asChild>
- <Button colorSchema="secondary" variant="plain">
- Cancel
- </Button>
- </ModalClose>
- </div>
- </>
+ value={subject}
+ keywords={[PROJECT_PERMISSION_OBJECT[subject as ProjectPermissionSub].title]}
+ onSelect={handleSelectPolicy}
+ >
+ <CheckIcon
+ className={cn("size-4 shrink-0", hasPolicy ? "opacity-100" : "opacity-0")}
+ />
+ <span>{PROJECT_PERMISSION_OBJECT[subject as ProjectPermissionSub].title}</span>
+ </CommandItem>
+ );
+ })}
+ </CommandGroup>
+ </CommandList>
+ </Command>
);
};
-export const PolicySelectionModal = ({
+export const PolicySelectionPopover = ({
isOpen,
onOpenChange,
type,
projectId,
- allowedSubjects
+ allowedSubjects,
+ children,
+ portalContainer
}: Props) => {
return (
- <Modal isOpen={isOpen} onOpenChange={onOpenChange}>
- <ModalContent
- title="Add Policies"
- subTitle="Select one or more policies to add to this role."
- className="max-w-3xl"
+ <Popover open={isOpen} onOpenChange={onOpenChange}>
+ <PopoverTrigger asChild>{children}</PopoverTrigger>
+ <PopoverContent
+ align="end"
+ className="w-72 p-0"
+ container={portalContainer}
+ onWheel={(e) => e.stopPropagation()}
>
- <Content
- onClose={() => onOpenChange(false)}
- type={type}
- projectId={projectId}
- allowedSubjects={allowedSubjects}
- />
- </ModalContent>
- </Modal>
+ <Content type={type} projectId={projectId} allowedSubjects={allowedSubjects} />
+ </PopoverContent>
+ </Popover>
);
};
diff --git a/frontend/src/pages/project/RoleDetailsBySlugPage/components/PolicyTemplateModal.tsx b/frontend/src/pages/project/RoleDetailsBySlugPage/components/PolicyTemplateModal.tsx
index 4af7309470..1479053c8d 100644
--- a/frontend/src/pages/project/RoleDetailsBySlugPage/components/PolicyTemplateModal.tsx
+++ b/frontend/src/pages/project/RoleDetailsBySlugPage/components/PolicyTemplateModal.tsx
@@ -193,7 +193,7 @@ export const PolicyTemplateModal = ({ isOpen, onOpenChange, type }: Props) => {
<ModalContent
title="Policy Templates"
subTitle="Select a template with prepopulated policies to get started. You can always add more policies later."
- className="max-w-3xl"
+ className="z-60 max-w-3xl"
>
<Content onClose={() => onOpenChange(false)} type={type} />
</ModalContent>
diff --git a/frontend/src/pages/project/RoleDetailsBySlugPage/components/VaultPolicyImportModal.tsx b/frontend/src/pages/project/RoleDetailsBySlugPage/components/VaultPolicyImportModal.tsx
index 3b095e8ff8..8711739ee7 100644
--- a/frontend/src/pages/project/RoleDetailsBySlugPage/components/VaultPolicyImportModal.tsx
+++ b/frontend/src/pages/project/RoleDetailsBySlugPage/components/VaultPolicyImportModal.tsx
@@ -318,7 +318,7 @@ export const VaultPolicyImportModal = ({ isOpen, onOpenChange }: Props) => {
<ModalContent
title="Import from HashiCorp Vault"
subTitle="Select a policy from your Vault namespace or paste your own HCL policy to translate it into Infisical permissions."
- className="max-w-4xl"
+ className="z-60 max-w-4xl"
>
<Content onClose={() => onOpenChange(false)} />
</ModalContent>
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretAccessInsights.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretAccessInsights.tsx
index 018a690eff..1c9a6d5ae8 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretAccessInsights.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretAccessInsights.tsx
@@ -1,5 +1,14 @@
+import { useMemo, useRef, useState } from "react";
+import { subject } from "@casl/ability";
import { Link } from "@tanstack/react-router";
-import { HardDriveIcon, UserIcon, UsersIcon } from "lucide-react";
+import {
+ ExternalLinkIcon,
+ HardDriveIcon,
+ MoreVerticalIcon,
+ PlusIcon,
+ UserIcon,
+ UsersIcon
+} from "lucide-react";
import {
Badge,
@@ -9,17 +18,40 @@ import {
ItemFooter,
ItemGroup,
ItemTitle,
+ Sheet,
+ SheetContent,
+ SheetDescription,
+ SheetHeader,
+ SheetTitle,
Skeleton,
+ UnstableDropdownMenu,
+ UnstableDropdownMenuContent,
+ UnstableDropdownMenuItem,
+ UnstableDropdownMenuTrigger,
UnstableEmpty,
UnstableEmptyDescription,
UnstableEmptyHeader,
- UnstableEmptyTitle
+ UnstableEmptyTitle,
+ UnstableIconButton
} from "@app/components/v3";
-import { useOrganization, useProject } from "@app/context";
+import {
+ ProjectPermissionIdentityActions,
+ ProjectPermissionMemberActions,
+ ProjectPermissionSub,
+ useOrganization,
+ useProject,
+ useProjectPermission
+} from "@app/context";
+import {
+ PermissionConditionOperators,
+ ProjectPermissionSecretActions
+} from "@app/context/ProjectPermissionContext/types";
import { getProjectBaseURL } from "@app/helpers/project";
import { useGetSecretAccessList } from "@app/hooks/api/secrets/queries";
import { SecretAccessListEntry } from "@app/hooks/api/secrets/types";
import { camelCaseToSpaces } from "@app/lib/fn/string";
+import { IdentityProjectAdditionalPrivilegeModifySection } from "@app/pages/project/IdentityDetailsByIDPage/components/IdentityProjectAdditionalPrivilegeSection/IdentityProjectAdditionalPrivilegeModifySection";
+import { MembershipProjectAdditionalPrivilegeModifySection } from "@app/pages/project/MemberDetailsByIDPage/components/MemberProjectAdditionalPrivilegeSection/MembershipProjectAdditionalPrivilegeModifySection";
type Props = {
secretKey: string;
@@ -27,15 +59,23 @@ type Props = {
secretPath: string;
};
+type EditingPrivilege = {
+ type: "user" | "identity";
+ membershipId: string;
+ identityId?: string;
+ name: string;
+};
+
function AccessCard({
entry,
-
linkTo,
- linkParams
+ linkParams,
+ onEdit
}: {
entry: SecretAccessListEntry;
linkTo?: string;
linkParams?: Record<string, string>;
+ onEdit?: () => void;
}) {
const cardContent = (
<>
@@ -45,7 +85,7 @@ function AccessCard({
</ItemTitle>
</ItemContent>
<ItemFooter>
- <div className="flex flex-wrap gap-2">
+ <div className="mt-2 flex flex-wrap gap-2">
{entry.allowedActions.map((action) => (
<Badge key={action} className="capitalize" variant="neutral">
{camelCaseToSpaces(action)}
@@ -58,9 +98,46 @@ function AccessCard({
if (linkTo && linkParams) {
return (
- <Item variant="outline" asChild>
+ <Item variant="outline" asChild className="group relative">
<Link to={linkTo as "."} params={linkParams}>
- {cardContent}
+ <div className="flex w-full items-start justify-between gap-2">
+ <div className="min-w-0 flex-1">{cardContent}</div>
+ <UnstableDropdownMenu>
+ <UnstableDropdownMenuTrigger asChild>
+ <UnstableIconButton
+ size="xs"
+ variant="ghost"
+ className="absolute top-1 right-1 shrink-0"
+ onClick={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ }}
+ >
+ <MoreVerticalIcon />
+ </UnstableIconButton>
+ </UnstableDropdownMenuTrigger>
+ <UnstableDropdownMenuContent align="end" onClick={(e) => e.stopPropagation()}>
+ {onEdit && (
+ <UnstableDropdownMenuItem
+ onClick={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ onEdit();
+ }}
+ >
+ <PlusIcon />
+ Add Additional Privilege
+ </UnstableDropdownMenuItem>
+ )}
+ <UnstableDropdownMenuItem asChild>
+ <Link to={linkTo as "."} params={linkParams}>
+ <ExternalLinkIcon />
+ Manage Access
+ </Link>
+ </UnstableDropdownMenuItem>
+ </UnstableDropdownMenuContent>
+ </UnstableDropdownMenu>
+ </div>
</Link>
</Item>
);
@@ -92,6 +169,43 @@ function SectionHeader({
export function SecretAccessInsights({ secretKey, environment, secretPath }: Props) {
const { currentOrg } = useOrganization();
const { currentProject } = useProject();
+ const { permission } = useProjectPermission();
+ const sheetContainerRef = useRef<HTMLDivElement>(null);
+ const [editingPrivilege, setEditingPrivilege] = useState<EditingPrivilege | null>(null);
+
+ const canEditMemberPrivileges = permission.can(
+ ProjectPermissionMemberActions.Edit,
+ ProjectPermissionSub.Member
+ );
+
+ const initialPermissions = useMemo(
+ () => ({
+ [ProjectPermissionSub.Secrets]: [
+ {
+ [ProjectPermissionSecretActions.ReadValue]: true,
+ [ProjectPermissionSecretActions.DescribeSecret]: true,
+ conditions: [
+ {
+ operator: PermissionConditionOperators.$EQ,
+ lhs: "environment",
+ rhs: environment
+ },
+ {
+ operator: PermissionConditionOperators.$EQ,
+ lhs: "secretPath",
+ rhs: secretPath
+ },
+ {
+ operator: PermissionConditionOperators.$EQ,
+ lhs: "secretName",
+ rhs: secretKey
+ }
+ ]
+ }
+ ]
+ }),
+ [environment, secretPath, secretKey]
+ );
const { data: secretAccessList, isLoading } = useGetSecretAccessList({
projectId: currentProject.id,
@@ -146,78 +260,142 @@ export function SecretAccessInsights({ secretKey, environment, secretPath }: Pro
}
return (
- <div className="flex thin-scrollbar flex-col gap-6 overflow-y-auto p-4">
- {hasUsers && (
- <div>
- <SectionHeader
- icon={<UserIcon className="size-4 text-accent" />}
- title="Users"
- count={secretAccessList.users.length}
- />
- <ItemGroup>
- {secretAccessList.users.map((user) => (
- <AccessCard
- key={user.id}
- entry={user}
- linkTo={`${getProjectBaseURL(currentProject.type)}/members/$membershipId`}
- linkParams={{
- orgId: currentOrg.id,
- projectId: currentProject.id,
- membershipId: user.membershipId
- }}
- />
- ))}
- </ItemGroup>
- </div>
- )}
-
- {hasIdentities && (
- <div>
- <SectionHeader
- icon={<HardDriveIcon className="size-4 text-accent" />}
- title="Machine Identities"
- count={secretAccessList.identities.length}
- />
- <ItemGroup>
- {secretAccessList.identities.map((identity) => (
- <AccessCard
- key={identity.id}
- entry={identity}
- linkTo={`${getProjectBaseURL(currentProject.type)}/identities/$identityId`}
- linkParams={{
- orgId: currentOrg.id,
- projectId: currentProject.id,
- identityId: identity.id
- }}
- />
- ))}
- </ItemGroup>
- </div>
- )}
-
- {hasGroups && (
- <div>
- <SectionHeader
- icon={<UsersIcon className="size-4 text-accent" />}
- title="Groups"
- count={secretAccessList.groups.length}
- />
- <ItemGroup>
- {secretAccessList.groups.map((group) => (
- <AccessCard
- key={group.id}
- entry={group}
- linkTo={`${getProjectBaseURL(currentProject.type)}/groups/$groupId`}
- linkParams={{
- orgId: currentOrg.id,
- projectId: currentProject.id,
- groupId: group.id
- }}
- />
- ))}
- </ItemGroup>
- </div>
- )}
- </div>
+ <>
+ <div className="flex thin-scrollbar flex-col gap-6 overflow-y-auto p-4">
+ {hasUsers && (
+ <div>
+ <SectionHeader
+ icon={<UserIcon className="size-4 text-accent" />}
+ title="Users"
+ count={secretAccessList.users.length}
+ />
+ <ItemGroup>
+ {secretAccessList.users.map((user) => (
+ <AccessCard
+ key={user.id}
+ entry={user}
+ linkTo={`${getProjectBaseURL(currentProject.type)}/members/$membershipId`}
+ linkParams={{
+ orgId: currentOrg.id,
+ projectId: currentProject.id,
+ membershipId: user.membershipId
+ }}
+ onEdit={
+ canEditMemberPrivileges
+ ? () =>
+ setEditingPrivilege({
+ type: "user",
+ membershipId: user.membershipId,
+ name: user.name
+ })
+ : undefined
+ }
+ />
+ ))}
+ </ItemGroup>
+ </div>
+ )}
+
+ {hasIdentities && (
+ <div>
+ <SectionHeader
+ icon={<HardDriveIcon className="size-4 text-accent" />}
+ title="Machine Identities"
+ count={secretAccessList.identities.length}
+ />
+ <ItemGroup>
+ {secretAccessList.identities.map((identity) => {
+ const canEditIdentity = permission.can(
+ ProjectPermissionIdentityActions.Edit,
+ subject(ProjectPermissionSub.Identity, { identityId: identity.id })
+ );
+
+ return (
+ <AccessCard
+ key={identity.id}
+ entry={identity}
+ linkTo={`${getProjectBaseURL(currentProject.type)}/identities/$identityId`}
+ linkParams={{
+ orgId: currentOrg.id,
+ projectId: currentProject.id,
+ identityId: identity.id
+ }}
+ onEdit={
+ canEditIdentity
+ ? () =>
+ setEditingPrivilege({
+ type: "identity",
+ membershipId: identity.membershipId,
+ identityId: identity.id,
+ name: identity.name
+ })
+ : undefined
+ }
+ />
+ );
+ })}
+ </ItemGroup>
+ </div>
+ )}
+
+ {hasGroups && (
+ <div>
+ <SectionHeader
+ icon={<UsersIcon className="size-4 text-accent" />}
+ title="Groups"
+ count={secretAccessList.groups.length}
+ />
+ <ItemGroup>
+ {secretAccessList.groups.map((group) => (
+ <AccessCard
+ key={group.id}
+ entry={group}
+ linkTo={`${getProjectBaseURL(currentProject.type)}/groups/$groupId`}
+ linkParams={{
+ orgId: currentOrg.id,
+ projectId: currentProject.id,
+ groupId: group.id
+ }}
+ />
+ ))}
+ </ItemGroup>
+ </div>
+ )}
+ </div>
+
+ <Sheet
+ open={editingPrivilege !== null}
+ onOpenChange={(isOpen) => {
+ if (!isOpen) setEditingPrivilege(null);
+ }}
+ >
+ <SheetContent ref={sheetContainerRef} className="flex h-full flex-col gap-y-0 sm:max-w-6xl">
+ <SheetHeader className="border-b">
+ <SheetTitle>Add Additional Privilege for {editingPrivilege?.name}</SheetTitle>
+ <SheetDescription>
+ Grant {editingPrivilege?.name} edit access to the secret {secretKey}
+ </SheetDescription>
+ </SheetHeader>
+ {editingPrivilege?.type === "user" && (
+ <MembershipProjectAdditionalPrivilegeModifySection
+ key={editingPrivilege.membershipId}
+ projectMembershipId={editingPrivilege.membershipId}
+ onGoBack={() => setEditingPrivilege(null)}
+ menuPortalContainerRef={sheetContainerRef}
+ initialPermissions={initialPermissions}
+ />
+ )}
+ {editingPrivilege?.type === "identity" && editingPrivilege.identityId && (
+ <IdentityProjectAdditionalPrivilegeModifySection
+ key={editingPrivilege.identityId}
+ identityId={editingPrivilege.identityId}
+ onGoBack={() => setEditingPrivilege(null)}
+ menuPortalContainerRef={sheetContainerRef}
+ initialPermissions={initialPermissions}
+ />
+ )}
+ </SheetContent>
+ </Sheet>
+ </>
);
}