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
fix: training assignees picked directly now show on the assignment
aashu699d31dc2862
diff --git a/packages/database/supabase/migrations/20261026114317_users-for-groups-identity-groups.sql b/packages/database/supabase/migrations/20261026114317_users-for-groups-identity-groups.sqlnew file mode 100644index 0000000000..f1798d9c42--- /dev/null+++ b/packages/database/supabase/migrations/20261026114317_users-for-groups-identity-groups.sql@@ -0,0 +1,44 @@+-- A person picked directly on a training assignment is stored as their own+-- identity group, which has no companyId. The API guard kept only groups of+-- the caller's companies, so it dropped every identity group and the+-- assignment listed nobody. Keep an identity group when its user belongs to+-- one of the caller's companies.+CREATE OR REPLACE FUNCTION public.users_for_groups(groups text[])+ RETURNS jsonb+ LANGUAGE plpgsql+ SECURITY DEFINER+ SET search_path TO 'public'+AS $function$+ DECLARE+ retval jsonb;+ caller_companies text[];+ BEGIN+ IF current_setting('role', true) IN ('anon', 'authenticated') THEN+ caller_companies := get_companies_with_employee_role();+ groups := ARRAY(+ SELECT g.id FROM "group" g+ WHERE g.id = ANY (groups)+ AND (+ g."companyId" = ANY (caller_companies)+ OR (+ g."isIdentityGroup"+ AND EXISTS (+ SELECT 1 FROM "userToCompany" uc+ WHERE uc."userId" = g.id+ AND uc."companyId" = ANY (caller_companies)+ )+ )+ )+ );+ END IF;++ WITH RECURSIVE "usersForGroups" AS (+ SELECT "groupId", "memberGroupId", "memberUserId" FROM "membership"+ WHERE "groupId" = ANY(groups)+ UNION+ SELECT g1."groupId", g1."memberGroupId", g1."memberUserId" FROM "membership" g1+ INNER JOIN "usersForGroups" g2 ON g2."memberGroupId" = g1."groupId"+ ) SELECT coalesce(jsonb_agg("memberUserId"), '[]') AS groups INTO retval FROM "usersForGroups" WHERE "memberUserId" IS NOT NULL;+ RETURN retval;+ END;+$function$;diff --git a/packages/database/supabase/tests/rpc-privileges.test.sql b/packages/database/supabase/tests/rpc-privileges.test.sqlindex e15ad6ecb8..6e2b63942f 100644--- a/packages/database/supabase/tests/rpc-privileges.test.sql+++ b/packages/database/supabase/tests/rpc-privileges.test.sql@@ -170,6 +170,15 @@ BEGINRAISE EXCEPTION 'FAIL: an employee of A listed the members of a group in B';END IF;+ -- A person picked directly is their own identity group, which has no company.+ IF users_for_groups(ARRAY[current_setting('test.user_a')]) <> jsonb_build_array(current_setting('test.user_a')) THEN+ RAISE EXCEPTION 'FAIL: an employee of A could not list the identity group of a user in A';+ END IF;++ IF users_for_groups(ARRAY[current_setting('test.user_b')]) <> '[]'::jsonb THEN+ RAISE EXCEPTION 'FAIL: an employee of A listed the identity group of a user only in B';+ END IF;+-- An interceptor called directly with a forged payload runs under RLS.BEGINPERFORM sync_create_customer_type_group('customerType', 'INSERT',