Skip to content

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

address the rest of reviews

x03220501fad3542b4b
diff --git a/backend/src/ee/services/pam-account/pam-account-schemas.test.ts b/backend/src/ee/services/pam-account/pam-account-schemas.test.ts
index 24a3cf0762..0a0390521e 100644
--- a/backend/src/ee/services/pam-account/pam-account-schemas.test.ts
+++ b/backend/src/ee/services/pam-account/pam-account-schemas.test.ts
@@ -50,7 +50,8 @@ describe("buildPamAccountTypeMetadata", () => {
});
expect(fieldByKey(postgres!.connectionFields, "port")).toMatchObject({
widget: "number",
- required: true
+ required: true,
+ defaultValue: 5432
});
expect(fieldByKey(postgres!.connectionFields, "sslEnabled")).toMatchObject({ widget: "boolean" });
diff --git a/backend/src/ee/services/pam-account/pam-account-schemas.ts b/backend/src/ee/services/pam-account/pam-account-schemas.ts
index e220a8fd06..edd1986512 100644
--- a/backend/src/ee/services/pam-account/pam-account-schemas.ts
+++ b/backend/src/ee/services/pam-account/pam-account-schemas.ts
@@ -41,6 +41,7 @@ export const ACCOUNT_TYPE_CONFIGS = {
}),
sanitizedCredentials: z.object({ username: z.string().optional() }),
ui: {
+ port: { defaultValue: 5432 },
sslEnabled: { label: "SSL Enabled" },
sslRejectUnauthorized: {
label: "Reject Unauthorized",
@@ -81,6 +82,7 @@ export const ACCOUNT_TYPE_CONFIGS = {
}),
sanitizedCredentials: z.object({ username: z.string().optional() }),
ui: {
+ port: { defaultValue: 3306 },
sslEnabled: { label: "SSL Enabled" },
sslRejectUnauthorized: {
label: "Reject Unauthorized",
@@ -129,6 +131,7 @@ export const ACCOUNT_TYPE_CONFIGS = {
username: z.string().optional()
}),
ui: {
+ port: { defaultValue: 22 },
authMethod: { label: "Auth Method" },
password: { widget: PamFieldWidget.Password, secret: true },
privateKey: { label: "Private Key", widget: PamFieldWidget.Textarea, secret: true }
@@ -154,6 +157,7 @@ export const ACCOUNT_TYPE_CONFIGS = {
label?: string;
widget?: PamFieldWidget;
secret?: boolean;
+ defaultValue?: string | number | boolean;
showWhen?: { field: string; equals: string | boolean };
}
>;
@@ -262,6 +266,9 @@ export const PamFieldDescriptorSchema = z.object({
secret: z.boolean(),
options: z.array(z.object({ label: z.string(), value: z.string() })).optional(),
+ // Value the form prefills the field with on create
+ defaultValue: z.union([z.string(), z.number(), z.boolean()]).optional(),
+
// Only render when the referenced field equals this value
showWhen: z.object({ field: z.string(), equals: z.union([z.string(), z.boolean()]) }).optional()
});
@@ -282,6 +289,7 @@ type TFieldUiHint = {
label?: string;
widget?: PamFieldWidget;
secret?: boolean;
+ defaultValue?: string | number | boolean;
showWhen?: PamFieldDescriptor["showWhen"];
};
@@ -338,6 +346,7 @@ const describeField = (
...(widget === PamFieldWidget.Select && enumValues
? { options: enumValues.map((v) => ({ label: humanizeKey(v), value: v })) }
: {}),
+ ...(hint.defaultValue !== undefined ? { defaultValue: hint.defaultValue } : {}),
...(resolvedShowWhen ? { showWhen: resolvedShowWhen } : {})
};
};
diff --git a/frontend/src/hooks/api/pam/types/index.ts b/frontend/src/hooks/api/pam/types/index.ts
index 84b1df1af0..fd6f1f229d 100644
--- a/frontend/src/hooks/api/pam/types/index.ts
+++ b/frontend/src/hooks/api/pam/types/index.ts
@@ -30,6 +30,7 @@ export type TPamFieldDescriptor = {
required: boolean;
secret: boolean;
options?: { label: string; value: string }[];
+ defaultValue?: string | number | boolean;
showWhen?: { field: string; equals: string | boolean };
};
diff --git a/frontend/src/pages/pam/PamAccountsPage/PamAccountsPage.tsx b/frontend/src/pages/pam/PamAccountsPage/PamAccountsPage.tsx
index d5f7d5f481..e2ed256be2 100644
--- a/frontend/src/pages/pam/PamAccountsPage/PamAccountsPage.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/PamAccountsPage.tsx
@@ -42,7 +42,7 @@ import {
useListPamFoldersAdmin
} from "@app/hooks/api/pam";
import { ProjectType } from "@app/hooks/api/projects/types";
-import { PamSheetTab, usePamSheetState } from "@app/hooks/usePamSheetState";
+import { usePamSheetState } from "@app/hooks/usePamSheetState";
import { usePopUp } from "@app/hooks/usePopUp";
import { AccountPlatformIcon } from "../PamAccessPage/components/AccountPlatformIcon";
@@ -160,7 +160,7 @@ export const PamAccountsPage = () => {
<Search />
</InputGroupAddon>
<InputGroupInput
- placeholder="Search folders and accounts..."
+ placeholder="Search accounts..."
value={searchInput}
onChange={(e) => setSearchInput(e.target.value)}
/>
@@ -279,13 +279,9 @@ export const PamAccountsPage = () => {
search={searchInput}
templateId={selectedTemplateId}
filterActive={filterActive}
- onOpenAccount={(id) => accountSheet.openSheet(id)}
- onConfigureAccount={(id) => accountSheet.openSheet(id, PamSheetTab.Configuration)}
+ onOpenAccount={(id, tab) => accountSheet.openSheet(id, tab)}
onDeleteAccount={(target) => handlePopUpOpen("deleteAccount", target)}
- onFolderDetails={() => folderSheet.openSheet(folder.id)}
- onFolderConfigure={() =>
- folderSheet.openSheet(folder.id, PamSheetTab.Configuration)
- }
+ onOpenFolder={(tab) => folderSheet.openSheet(folder.id, tab)}
onFolderAddAccount={() =>
handlePopUpOpen("createAccount", { folderId: folder.id })
}
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/AccountActionsMenu.tsx b/frontend/src/pages/pam/PamAccountsPage/components/AccountActionsMenu.tsx
index b8c5c06730..8a0173d32b 100644
--- a/frontend/src/pages/pam/PamAccountsPage/components/AccountActionsMenu.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/AccountActionsMenu.tsx
@@ -1,5 +1,5 @@
import { useState } from "react";
-import { Eye, MoreHorizontal, Settings, Trash2 } from "lucide-react";
+import { MoreHorizontal, Trash2 } from "lucide-react";
import {
DropdownMenu,
@@ -10,23 +10,24 @@ import {
IconButton
} from "@app/components/v3";
import { PamResourcePermissionActions, usePamAccountActions } from "@app/hooks/api/pam";
+import { PamSheetTab } from "@app/hooks/usePamSheetState";
+
+import { PAM_ACCOUNT_TABS, visiblePamTabs } from "../../components/pamResourceTabs";
type Props = {
accountId: string;
- onDetails: () => void;
- onConfigure: () => void;
+ onOpenTab: (tab: PamSheetTab) => void;
onDelete: () => void;
};
-export const AccountActionsMenu = ({ accountId, onDetails, onConfigure, onDelete }: Props) => {
+export const AccountActionsMenu = ({ accountId, onOpenTab, onDelete }: Props) => {
// Defer the permission fetch until the menu is first opened to avoid a request per row
const [hasOpened, setHasOpened] = useState(false);
const { can, isLoading } = usePamAccountActions(accountId, hasOpened);
- const canRead = can(PamResourcePermissionActions.ReadAccounts);
- const canEdit = can(PamResourcePermissionActions.EditAccounts);
+ const tabs = visiblePamTabs(PAM_ACCOUNT_TABS, can);
const canDelete = can(PamResourcePermissionActions.DeleteAccounts);
- const hasAnyAction = canRead || canEdit || canDelete;
+ const hasAnyAction = tabs.length > 0 || canDelete;
return (
<DropdownMenu onOpenChange={(open) => open && setHasOpened(true)}>
@@ -46,18 +47,12 @@ export const AccountActionsMenu = ({ accountId, onDetails, onConfigure, onDelete
{!isLoading && !hasAnyAction && (
<DropdownMenuItem isDisabled>No actions available</DropdownMenuItem>
)}
- {canRead && (
- <DropdownMenuItem onClick={onDetails}>
- <Eye />
- View Details
- </DropdownMenuItem>
- )}
- {canEdit && (
- <DropdownMenuItem onClick={onConfigure}>
- <Settings />
- Configure
+ {tabs.map((tab) => (
+ <DropdownMenuItem key={tab.value} onClick={() => onOpenTab(tab.value)}>
+ <tab.icon />
+ {tab.label}
</DropdownMenuItem>
- )}
+ ))}
{canDelete && (
<>
<DropdownMenuSeparator />
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/AccountDetailSheet.tsx b/frontend/src/pages/pam/PamAccountsPage/components/AccountDetailSheet.tsx
index a911535bc7..859df540c8 100644
--- a/frontend/src/pages/pam/PamAccountsPage/components/AccountDetailSheet.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/AccountDetailSheet.tsx
@@ -7,12 +7,9 @@ import {
MoreHorizontal,
Network,
Pencil,
- Settings,
- Settings2,
SquarePen,
Trash2,
- UserPlus,
- Users
+ UserPlus
} from "lucide-react";
import { createNotification } from "@app/components/notifications";
@@ -46,9 +43,7 @@ import { gatewaysQueryKeys } from "@app/hooks/api/gateways/queries";
import { useGetOrganizationGroups } from "@app/hooks/api/organization/queries";
import {
PamAccountType,
- PamResourcePermissionActions,
TPamMember,
- useDeletePamAccount,
useGetPamAccountById,
useGetPamAccountTemplate,
useListAccountMembers,
@@ -70,11 +65,11 @@ import {
MemberExpiry,
PamDetailSheet
} from "../../components/PamDetailSheet";
+import { PAM_ACCOUNT_TABS, visiblePamTabs } from "../../components/pamResourceTabs";
import { RemoveMemberConfirm } from "../../components/RemoveMemberConfirm";
import { SheetSaveBar } from "../../components/SheetSaveBar";
import { AccountPlatformIcon } from "../../PamAccessPage/components/AccountPlatformIcon";
import { AssignAccessModal, EditMemberTarget } from "./AssignAccessModal";
-import { DeleteAccountModal } from "./DeleteAccountModal";
import { EditAccountForm } from "./EditAccountForm";
type Props = {
@@ -547,7 +542,11 @@ const SettingsTab = ({
{isOverriding && (
<div className="mt-4">
- <GatewayPicker value={{ gatewayId, gatewayPoolId }} onChange={setGateway} />
+ <GatewayPicker
+ value={{ gatewayId, gatewayPoolId }}
+ onChange={setGateway}
+ isRequired
+ />
</div>
)}
</div>
@@ -594,9 +593,7 @@ export const AccountDetailSheet = ({ isOpen, accountId, onOpenChange }: Props) =
const { data: account, isLoading } = useGetPamAccountById(isOpen ? accountId : undefined);
const { tab, setTab } = usePamSheetState("accountId");
const { currentOrg } = useOrganization();
- const deleteAccount = useDeletePamAccount();
- const [isDeleteOpen, setIsDeleteOpen] = useState(false);
const [isFormDirty, setIsFormDirty] = useState(false);
const { map: accountTypeMap } = usePamAccountTypeMap();
@@ -604,51 +601,7 @@ export const AccountDetailSheet = ({ isOpen, accountId, onOpenChange }: Props) =
const typeInfo = accountType ? accountTypeMap[accountType] : undefined;
const { can } = usePamAccountActions(accountId ?? "", isOpen && Boolean(accountId));
- const canManageMembers = can(PamResourcePermissionActions.ManageMembers);
- const canEdit = can(PamResourcePermissionActions.EditAccounts);
- const canDelete = can(PamResourcePermissionActions.DeleteAccounts);
-
- const handleDelete = () => {
- if (!accountId || !accountType) return;
- deleteAccount.mutate(
- { accountId, accountType },
- {
- onSuccess: () => {
- createNotification({ type: "success", text: "Account deleted" });
- setIsDeleteOpen(false);
- onOpenChange(false);
- }
- }
- );
- };
-
- const actions =
- account && (canEdit || canDelete) ? (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <IconButton variant="ghost" size="sm" aria-label="Account actions" className="text-muted">
- <MoreHorizontal className="size-4" />
- </IconButton>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end" onClick={(e) => e.stopPropagation()}>
- {canEdit && (
- <DropdownMenuItem onClick={() => setTab(PamSheetTab.Configuration)}>
- <Settings />
- Configure
- </DropdownMenuItem>
- )}
- {canDelete && (
- <>
- <DropdownMenuSeparator />
- <DropdownMenuItem variant="danger" onClick={() => setIsDeleteOpen(true)}>
- <Trash2 />
- Delete
- </DropdownMenuItem>
- </>
- )}
- </DropdownMenuContent>
- </DropdownMenu>
- ) : undefined;
+ const availableTabs = visiblePamTabs(PAM_ACCOUNT_TABS, can);
const conn = (account?.connectionDetails ?? {}) as Record<string, unknown>;
@@ -691,76 +644,49 @@ export const AccountDetailSheet = ({ isOpen, accountId, onOpenChange }: Props) =
</span>
) : undefined;
- return (
- <>
- <PamDetailSheet
- isOpen={isOpen}
- onOpenChange={onOpenChange}
- isLoading={isLoading}
- accountType={accountType}
- title={account?.name}
- subtitle={folderSubtitle}
- typeBadge={typeInfo?.name}
- icon={
- accountType ? (
- <div className="mb-4 flex size-16 items-center justify-center rounded-lg border border-border bg-container">
- <AccountPlatformIcon accountType={accountType} size={40} />
- </div>
- ) : undefined
- }
- metadata={metadata}
- actions={actions}
- activeTab={tab}
- onTabChange={setTab}
- tabs={
- [
- canManageMembers && {
- value: PamSheetTab.Permissions,
- label: "Permissions",
- icon: <Users className="mr-1.5 size-4" />,
- content:
- accountId && account ? (
- <PermissionsTab
- accountId={accountId}
- folderId={account.folderId}
- folderName={account.folderName}
- />
- ) : null
- },
- canEdit && {
- value: PamSheetTab.Configuration,
- label: "Configuration",
- icon: <Settings className="mr-1.5 size-4" />,
- content: accountId ? (
- <EditAccountForm accountId={accountId} onDirtyChange={setIsFormDirty} />
- ) : null
- },
- canEdit && {
- value: PamSheetTab.Advanced,
- label: "Advanced",
- icon: <Settings2 className="mr-1.5 size-4" />,
- content: accountId ? (
- <SettingsTab accountId={accountId} onDirtyChange={setIsFormDirty} />
- ) : null
- }
- ].filter(Boolean) as {
- value: string;
- label: string;
- icon: JSX.Element;
- content: JSX.Element | null;
- }[]
- }
- isDirty={isFormDirty}
- />
+ const tabContent: Partial<Record<PamSheetTab, ReactNode>> = {
+ [PamSheetTab.Permissions]:
+ accountId && account ? (
+ <PermissionsTab
+ accountId={accountId}
+ folderId={account.folderId}
+ folderName={account.folderName}
+ />
+ ) : null,
+ [PamSheetTab.Configuration]: accountId ? (
+ <EditAccountForm accountId={accountId} onDirtyChange={setIsFormDirty} />
+ ) : null,
+ [PamSheetTab.Advanced]: accountId ? (
+ <SettingsTab accountId={accountId} onDirtyChange={setIsFormDirty} />
+ ) : null
+ };
- <DeleteAccountModal
- isOpen={isDeleteOpen}
- accountName={account?.name ?? ""}
- accountType={accountType}
- isLoading={deleteAccount.isPending}
- onConfirm={handleDelete}
- onOpenChange={setIsDeleteOpen}
- />
- </>
+ return (
+ <PamDetailSheet
+ isOpen={isOpen}
+ onOpenChange={onOpenChange}
+ isLoading={isLoading}
+ accountType={accountType}
+ title={account?.name}
+ subtitle={folderSubtitle}
+ typeBadge={typeInfo?.name}
+ icon={
+ accountType ? (
+ <div className="mb-4 flex size-16 items-center justify-center rounded-lg border border-border bg-container">
+ <AccountPlatformIcon accountType={accountType} size={40} />
+ </div>
+ ) : undefined
+ }
+ metadata={metadata}
+ activeTab={tab}
+ onTabChange={setTab}
+ tabs={availableTabs.map((tabDef) => ({
+ value: tabDef.value,
+ label: tabDef.label,
+ icon: <tabDef.icon className="mr-1.5 size-4" />,
+ content: tabContent[tabDef.value] ?? null
+ }))}
+ isDirty={isFormDirty}
+ />
);
};
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/CreateAccountSheet.tsx b/frontend/src/pages/pam/PamAccountsPage/components/CreateAccountSheet.tsx
index 05d1f9877c..3c27b8f653 100644
--- a/frontend/src/pages/pam/PamAccountsPage/components/CreateAccountSheet.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/CreateAccountSheet.tsx
@@ -1,7 +1,7 @@
import { useEffect, useState } from "react";
import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
-import { AlertTriangle, Search } from "lucide-react";
+import { AlertTriangle, Plus, Search } from "lucide-react";
import { createNotification } from "@app/components/notifications";
import { HighlightText } from "@app/components/v2/HighlightText";
@@ -29,6 +29,7 @@ import {
Select,
SelectContent,
SelectItem,
+ SelectSeparator,
SelectTrigger,
SelectValue
} from "@app/components/v3/generic/Select";
@@ -59,9 +60,12 @@ import {
TAccountFormValues
} from "./accountFormSchema";
import { ConnectionDetailsForm } from "./ConnectionDetailsForm";
+import { CreateFolderModal } from "./CreateFolderModal";
import { CredentialsForm } from "./CredentialsForm";
import { RecordingConnectionPicker } from "./RecordingConnectionPicker";
+const CREATE_FOLDER_VALUE = "__create_folder__";
+
type Props = {
isOpen: boolean;
onOpenChange: (open: boolean) => void;
@@ -74,6 +78,7 @@ export const CreateAccountSheet = ({ isOpen, onOpenChange, defaultFolderId }: Pr
const [step, setStep] = useState<1 | 2>(1);
const [templateSearch, setTemplateSearch] = useState("");
const [confirmDiscardOpen, setConfirmDiscardOpen] = useState(false);
+ const [createFolderOpen, setCreateFolderOpen] = useState(false);
// Gateway/recording are collected inline only when the chosen template doesn't already provide them
const [gateway, setGateway] = useState<{
@@ -275,7 +280,16 @@ export const CreateAccountSheet = ({ isOpen, onOpenChange, defaultFolderId }: Pr
Folder<span className="text-product-pam">*</span>
</FieldLabel>
<FieldContent>
- <Select value={field.value} onValueChange={field.onChange}>
+ <Select
+ value={field.value}
+ onValueChange={(val) => {
+ if (val === CREATE_FOLDER_VALUE) {
+ setCreateFolderOpen(true);
+ return;
+ }
+ field.onChange(val);
+ }}
+ >
<SelectTrigger className="w-full">
<SelectValue placeholder="Select folder" />
</SelectTrigger>
@@ -285,6 +299,13 @@ export const CreateAccountSheet = ({ isOpen, onOpenChange, defaultFolderId }: Pr
{folder.name}
</SelectItem>
))}
+ {folders.length > 0 && <SelectSeparator />}
+ <SelectItem value={CREATE_FOLDER_VALUE}>
+ <span className="flex items-center gap-1.5 text-muted">
+ <Plus className="size-4" />
+ Create folder
+ </span>
+ </SelectItem>
</SelectContent>
</Select>
</FieldContent>
@@ -511,6 +532,12 @@ export const CreateAccountSheet = ({ isOpen, onOpenChange, defaultFolderId }: Pr
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
+
+ <CreateFolderModal
+ isOpen={createFolderOpen}
+ onOpenChange={setCreateFolderOpen}
+ onCreated={(folderId) => setValue("folderId", folderId, { shouldDirty: true })}
+ />
</>
);
};
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/CreateFolderModal.tsx b/frontend/src/pages/pam/PamAccountsPage/components/CreateFolderModal.tsx
index a14118e6c9..7a12801e48 100644
--- a/frontend/src/pages/pam/PamAccountsPage/components/CreateFolderModal.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/CreateFolderModal.tsx
@@ -29,9 +29,10 @@ type FormData = z.infer<typeof formSchema>;
type Props = {
isOpen: boolean;
onOpenChange: (open: boolean) => void;
+ onCreated?: (folderId: string) => void;
};
-export const CreateFolderModal = ({ isOpen, onOpenChange }: Props) => {
+export const CreateFolderModal = ({ isOpen, onOpenChange, onCreated }: Props) => {
const createFolder = useCreatePamFolder();
const {
@@ -48,9 +49,10 @@ export const CreateFolderModal = ({ isOpen, onOpenChange }: Props) => {
createFolder.mutate(
{ name: data.name, description: data.description || undefined },
{
- onSuccess: () => {
+ onSuccess: (folder) => {
createNotification({ type: "success", text: "Folder created" });
reset();
+ onCreated?.(folder.id);
onOpenChange(false);
}
}
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/FolderAccountRows.tsx b/frontend/src/pages/pam/PamAccountsPage/components/FolderAccountRows.tsx
index 93b03d85b1..4e56d33bcb 100644
--- a/frontend/src/pages/pam/PamAccountsPage/components/FolderAccountRows.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/FolderAccountRows.tsx
@@ -10,6 +10,7 @@ import {
useListPamAccountsAdmin,
usePamAccountTypeMap
} from "@app/hooks/api/pam";
+import { PamSheetTab } from "@app/hooks/usePamSheetState";
import { AccountAccessibilityBadge } from "../../components/AccountAccessibilityBadge";
import { AccountPlatformIcon } from "../../PamAccessPage/components/AccountPlatformIcon";
@@ -25,11 +26,9 @@ type Props = {
search: string;
templateId: string;
filterActive: boolean;
- onOpenAccount: (accountId: string) => void;
- onConfigureAccount: (accountId: string) => void;
+ onOpenAccount: (accountId: string, tab?: PamSheetTab) => void;
onDeleteAccount: (target: DeleteTarget) => void;
- onFolderDetails: () => void;
- onFolderConfigure: () => void;
+ onOpenFolder: (tab?: PamSheetTab) => void;
onFolderAddAccount: () => void;
onFolderDelete: () => void;
onResultCount: (folderId: string, count: number) => void;
@@ -43,10 +42,8 @@ export const FolderAccountRows = ({
templateId,
filterActive,
onOpenAccount,
- onConfigureAccount,
onDeleteAccount,
- onFolderDetails,
- onFolderConfigure,
+ onOpenFolder,
onFolderAddAccount,
onFolderDelete,
onResultCount
@@ -105,8 +102,7 @@ export const FolderAccountRows = ({
<div className="flex items-center justify-end gap-1">
<FolderActionsMenu
folder={folder}
- onDetails={onFolderDetails}
- onConfigure={onFolderConfigure}
+ onOpenTab={(tab) => onOpenFolder(tab)}
onAddAccount={onFolderAddAccount}
onDelete={onFolderDelete}
/>
@@ -150,8 +146,7 @@ export const FolderAccountRows = ({
<div className="flex items-center justify-end gap-1">
<AccountActionsMenu
accountId={account.id}
- onDetails={() => onOpenAccount(account.id)}
- onConfigure={() => onConfigureAccount(account.id)}
+ onOpenTab={(tab) => onOpenAccount(account.id, tab)}
onDelete={() =>
onDeleteAccount({
accountId: account.id,
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/FolderActionsMenu.tsx b/frontend/src/pages/pam/PamAccountsPage/components/FolderActionsMenu.tsx
index 1104791cba..adb3b8e355 100644
--- a/frontend/src/pages/pam/PamAccountsPage/components/FolderActionsMenu.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/FolderActionsMenu.tsx
@@ -1,5 +1,5 @@
import { useState } from "react";
-import { Eye, MoreHorizontal, Plus, Settings, Trash2 } from "lucide-react";
+import { MoreHorizontal, Plus, Trash2 } from "lucide-react";
import {
DropdownMenu,
@@ -14,31 +14,26 @@ import {
TPamFolderWithCount,
usePamFolderActions
} from "@app/hooks/api/pam";
+import { PamSheetTab } from "@app/hooks/usePamSheetState";
+
+import { PAM_FOLDER_TABS, visiblePamTabs } from "../../components/pamResourceTabs";
type Props = {
folder: TPamFolderWithCount;
- onDetails: () => void;
- onConfigure: () => void;
+ onOpenTab: (tab: PamSheetTab) => void;
onAddAccount: () => void;
onDelete: () => void;
};
-export const FolderActionsMenu = ({
- folder,
- onDetails,
- onConfigure,
- onAddAccount,
- onDelete
-}: Props) => {
+export const FolderActionsMenu = ({ folder, onOpenTab, onAddAccount, onDelete }: Props) => {
// Defer the permission fetch until the menu is first opened to avoid a request per row
const [hasOpened, setHasOpened] = useState(false);
const { can, isLoading } = usePamFolderActions(folder.id, hasOpened);
- const canRead = can(PamResourcePermissionActions.ReadFolder);
- const canEdit = can(PamResourcePermissionActions.EditFolder);
+ const tabs = visiblePamTabs(PAM_FOLDER_TABS, can);
const canCreateAccounts = can(PamResourcePermissionActions.CreateAccounts);
const canDelete = can(PamResourcePermissionActions.DeleteFolder);
- const hasAnyAction = canRead || canEdit || canCreateAccounts || canDelete;
+ const hasAnyAction = tabs.length > 0 || canCreateAccounts || canDelete;
return (
<DropdownMenu onOpenChange={(open) => open && setHasOpened(true)}>
@@ -58,18 +53,12 @@ export const FolderActionsMenu = ({
{!isLoading && !hasAnyAction && (
<DropdownMenuItem isDisabled>No actions available</DropdownMenuItem>
)}
- {canRead && (
- <DropdownMenuItem onClick={onDetails}>
- <Eye />
- Details
- </DropdownMenuItem>
- )}
- {canEdit && (
- <DropdownMenuItem onClick={onConfigure}>
- <Settings />
- Configure
+ {tabs.map((tab) => (
+ <DropdownMenuItem key={tab.value} onClick={() => onOpenTab(tab.value)}>
+ <tab.icon />
+ {tab.label}
</DropdownMenuItem>
- )}
+ ))}
{canCreateAccounts && (
<DropdownMenuItem onClick={onAddAccount}>
<Plus />
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/FolderDetailSheet.tsx b/frontend/src/pages/pam/PamAccountsPage/components/FolderDetailSheet.tsx
index 77f2c3f60f..b506a76598 100644
--- a/frontend/src/pages/pam/PamAccountsPage/components/FolderDetailSheet.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/FolderDetailSheet.tsx
@@ -1,15 +1,7 @@
import { useEffect, useMemo, useState } from "react";
import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
-import {
- FolderOpen,
- MoreHorizontal,
- Pencil,
- Settings,
- Trash2,
- UserPlus,
- Users
-} from "lucide-react";
+import { FolderOpen, MoreHorizontal, Pencil, Trash2, UserPlus } from "lucide-react";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
@@ -45,7 +37,6 @@ import { Skeleton } from "@app/components/v3/generic/Skeleton";
import { useOrganization, useUser } from "@app/context";
import { useGetOrganizationGroups } from "@app/hooks/api/organization/queries";
import {
- PamResourcePermissionActions,
TPamFolderWithCount,
TPamMember,
useListFolderMembers,
@@ -65,6 +56,7 @@ import {
MemberExpiry,
PamDetailSheet
} from "../../components/PamDetailSheet";
+import { PAM_FOLDER_TABS, visiblePamTabs } from "../../components/pamResourceTabs";
import { RemoveMemberConfirm } from "../../components/RemoveMemberConfirm";
import { SheetSaveBar } from "../../components/SheetSaveBar";
import { AssignAccessModal, EditMemberTarget } from "./AssignAccessModal";
@@ -409,8 +401,7 @@ export const FolderDetailSheet = ({
onOpenChange
}: Props) => {
const { can } = usePamFolderActions(folder?.id ?? "", isOpen && Boolean(folder));
- const canManageMembers = can(PamResourcePermissionActions.ManageMembers);
- const canEdit = can(PamResourcePermissionActions.EditFolder);
+ const availableTabs = visiblePamTabs(PAM_FOLDER_TABS, can);
const [isFormDirty, setIsFormDirty] = useState(false);
@@ -422,25 +413,19 @@ export const FolderDetailSheet = ({
]
: [];
- const tabs = [
- canManageMembers && {
- value: PamSheetTab.Permissions,
- label: "Permissions",
- icon: <Users className="mr-1.5 size-4" />,
- content: folder ? <PermissionsTab folderId={folder.id} /> : null
- },
- canEdit && {
- value: PamSheetTab.Configuration,
- label: "Configuration",
- icon: <Settings className="mr-1.5 size-4" />,
- content: folder ? <GeneralTab folder={folder} onDirtyChange={setIsFormDirty} /> : null
- }
- ].filter(Boolean) as {
- value: string;
- label: string;
- icon: JSX.Element;
- content: JSX.Element | null;
- }[];
+ const tabContent: Partial<Record<PamSheetTab, JSX.Element | null>> = {
+ [PamSheetTab.Permissions]: folder ? <PermissionsTab folderId={folder.id} /> : null,
+ [PamSheetTab.Configuration]: folder ? (
+ <GeneralTab folder={folder} onDirtyChange={setIsFormDirty} />
+ ) : null
+ };
+
+ const tabs = availableTabs.map((tabDef) => ({
+ value: tabDef.value,
+ label: tabDef.label,
+ icon: <tabDef.icon className="mr-1.5 size-4" />,
+ content: tabContent[tabDef.value] ?? null
+ }));
return (
<PamDetailSheet
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/accountFormSchema.ts b/frontend/src/pages/pam/PamAccountsPage/components/accountFormSchema.ts
index 244aff1753..d93cd697c8 100644
--- a/frontend/src/pages/pam/PamAccountsPage/components/accountFormSchema.ts
+++ b/frontend/src/pages/pam/PamAccountsPage/components/accountFormSchema.ts
@@ -20,6 +20,7 @@ export const accountFormSchema = z.object({
export type TAccountFormValues = z.infer<typeof accountFormSchema>;
const defaultForField = (field: TPamFieldDescriptor): unknown => {
+ if (field.defaultValue !== undefined) return field.defaultValue;
if (field.widget === PamFieldWidget.Boolean) return false;
if (field.widget === PamFieldWidget.Select) return field.options?.[0]?.value ?? "";
return "";
diff --git a/frontend/src/pages/pam/PamTemplatesPage/PamTemplatesPage.tsx b/frontend/src/pages/pam/PamTemplatesPage/PamTemplatesPage.tsx
index 237f36d455..34198cb06c 100644
--- a/frontend/src/pages/pam/PamTemplatesPage/PamTemplatesPage.tsx
+++ b/frontend/src/pages/pam/PamTemplatesPage/PamTemplatesPage.tsx
@@ -1,16 +1,7 @@
import { useMemo, useState } from "react";
import { Helmet } from "react-helmet";
import { useTranslation } from "react-i18next";
-import {
- ClipboardList,
- Eye,
- Layers,
- MoreHorizontal,
- Plus,
- Search,
- Settings,
- Trash2
-} from "lucide-react";
+import { ClipboardList, Layers, MoreHorizontal, Plus, Search, Trash2 } from "lucide-react";
import { createNotification } from "@app/components/notifications";
import { PageHeader } from "@app/components/v2";
@@ -55,6 +46,7 @@ import { ProjectType } from "@app/hooks/api/projects/types";
import { PamSheetTab, usePamSheetState } from "@app/hooks/usePamSheetState";
import { usePopUp } from "@app/hooks/usePopUp";
+import { PAM_TEMPLATE_TABS } from "../components/pamResourceTabs";
import { AccountPlatformIcon } from "../PamAccessPage/components/AccountPlatformIcon";
import { CreateTemplateModal } from "./components/CreateTemplateModal";
import { DeleteTemplateModal } from "./components/DeleteTemplateModal";
@@ -103,24 +95,18 @@ const TemplateRow = ({
</IconButton>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" sideOffset={4} onClick={(e) => e.stopPropagation()}>
- <DropdownMenuItem
- onClick={(e) => {
- e.stopPropagation();
- onOpen();
- }}
- >
- <Eye />
- Details
- </DropdownMenuItem>
- <DropdownMenuItem
- onClick={(e) => {
- e.stopPropagation();
- onOpen(PamSheetTab.Configuration);
- }}
- >
- <Settings />
- Configure
- </DropdownMenuItem>
+ {PAM_TEMPLATE_TABS.map((tab) => (
+ <DropdownMenuItem
+ key={tab.value}
+ onClick={(e) => {
+ e.stopPropagation();
+ onOpen(tab.value);
+ }}
+ >
+ <tab.icon />
+ {tab.label}
+ </DropdownMenuItem>
+ ))}
<DropdownMenuSeparator />
<DropdownMenuItem
variant="danger"
diff --git a/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx b/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx
index 2ebebbe521..b5b6016f57 100644
--- a/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx
+++ b/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx
@@ -1,7 +1,6 @@
import { useEffect, useState } from "react";
import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
-import { MoreHorizontal, Settings, Settings2, Trash2 } from "lucide-react";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
@@ -11,11 +10,6 @@ import {
CardDescription,
CardHeader,
CardTitle,
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuSeparator,
- DropdownMenuTrigger,
Field,
FieldContent,
FieldDescription,
@@ -23,7 +17,6 @@ import {
FieldLabel,
FieldTitle,
GatewayPicker,
- IconButton,
Input,
Switch,
TextArea
@@ -32,7 +25,6 @@ import { Skeleton } from "@app/components/v3/generic/Skeleton";
import {
accountTypeRequiresRecording,
PamAccountType,
- useDeletePamAccountTemplate,
useGetPamAccountTemplate,
usePamAccountTypeMap,
useUpdatePamAccountTemplate
@@ -40,10 +32,10 @@ import {
import { PamSheetTab, usePamSheetState } from "@app/hooks/usePamSheetState";
import { formatDetailDate, PamDetailSheet } from "../../components/PamDetailSheet";
+import { PAM_TEMPLATE_TABS } from "../../components/pamResourceTabs";
import { SheetSaveBar } from "../../components/SheetSaveBar";
import { AccountPlatformIcon } from "../../PamAccessPage/components/AccountPlatformIcon";
import { RecordingConnectionPicker } from "../../PamAccountsPage/components/RecordingConnectionPicker";
-import { DeleteTemplateModal } from "./DeleteTemplateModal";
const configSchema = z.object({
name: z.string().min(1, "Name is required").max(64),
@@ -369,27 +361,12 @@ const SettingsTab = ({
export const TemplateDetailSheet = ({ isOpen, templateId, onOpenChange }: Props) => {
const { data: template, isLoading } = useGetPamAccountTemplate(isOpen ? templateId : undefined);
const { tab, setTab } = usePamSheetState("templateId");
- const deleteTemplate = useDeletePamAccountTemplate();
- const [isDeleteOpen, setIsDeleteOpen] = useState(false);
const [isFormDirty, setIsFormDirty] = useState(false);
const { map: accountTypeMap } = usePamAccountTypeMap();
const accountType = template?.type as PamAccountType | undefined;
const typeInfo = accountType ? accountTypeMap[accountType] : undefined;
- const handleDelete = (id: string) => {
- deleteTemplate.mutate(
- { templateId: id },
- {
- onSuccess: () => {
- createNotification({ type: "success", text: "Template deleted" });
- setIsDeleteOpen(false);
- onOpenChange(false);
- }
- }
- );
- };
-
const metadata = template
? [
...(template.description ? [{ label: "Description", value: template.description }] : []),
@@ -401,75 +378,40 @@ export const TemplateDetailSheet = ({ isOpen, templateId, onOpenChange }: Props)
]
: [];
- const actions = template ? (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <IconButton variant="ghost" size="sm" aria-label="Template actions" className="text-muted">
- <MoreHorizontal className="size-4" />
- </IconButton>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end" onClick={(e) => e.stopPropagation()}>
- <DropdownMenuItem onClick={() => setTab(PamSheetTab.Configuration)}>
- <Settings />
- Configure
- </DropdownMenuItem>
- <DropdownMenuSeparator />
- <DropdownMenuItem variant="danger" onClick={() => setIsDeleteOpen(true)}>
- <Trash2 />
- Delete
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- ) : undefined;
+ const tabContent: Partial<Record<PamSheetTab, JSX.Element | null>> = {
+ [PamSheetTab.Advanced]: templateId ? (
+ <SettingsTab templateId={templateId} onDirtyChange={setIsFormDirty} />
+ ) : null,
+ [PamSheetTab.Configuration]: templateId ? (
+ <ConfigurationTab templateId={templateId} onDirtyChange={setIsFormDirty} />
+ ) : null
+ };
return (
- <>
- <PamDetailSheet
- isOpen={isOpen}
- onOpenChange={onOpenChange}
- isLoading={isLoading}
- accountType={accountType}
- title={template?.name}
- typeBadge={typeInfo?.name}
- activeTab={tab}
- onTabChange={setTab}
- actions={actions}
- icon={
- accountType ? (
- <div className="mb-4 flex size-16 items-center justify-center rounded-lg border border-border bg-container">
- <AccountPlatformIcon accountType={accountType} size={40} />
- </div>
- ) : undefined
- }
- metadata={metadata}
- tabs={[
- {
- value: PamSheetTab.Advanced,
- label: "General",
- icon: <Settings2 className="mr-1.5 size-4" />,
- content: templateId ? (
- <SettingsTab templateId={templateId} onDirtyChange={setIsFormDirty} />
- ) : null
- },
- {
- value: PamSheetTab.Configuration,
- label: "Configuration",
- icon: <Settings className="mr-1.5 size-4" />,
- content: templateId ? (
- <ConfigurationTab templateId={templateId} onDirtyChange={setIsFormDirty} />
- ) : null
- }
- ]}
- isDirty={isFormDirty}
- />
-
- <DeleteTemplateModal
- template={template}
- isOpen={isDeleteOpen}
- onOpenChange={setIsDeleteOpen}
- onConfirm={handleDelete}
- isDeleting={deleteTemplate.isPending}
- />
- </>
+ <PamDetailSheet
+ isOpen={isOpen}
+ onOpenChange={onOpenChange}
+ isLoading={isLoading}
+ accountType={accountType}
+ title={template?.name}
+ typeBadge={typeInfo?.name}
+ activeTab={tab}
+ onTabChange={setTab}
+ icon={
+ accountType ? (
+ <div className="mb-4 flex size-16 items-center justify-center rounded-lg border border-border bg-container">
+ <AccountPlatformIcon accountType={accountType} size={40} />
+ </div>
+ ) : undefined
+ }
+ metadata={metadata}
+ tabs={PAM_TEMPLATE_TABS.map((tabDef) => ({
+ value: tabDef.value,
+ label: tabDef.label,
+ icon: <tabDef.icon className="mr-1.5 size-4" />,
+ content: tabContent[tabDef.value] ?? null
+ }))}
+ isDirty={isFormDirty}
+ />
);
};
diff --git a/frontend/src/pages/pam/components/pamResourceTabs.ts b/frontend/src/pages/pam/components/pamResourceTabs.ts
new file mode 100644
index 0000000000..1298586af8
--- /dev/null
+++ b/frontend/src/pages/pam/components/pamResourceTabs.ts
@@ -0,0 +1,57 @@
+import { type LucideIcon, Settings, Settings2, Users } from "lucide-react";
+
+import { PamResourcePermissionActions } from "@app/hooks/api/pam";
+import { PamSheetTab } from "@app/hooks/usePamSheetState";
+
+export type PamResourceTab = {
+ value: PamSheetTab;
+ label: string;
+ icon: LucideIcon;
+ action?: PamResourcePermissionActions;
+};
+
+export const PAM_ACCOUNT_TABS: PamResourceTab[] = [
+ {
+ value: PamSheetTab.Permissions,
+ label: "Permissions",
+ icon: Users,
+ action: PamResourcePermissionActions.ManageMembers
+ },
+ {
+ value: PamSheetTab.Configuration,
+ label: "Configuration",
+ icon: Settings,
+ action: PamResourcePermissionActions.EditAccounts
+ },
+ {
+ value: PamSheetTab.Advanced,
+ label: "Advanced",
+ icon: Settings2,
+ action: PamResourcePermissionActions.EditAccounts
+ }
+];
+
+export const PAM_FOLDER_TABS: PamResourceTab[] = [
+ {
+ value: PamSheetTab.Permissions,
+ label: "Permissions",
+ icon: Users,
+ action: PamResourcePermissionActions.ManageMembers
+ },
+ {
+ value: PamSheetTab.Configuration,
+ label: "Configuration",
+ icon: Settings,
+ action: PamResourcePermissionActions.EditFolder
+ }
+];
+
+export const PAM_TEMPLATE_TABS: PamResourceTab[] = [
+ { value: PamSheetTab.Advanced, label: "General", icon: Settings2 },
+ { value: PamSheetTab.Configuration, label: "Configuration", icon: Settings }
+];
+
+export const visiblePamTabs = (
+ tabs: PamResourceTab[],
+ can: (action: PamResourcePermissionActions) => boolean
+) => tabs.filter((tab) => !tab.action || can(tab.action));