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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
style: spacing in settings module
Brad Barbin4d66900d64a5
diff --git a/apps/erp/app/routes/x+/job+/$jobId.details.tsx b/apps/erp/app/routes/x+/job+/$jobId.details.tsxindex 4505e0863e..f09e71ca2a 100644--- a/apps/erp/app/routes/x+/job+/$jobId.details.tsx+++ b/apps/erp/app/routes/x+/job+/$jobId.details.tsx@@ -126,7 +126,7 @@ export default function JobDetailsRoute() {useRealtime("modelUpload", `modelPath=eq.(${jobData?.job.modelPath})`);return (- <VStack spacing={2} className="p-2 h-full">+ <VStack spacing={4} className="p-4 h-full"><JobNotesid={jobId}title={jobData?.job.jobId ?? ""}diff --git a/apps/erp/app/routes/x+/settings+/company.tsx b/apps/erp/app/routes/x+/settings+/company.tsxindex e60e2bd670..c5269ead6f 100644--- a/apps/erp/app/routes/x+/settings+/company.tsx+++ b/apps/erp/app/routes/x+/settings+/company.tsx@@ -77,7 +77,7 @@ export default function Company() {};return (- <VStack spacing={0} className="p-2 h-full">+ <VStack spacing={4} className="p-4 h-full"><Card><CardHeader><CardTitle>Company</CardTitle>diff --git a/apps/erp/app/routes/x+/settings+/logos.tsx b/apps/erp/app/routes/x+/settings+/logos.tsxindex 4ce44d2264..00745ce73c 100644--- a/apps/erp/app/routes/x+/settings+/logos.tsx+++ b/apps/erp/app/routes/x+/settings+/logos.tsx@@ -71,7 +71,7 @@ export default function LogosRoute() {return (<ScrollArea className="w-full h-[calc(100dvh-49px)]">- <VStack spacing={2} className="p-2 h-full">+ <VStack spacing={4} className="p-4 h-full"><Card><CardHeader><CardTitle className="flex items-center gap-2">diff --git a/apps/erp/app/routes/x+/settings+/purchasing.tsx b/apps/erp/app/routes/x+/settings+/purchasing.tsxindex 8b3b4bd5e6..1623e8b0a6 100644--- a/apps/erp/app/routes/x+/settings+/purchasing.tsx+++ b/apps/erp/app/routes/x+/settings+/purchasing.tsx@@ -91,7 +91,7 @@ export default function Terms() {};return (- <VStack spacing={2} className="p-2 h-full">+ <VStack spacing={4} className="p-4 h-full"><Card><HStack className="justify-between items-start"><CardHeader>diff --git a/apps/erp/app/routes/x+/settings+/sales.tsx b/apps/erp/app/routes/x+/settings+/sales.tsxindex 489202bac0..29db641efe 100644--- a/apps/erp/app/routes/x+/settings+/sales.tsx+++ b/apps/erp/app/routes/x+/settings+/sales.tsx@@ -175,7 +175,7 @@ export default function SalesSettingsRoute() {return (<ScrollArea className="w-full h-[calc(100dvh-49px)]">- <VStack spacing={2} className="p-2 h-full">+ <VStack spacing={4} className="p-4 h-full"><Card><ValidatedFormmethod="post"diff --git a/packages/database/supabase/migrations/20250201181148_rls-refactor.sql b/packages/database/supabase/migrations/20250201181148_rls-refactor.sqlindex 4f4274b418..7bbcd9f9b6 100644--- a/packages/database/supabase/migrations/20250201181148_rls-refactor.sql+++ b/packages/database/supabase/migrations/20250201181148_rls-refactor.sql@@ -94,114 +94,53 @@ BEGINEND;$$;-CREATE OR REPLACE FUNCTION get_companies_with_customer_role() RETURNS text[] LANGUAGE "plpgsql" SECURITY DEFINER-SET- search_path = public AS $$-DECLARE- user_companies text[];-BEGIN- SELECT array_agg("companyId"::text)- INTO user_companies- FROM "userToCompany"- WHERE "userId" = auth.uid()::text AND "role" = 'customer';-- RETURN user_companies;-END;-$$;--CREATE OR REPLACE FUNCTION get_companies_with_customer_permission (permission text) RETURNS text[] LANGUAGE "plpgsql" SECURITY DEFINER+CREATE OR REPLACE FUNCTION get_customer_ids_with_customer_permission (permission text) RETURNS text[] LANGUAGE "plpgsql" SECURITY DEFINERSETsearch_path = public AS $$DECLAREpermission_companies text[];- api_key_company text;- employee_companies text[];+ customer_company_ids text[];+ customer_ids text[];BEGIN- api_key_company := get_company_id_from_api_key();-- -- If API key exists for a company, add it to results- IF api_key_company IS NOT NULL THEN- RETURN ARRAY[api_key_company];- END IF;-- -- Get companies where user is an employee+ -- Get companies where user is a customerSELECT array_agg("companyId"::text)- INTO employee_companies+ INTO customer_company_idsFROM "userToCompany"WHERE "userId" = auth.uid()::text AND "role" = 'customer';-- Get companies from user permissionsSELECT jsonb_to_text_array(COALESCE(permissions->permission, '[]'))INTO permission_companies- FROM public."userPermission"- WHERE id::text = auth.uid()::text;+ FROM public."userPermission" up+ WHERE up.id::text = auth.uid()::text;- -- Filter permission_companies to only include companies where user is employee- IF permission_companies IS NOT NULL AND employee_companies IS NOT NULL THEN+ -- Filter permission_companies to only include companies where user is customer+ IF permission_companies IS NOT NULL AND customer_company_ids IS NOT NULL THENSELECT array_agg(company)INTO permission_companiesFROM unnest(permission_companies) company- WHERE company = ANY(employee_companies);+ WHERE company = ANY(customer_company_ids);ELSEpermission_companies := '{}';END IF;- RETURN permission_companies;-END;-$$;---CREATE OR REPLACE FUNCTION get_companies_with_supplier_role() RETURNS text[] LANGUAGE "plpgsql"-SET- search_path = public AS $$-DECLARE- user_companies text[];-BEGIN- SELECT array_agg("companyId"::text)- INTO user_companies- FROM "userToCompany"- WHERE "userId" = auth.uid()::text AND "role" = 'supplier';-- RETURN user_companies;-END;-$$;-CREATE OR REPLACE FUNCTION get_companies_with_supplier_permission (permission text) RETURNS text[] LANGUAGE "plpgsql" SECURITY DEFINER-SET- search_path = public AS $$-DECLARE- permission_companies text[];- employee_companies text[];-BEGIN-- -- Get companies where user is an employee- SELECT array_agg("companyId"::text)- INTO employee_companies- FROM "userToCompany"- WHERE "userId" = auth.uid()::text AND "role" = 'supplier';-- -- Get companies from user permissions- SELECT jsonb_to_text_array(COALESCE(permissions->permission, '[]'))- INTO permission_companies- FROM public."userPermission"- WHERE id::text = auth.uid()::text;+ -- Get customer IDs where company matches filtered permissions+ SELECT array_agg(c.id::text)+ INTO customer_ids+ FROM "customer" c+ WHERE c."companyId" = ANY(permission_companies);- -- Filter permission_companies to only include companies where user is employee- IF permission_companies IS NOT NULL AND employee_companies IS NOT NULL THEN- SELECT array_agg(company)- INTO permission_companies- FROM unnest(permission_companies) company- WHERE company = ANY(employee_companies);- ELSE- permission_companies := '{}';- END IF;+ -- Get customer IDs from customer accounts+ SELECT array_agg(ca."customerId"::text)+ INTO customer_ids+ FROM "customerAccount" ca+ WHERE ca.id::uuid = auth.uid() AND ca."companyId" = ANY(customer_company_ids);- RETURN permission_companies;+ RETURN customer_ids;END;$$;---- abilityDROP POLICY IF EXISTS "Employees with resources_create can insert abilities" ON "public"."ability";@@ -498,7 +437,7 @@ USING (UNIONSELECT unnest(get_companies_with_employee_permission('purchasing_view'))))- )+ ));CREATE POLICY "INSERT" ON "public"."address"@@ -1031,7 +970,6 @@ USING (SELECT unnest(get_companies_with_employee_permission('purchasing_view')))))-);CREATE POLICY "INSERT" ON "public"."contact"@@ -1044,7 +982,6 @@ WITH CHECK (SELECT unnest(get_companies_with_employee_permission('purchasing_create')))))-);CREATE POLICY "UPDATE" ON "public"."contact"@@ -1057,7 +994,6 @@ USING (SELECT unnest(get_companies_with_employee_permission('purchasing_update')))))-);CREATE POLICY "DELETE" ON "public"."contact"@@ -1213,6 +1149,55 @@ FOR UPDATE USING ());+-- custom fields++DROP POLICY IF EXISTS "Employees can view custom fields" ON "public"."customField";+DROP POLICY IF EXISTS "Employees with settings_create can insert custom fields" ON "public"."customField";+DROP POLICY IF EXISTS "Employees with settings_delete can delete custom fields" ON "public"."customField";+DROP POLICY IF EXISTS "Employees with settings_update can update custom fields" ON "public"."customField";+DROP POLICY IF EXISTS "Requests with an API key can access custom fields" ON "public"."customField";++CREATE POLICY "SELECT" ON "public"."customField"+FOR SELECT USING (+ "companyId" = ANY (+ (+ SELECT+ get_companies_with_any_role()+ )::text[]+ )+);++CREATE POLICY "INSERT" ON "public"."customField"+FOR INSERT WITH CHECK (+ "companyId" = ANY (+ (+ SELECT+ get_companies_with_employee_permission ('settings_create')+ )::text[]+ )+);++CREATE POLICY "UPDATE" ON "public"."customField"+FOR UPDATE USING (+ "companyId" = ANY (+ (+ SELECT+ get_companies_with_employee_permission ('settings_update')+ )::text[]+ )+);++CREATE POLICY "DELETE" ON "public"."customField"+FOR DELETE USING (+ "companyId" = ANY (+ (+ SELECT+ get_companies_with_employee_permission ('settings_delete')+ )::text[]+ )+);++-- customerDROP POLICY IF EXISTS "Customers with sales_update can update their own organization" ON "public"."customer";@@ -1232,6 +1217,12 @@ FOR SELECT USING (get_companies_with_employee_permission ('sales_view'))::text[])+ OR "id" = ANY (+ (+ SELECT+ get_customer_ids_with_customer_permission ('sales_view')+ )::text[]+ ));CREATE POLICY "INSERT" ON "public"."customer"@@ -1265,3 +1256,124 @@ FOR DELETE USING ();+-- customer account++DROP POLICY IF EXISTS "Employees with sales_create can create customer accounts" ON "public"."customerAccount";+DROP POLICY IF EXISTS "Employees with sales_delete can delete customer accounts" ON "public"."customerAccount";+DROP POLICY IF EXISTS "Employees with sales_update can update customer accounts" ON "public"."customerAccount";+DROP POLICY IF EXISTS "Employees with sales_view can view customer accounts" ON "public"."customerAccount";+DROP POLICY IF EXISTS "Requests with an API key can access customer accounts" ON "public"."customerAccount";++CREATE POLICY "SELECT" ON "public"."customerAccount"+FOR SELECT USING (+ "companyId" = ANY (+ (+ SELECT+ get_companies_with_employee_permission ('sales_view')+ )::text[]+ )+ OR "customerId" = ANY (+ (+ SELECT+ get_customer_ids_with_customer_permission ('sales_view')+ )::text[]+ )+);++CREATE POLICY "INSERT" ON "public"."customerAccount"+FOR INSERT WITH CHECK (+ "companyId" = ANY (+ (+ SELECT+ get_companies_with_employee_permission ('sales_create')+ )::text[]+ )+);++CREATE POLICY "UPDATE" ON "public"."customerAccount"+FOR UPDATE USING (+ "companyId" = ANY (+ (+ SELECT+ get_companies_with_employee_permission ('sales_update')+ )::text[]+ )+);++CREATE POLICY "DELETE" ON "public"."customerAccount"+FOR DELETE USING (+ "companyId" = ANY (+ (+ SELECT+ get_companies_with_employee_permission ('sales_delete')+ )::text[]+ )+);++DROP POLICY IF EXISTS "Customers with sales_create can create customer contacts" ON "public"."customerContact";+DROP POLICY IF EXISTS "Customers with sales_update can update their customer contacts" ON "public"."customerContact";+DROP POLICY IF EXISTS "Customers with sales_view can their own customer contacts" ON "public"."customerContact";+DROP POLICY IF EXISTS "Employees with sales_create can create customer contacts" ON "public"."customerContact";+DROP POLICY IF EXISTS "Employees with sales_delete can delete customer contacts" ON "public"."customerContact";+DROP POLICY IF EXISTS "Employees with sales_update can update customer contacts" ON "public"."customerContact";+DROP POLICY IF EXISTS "Employees with sales_view can view customer contact" ON "public"."customerContact";+DROP POLICY IF EXISTS "Requests with an API key can access customer contacts" ON "public"."customerContact";++CREATE POLICY "SELECT" ON "public"."customerContact"+FOR SELECT USING (+ get_company_id_from_foreign_key("customerId", 'customer') = ANY (+ (+ SELECT+ get_companies_with_employee_permission('sales_view')+ )::text[]+ )+ OR "customerId" = ANY (+ (+ SELECT+ get_customer_ids_with_customer_permission('sales_view')+ )::text[]+ )+);++CREATE POLICY "INSERT" ON "public"."customerContact"+FOR INSERT WITH CHECK (+ get_company_id_from_foreign_key("customerId", 'customer') = ANY (+ (+ SELECT+ get_companies_with_employee_permission('sales_create')+ )::text[]+ )+ OR "customerId" = ANY (+ (+ SELECT+ get_customer_ids_with_customer_permission('sales_create')+ )::text[]+ )+);++CREATE POLICY "UPDATE" ON "public"."customerContact"+FOR UPDATE USING (+ get_company_id_from_foreign_key("customerId", 'customer') = ANY (+ (+ SELECT+ get_companies_with_employee_permission('sales_update')+ )::text[]+ )+ OR "customerId" = ANY (+ (+ SELECT+ get_customer_ids_with_customer_permission('sales_update')+ )::text[]+ )+);++CREATE POLICY "DELETE" ON "public"."customerContact"+FOR DELETE USING (+ get_company_id_from_foreign_key("customerId", 'customer') = ANY (+ (+ SELECT+ get_companies_with_employee_permission('sales_delete')+ )::text[]+ )+);+