Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat: add tables for external links

Brad Barbin6196c9fb3700
diff --git a/apps/carbon/app/components/Layout/Navigation/GroupedContentSidebar.tsx b/apps/carbon/app/components/Layout/Navigation/GroupedContentSidebar.tsx
index 2e1a2e4221..d018053350 100644
--- a/apps/carbon/app/components/Layout/Navigation/GroupedContentSidebar.tsx
+++ b/apps/carbon/app/components/Layout/Navigation/GroupedContentSidebar.tsx
@@ -6,7 +6,7 @@ import { CollapsibleSidebar } from "./CollapsibleSidebar";
const GroupedContentSidebar = ({
groups,
- width,
+ width = 200,
exactMatch = false,
}: {
groups: RouteGroup[];
diff --git a/apps/carbon/app/modules/settings/ui/useSettingsSubmodules.tsx b/apps/carbon/app/modules/settings/ui/useSettingsSubmodules.tsx
index 487097b2c4..768e4ee0b1 100644
--- a/apps/carbon/app/modules/settings/ui/useSettingsSubmodules.tsx
+++ b/apps/carbon/app/modules/settings/ui/useSettingsSubmodules.tsx
@@ -1,4 +1,10 @@
-import { LuFactory, LuFileText, LuSheet, LuWorkflow } from "react-icons/lu";
+import {
+ LuCrown,
+ LuFactory,
+ LuFileText,
+ LuSheet,
+ LuWorkflow,
+} from "react-icons/lu";
import { MdOutlineDashboardCustomize } from "react-icons/md";
import { usePermissions } from "~/hooks";
import type { AuthenticatedRouteGroup } from "~/types";
@@ -14,6 +20,12 @@ const settingsRoutes: AuthenticatedRouteGroup[] = [
role: "employee",
icon: <LuFactory />,
},
+ {
+ name: "Sales",
+ to: path.to.salesSettings,
+ role: "employee",
+ icon: <LuCrown />,
+ },
{
name: "Standard Terms",
to: path.to.terms,
diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.ts
index 345c2c6af8..a6be847766 100644
--- a/apps/carbon/app/utils/path.ts
+++ b/apps/carbon/app/utils/path.ts
@@ -739,6 +739,7 @@ export const path = {
salesRfqRoot: `${x}/sales-rfq`,
salesRfqStatus: (id: string) => generatePath(`${x}/sales-rfq/${id}/status`),
salesRfqs: `${x}/sales/rfqs`,
+ salesSettings: `${x}/settings/sales`,
schedule: `${x}/schedule`,
scheduleOperationUpdate: `${x}/schedule/operation/update`,
scrapReason: (id: string) =>
diff --git a/packages/database/supabase/migrations/20241030005037_external-links.sql b/packages/database/supabase/migrations/20241030005037_external-links.sql
new file mode 100644
index 0000000000..137a394b60
--- /dev/null
+++ b/packages/database/supabase/migrations/20241030005037_external-links.sql
@@ -0,0 +1,85 @@
+ALTER TABLE "company" ADD COLUMN "digitalQuoteEnabled" BOOLEAN NOT NULL DEFAULT FALSE;
+
+UPDATE "company" SET "digitalQuoteEnabled" = TRUE;
+
+CREATE TYPE "externalLinkDocumentType" AS ENUM ('Quote');
+
+CREATE TABLE "externalLink" (
+ "id" uuid NOT NULL DEFAULT uuid_generate_v4(),
+ "documentType" "externalLinkDocumentType" NOT NULL,
+ "documentId" TEXT NOT NULL,
+ "customerId" TEXT,
+ "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
+ "expiresAt" TIMESTAMP WITH TIME ZONE,
+ "companyId" TEXT NOT NULL,
+ CONSTRAINT "externalLinks_pkey" PRIMARY KEY ("id"),
+ CONSTRAINT "externalLinks_customerId_fkey" FOREIGN KEY ("customerId") REFERENCES "customer"("id"),
+ CONSTRAINT "externalLinks_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id")
+);
+
+ALTER TABLE "externalLink" ENABLE ROW LEVEL SECURITY;
+
+CREATE POLICY "Employees with sales_view can view sales-related external links" ON "externalLink"
+ FOR SELECT
+ USING (
+ "documentType" = 'Quote' AND
+ has_role('employee', "companyId") AND
+ has_company_permission('sales_view', "companyId")
+ );
+
+CREATE POLICY "Employees with sales_create can insert sales-related external links" ON "externalLink"
+ FOR INSERT
+ WITH CHECK (
+ "documentType" = 'Quote' AND
+ has_role('employee', "companyId") AND
+ has_company_permission('sales_create', "companyId")
+ );
+
+CREATE POLICY "Employees with sales_update can update sales-related external links" ON "externalLink"
+ FOR UPDATE
+ USING (
+ "documentType" = 'Quote' AND
+ has_role('employee', "companyId") AND
+ has_company_permission('sales_update', "companyId")
+ );
+
+CREATE POLICY "Employees with sales_delete can delete sales-related external links" ON "externalLink"
+ FOR DELETE
+ USING (
+ "documentType" = 'Quote' AND
+ has_role('employee', "companyId") AND
+ has_company_permission('sales_delete', "companyId")
+ );
+
+CREATE TABLE "externalLinkMessage" (
+ "id" uuid NOT NULL DEFAULT uuid_generate_v4(),
+ "externalLinkId" uuid NOT NULL,
+ "message" TEXT NOT NULL,
+ "createdBy" TEXT,
+ "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
+ "companyId" TEXT NOT NULL,
+ CONSTRAINT "externalLinkMessages_pkey" PRIMARY KEY ("id"),
+ CONSTRAINT "externalLinkMessages_externalLinkId_fkey" FOREIGN KEY ("externalLinkId") REFERENCES "externalLink"("id"),
+ CONSTRAINT "externalLinkMessages_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id"),
+ CONSTRAINT "externalLinkMessages_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id")
+);
+
+ALTER TABLE "externalLinkMessage" ENABLE ROW LEVEL SECURITY;
+
+CREATE POLICY "Employees can view external link messages" ON "externalLinkMessage"
+ FOR SELECT
+ USING (
+ has_role('employee', "companyId")
+ );
+
+CREATE POLICY "Employees can insert external link messages" ON "externalLinkMessage"
+ FOR INSERT
+ WITH CHECK (
+ has_role('employee', "companyId")
+ );
+
+CREATE POLICY "Employees can delete external link messages" ON "externalLinkMessage"
+ FOR DELETE
+ USING (
+ has_role('employee', "companyId")
+ );