From 9f6d837a9b055f981795638a872b08540a9ca11b Mon Sep 17 00:00:00 2001 From: Meet Date: Mon, 7 Oct 2024 17:28:32 +0530 Subject: [PATCH 01/25] feat: add migration script to migrate org --- backend/package.json | 1 + backend/scripts/migrate-organization.ts | 55 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 backend/scripts/migrate-organization.ts diff --git a/backend/package.json b/backend/package.json index 314a77306..a51a5b3e4 100644 --- a/backend/package.json +++ b/backend/package.json @@ -52,6 +52,7 @@ "migration:latest": "knex --knexfile ./src/db/knexfile.ts --client pg migrate:latest", "migration:status": "knex --knexfile ./src/db/knexfile.ts --client pg migrate:status", "migration:rollback": "knex --knexfile ./src/db/knexfile.ts migrate:rollback", + "migrate:org": "tsx ./scripts/migrate-organization.ts", "seed:new": "tsx ./scripts/create-seed-file.ts", "seed": "knex --knexfile ./src/db/knexfile.ts --client pg seed:run", "db:reset": "npm run migration:rollback -- --all && npm run migration:latest" diff --git a/backend/scripts/migrate-organization.ts b/backend/scripts/migrate-organization.ts new file mode 100644 index 000000000..88ffbdd25 --- /dev/null +++ b/backend/scripts/migrate-organization.ts @@ -0,0 +1,55 @@ +/* eslint-disable */ +import promptSync from "prompt-sync"; +import { execSync } from "child_process"; +import path from "path"; +import { existsSync } from "fs"; + +const prompt = promptSync({ + sigint: true +}); + +const exportDb = () => { + const exportHost = prompt("Enter your Postgres Host to migrate from: "); + const exportPort = prompt("Enter your Postgres Port to migrate from [Default = 5432]: ") ?? "5432"; + const exportUser = prompt("Enter your Postgres User to migrate from: [Default = infisical]: ") ?? "infisical"; + const exportPassword = prompt("Enter your Postgres Password to migrate from: "); + const exportDatabase = prompt("Enter your Postgres Database to migrate from [Default = infisical]: ") ?? "infisical"; + + execSync( + `PGDATABASE="${exportDatabase}" PGPASSWORD="${exportPassword}" PGHOST="${exportHost}" PGPORT=${exportPort} PGUSER=${exportUser} pg_dump infisical --exclude-table "audit_log*" > ${path.join(__dirname, "../src/db/dump.sql")}`, + { stdio: "inherit" } + ); +} + +const importDbForOrg = () => { + const importHost = prompt("Enter your Postgres Host to migrate to: "); + const importPort = prompt("Enter your Postgres Port to migrate to [Default = 5432]: ") ?? "5432"; + const importUser = prompt("Enter your Postgres User to migrate to: [Default = infisical]: ") ?? "infisical"; + const importPassword = prompt("Enter your Postgres Password to migrate to: "); + const importDatabase = prompt("Enter your Postgres Database to migrate to [Default = infisical]: ") ?? "infisical"; + const orgId = prompt("Enter the organization ID to migrate: "); + + if (!existsSync(path.join(__dirname, "../src/db/dump.sql"))) { + console.log("File not found, please export the database first."); + return; + } + + execSync(`PGDATABASE="${importDatabase}" PGPASSWORD="${importPassword}" PGHOST="${importHost}" PGPORT=${importPort} PGUSER=${importUser} psql -f ${path.join(__dirname, "../src/db/dump.sql")}`); + + execSync(`PGDATABASE="${importDatabase}" PGPASSWORD="${importPassword}" PGHOST="${importHost}" PGPORT=${importPort} PGUSER=${importUser} psql -c "DELETE FROM public.organizations WHERE id != '${orgId}'"`); + + console.log("Organization migrated successfully."); +} + +const main = () => { + const action = prompt("Enter the action to perform\n 1. Export from existing instance.\n 2. Import org to instance.\n \n Action: "); + if (action === "1") { + exportDb(); + } else if (action === "2") { + importDbForOrg(); + } else { + console.log("Invalid action"); + } +} + +main(); \ No newline at end of file From 9d90c35629a00164bd8af68dbeeef5c365ff418c Mon Sep 17 00:00:00 2001 From: = Date: Thu, 17 Oct 2024 20:26:22 +0530 Subject: [PATCH 02/25] feat: added organization kms in org role permission section --- .../Org/RolePage/components/OrgRoleModifySection.utils.ts | 4 +++- .../RolePermissionsSection/RolePermissionsSection.tsx | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/src/views/Org/RolePage/components/OrgRoleModifySection.utils.ts b/frontend/src/views/Org/RolePage/components/OrgRoleModifySection.utils.ts index 027ac1bfe..a91ba4908 100644 --- a/frontend/src/views/Org/RolePage/components/OrgRoleModifySection.utils.ts +++ b/frontend/src/views/Org/RolePage/components/OrgRoleModifySection.utils.ts @@ -1,6 +1,7 @@ /* eslint-disable no-param-reassign */ import { z } from "zod"; +import { OrgPermissionSubjects } from "@app/context"; import { TPermission } from "@app/hooks/api/roles/types"; const generalPermissionSchema = z @@ -46,7 +47,8 @@ export const formSchema = z.object({ ldap: generalPermissionSchema, billing: generalPermissionSchema, identity: generalPermissionSchema, - "organization-admin-console": adminConsolePermissionSchmea + "organization-admin-console": adminConsolePermissionSchmea, + [OrgPermissionSubjects.Kms]: generalPermissionSchema }) .optional() }); diff --git a/frontend/src/views/Org/RolePage/components/RolePermissionsSection/RolePermissionsSection.tsx b/frontend/src/views/Org/RolePage/components/RolePermissionsSection/RolePermissionsSection.tsx index 54bb903c6..98dc1c4c1 100644 --- a/frontend/src/views/Org/RolePage/components/RolePermissionsSection/RolePermissionsSection.tsx +++ b/frontend/src/views/Org/RolePage/components/RolePermissionsSection/RolePermissionsSection.tsx @@ -3,7 +3,7 @@ import { zodResolver } from "@hookform/resolvers/zod"; import { createNotification } from "@app/components/notifications"; import { Button, Table, TableContainer, TBody, Th, THead, Tr } from "@app/components/v2"; -import { useOrganization } from "@app/context"; +import { OrgPermissionSubjects, useOrganization } from "@app/context"; import { useGetOrgRole, useUpdateOrgRole } from "@app/hooks/api"; import { formRolePermission2API, @@ -64,6 +64,10 @@ const SIMPLE_PERMISSION_OPTIONS = [ { title: "SCIM", formName: "scim" + }, + { + title: "External KMS", + formName: OrgPermissionSubjects.Kms } ] as const; From d94b4b2a3c23f5b40e58c2cdb267dc22867883b0 Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Thu, 17 Oct 2024 10:17:23 -0700 Subject: [PATCH 03/25] feat: select all on page for secrets tables and fix multipage select behavior for actions --- .../src/components/v2/Checkbox/Checkbox.tsx | 10 +- .../SecretMainPage/SecretMainPage.store.tsx | 18 +- .../views/SecretMainPage/SecretMainPage.tsx | 367 ++++++++++-------- .../components/ActionBar/ActionBar.tsx | 10 +- .../components/SecretListView/SecretItem.tsx | 4 +- .../SecretListView/SecretListView.tsx | 2 +- .../SecretOverviewPage/SecretOverviewPage.tsx | 133 +++++-- .../SelectionPanel/SelectionPanel.tsx | 32 +- 8 files changed, 356 insertions(+), 220 deletions(-) diff --git a/frontend/src/components/v2/Checkbox/Checkbox.tsx b/frontend/src/components/v2/Checkbox/Checkbox.tsx index 8c7472b26..751a026c3 100644 --- a/frontend/src/components/v2/Checkbox/Checkbox.tsx +++ b/frontend/src/components/v2/Checkbox/Checkbox.tsx @@ -1,5 +1,5 @@ import { ReactNode } from "react"; -import { faCheck } from "@fortawesome/free-solid-svg-icons"; +import { faCheck, faMinus } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import * as CheckboxPrimitive from "@radix-ui/react-checkbox"; import { twMerge } from "tailwind-merge"; @@ -15,6 +15,7 @@ export type CheckboxProps = Omit< isRequired?: boolean; checkIndicatorBg?: string | undefined; isError?: boolean; + isIndeterminate?: boolean; }; export const Checkbox = ({ @@ -26,6 +27,7 @@ export const Checkbox = ({ isRequired, checkIndicatorBg, isError, + isIndeterminate, ...props }: CheckboxProps): JSX.Element => { return ( @@ -45,7 +47,11 @@ export const Checkbox = ({ id={id} > - + {isIndeterminate ? ( + + ) : ( + + )}