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:approval reads fail closed instead of reading as nothing pending
aashuc0b85077ee97
diff --git a/packages/ee/src/approvals/document.server.ts b/packages/ee/src/approvals/document.server.tsindex 0e29b470f5..2d7eb5ae90 100644--- a/packages/ee/src/approvals/document.server.ts+++ b/packages/ee/src/approvals/document.server.ts@@ -4,6 +4,7 @@import type { Database } from "@carbon/database";import type { Kysely, KyselyDatabase } from "@carbon/database/client";+import { getLogger } from "@carbon/logger";import { datetime } from "@carbon/utils";import type { SupabaseClient } from "@supabase/supabase-js";import { toDocumentApprovalState, withdrawalVerdict } from "./document";@@ -22,6 +23,8 @@ import type {DocumentApprovalState} from "./types";+const logger = getLogger("ee", "approvals");+// The document-level approval lifecycle (state, open, cancel, decide), shared by// every approval document type. Each takes the service role: approvalRequest has// no RLS policies. Notifications stay with the caller, because @carbon/ee must@@ -60,6 +63,16 @@ export async function getDocumentApprovalState()]);+ // A failed read must not look like "nothing pending": the page would hide+ // Pending Approval and offer the advance form.+ if (latest.error) {+ logger.error("Failed to read the latest approval request", {+ ...doc,+ error: latest.error+ });+ throw new Error("Failed to read approval requests");+ }+return toDocumentApprovalState(latest.data, { isRequired, canApprove });}diff --git a/packages/ee/src/approvals/service.ts b/packages/ee/src/approvals/service.tsindex f4b0f73951..a3f2c63c1c 100644--- a/packages/ee/src/approvals/service.ts+++ b/packages/ee/src/approvals/service.ts@@ -814,7 +814,17 @@ export async function hasPendingApproval(.eq("status", "Pending").limit(1);- return (result.data?.length ?? 0) > 0;+ // Fail closed: "false" would unlock edits and skip the approval gate.+ if (result.error) {+ logger.error("Failed to check for a pending approval request", {+ documentType,+ documentId,+ error: result.error+ });+ throw new Error("Failed to read approval requests");+ }++ return result.data.length > 0;}export async function isApprovalRequired(