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.

fix: refuse blocked operators on kanban complete and batch routes

aashud5f754877909
diff --git a/.ai/specs/2026-10-22-mes-ability-enforcement.md b/.ai/specs/2026-10-22-mes-ability-enforcement.md
index c52ee87da7..4ec2a028b8 100644
--- a/.ai/specs/2026-10-22-mes-ability-enforcement.md
+++ b/.ai/specs/2026-10-22-mes-ability-enforcement.md
@@ -77,7 +77,7 @@ The same migration drops and re-creates the `processes` view, so `p.*` picks up
1. `getAbilityShortfall` returns what the operator lacks, or null. One embedded read gets the process and its ability. Then the qualification and the granting training are read in parallel. A shortfall carries `policy`, `processName`, `expiredOn` and `trainingName`.
2. `abilityBlockRefusal` is the only check the routes call. It builds the English flash text when the policy is `Block`.
-3. `abilityBlockRefusal` returns the refusal text when the policy is `Block`. These routes call it before they write: `event` (Start), `start.$operationId`, `complete`, `finish`, `scrap`, `rework`, `record`, `record.$id.delete`, `issue`, `issue-tracked-entity` (single operation), `unconsume`, `entity+/…scrap`, and the inspection `sample`, `measurement`, `disposition` and `complete-passed` routes.
+3. `abilityBlockRefusal` returns the refusal text when the policy is `Block`. These routes call it before they write: `event` (Start), `start.$operationId`, `end.$operationId` (kanban complete scan), `batch.$batchId.complete` and `batch.$batchId.record` (one member is checked, because every member runs the batch's process), `complete`, `finish`, `scrap`, `rework`, `record`, `record.$id.delete`, `issue`, `issue-tracked-entity` (single operation), `unconsume`, `entity+/…scrap`, and the inspection `sample`, `measurement`, `disposition` and `complete-passed` routes.
4. The operation view disables the same actions when the policy is `Block`. Pause, Maintenance, Quality Issue, Instructions and Chat stay enabled. Not guarded: `steps.complete-all` (a manager override), `steps.inspection` (an automatic sync) and a batch pick.
5. `x+/event.tsx` redirects a full-page POST (`Sec-Fetch-Mode: navigate`, a press before the page hydrates) back to the referring page, keeping the flash.
6. The three loaders (`operation`, `assembly`, `inspection`) pass the shortfall to the view as `abilityWarning`. The assembly and inspection views disable the same work, and skip their timer auto-start, when the policy is `Block`.
diff --git a/.claude/rules/mes-job-operation-ui.md b/.claude/rules/mes-job-operation-ui.md
index 1b91ac6af3..3af5e7bede 100644
--- a/.claude/rules/mes-job-operation-ui.md
+++ b/.claude/rules/mes-job-operation-ui.md
@@ -83,7 +83,9 @@ banner.
finish, step records, material issue, inspection verdicts) and skips timer
auto-start; pausing a running timer stays enabled. Every write route calls
`abilityBlockRefusal` before it writes: `event` (Start only), `start.$operationId`,
- `complete`, `finish`, `scrap`, `rework`, `record`, `record.$id.delete`, `issue`,
+ `end.$operationId` (the kanban complete scan), `batch.$batchId.complete`,
+ `batch.$batchId.record` (one member checked: every member runs the batch's one
+ process), `complete`, `finish`, `scrap`, `rework`, `record`, `record.$id.delete`, `issue`,
`issue-tracked-entity` (single operation), `unconsume`, `entity+/…scrap`, and the
inspection `sample`, `measurement`, `disposition` and `complete-passed` routes.
Not gated: `steps.complete-all` (a manager override), `steps.inspection` (an
diff --git a/apps/mes/app/routes/x+/batch.$batchId.complete.tsx b/apps/mes/app/routes/x+/batch.$batchId.complete.tsx
index bd00bcd91a..d566d4069d 100644
--- a/apps/mes/app/routes/x+/batch.$batchId.complete.tsx
+++ b/apps/mes/app/routes/x+/batch.$batchId.complete.tsx
@@ -13,6 +13,7 @@ import { data } from "react-router";
import { erpPosting } from "~/services/erp";
import { completeJobOperationBatchValidator } from "~/services/models";
import {
+ abilityBlockRefusal,
getJobOperationBatch,
type JobOperationBatch
} from "~/services/operations.service";
@@ -118,6 +119,20 @@ export async function action({ request, params }: ActionFunctionArgs) {
);
}
+ // Every member runs the batch's one process, so one member's check covers
+ // the whole batch.
+ const firstMemberId = validation.data.members[0]?.jobOperationId;
+ const abilityRefusal = firstMemberId
+ ? await abilityBlockRefusal(serviceRole, {
+ operationId: firstMemberId,
+ employeeId: userId,
+ companyId
+ })
+ : null;
+ if (abilityRefusal) {
+ return data({}, await flash(request, error(null, abilityRefusal)));
+ }
+
const plannedLotNumber = planned.data.mergeOutput
? planned.data.outputLotNumber
: null;
diff --git a/apps/mes/app/routes/x+/batch.$batchId.record.tsx b/apps/mes/app/routes/x+/batch.$batchId.record.tsx
index d278348517..df750efc70 100644
--- a/apps/mes/app/routes/x+/batch.$batchId.record.tsx
+++ b/apps/mes/app/routes/x+/batch.$batchId.record.tsx
@@ -13,6 +13,7 @@ import type { ActionFunctionArgs } from "react-router";
import { data } from "react-router";
import { batchStepRecordsValidator } from "~/services/models";
import {
+ abilityBlockRefusal,
backflushUntrackedMaterialsOnStepRecord,
insertBatchStepRecords
} from "~/services/operations.service";
@@ -35,6 +36,27 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
const serviceRole = await getCarbonServiceRole();
+
+ // Every member runs the batch's one process, so one member's check covers
+ // the whole batch.
+ const member = await serviceRole
+ .from("jobOperation")
+ .select("id")
+ .eq("jobOperationBatchId", batchId)
+ .eq("companyId", companyId)
+ .limit(1)
+ .maybeSingle();
+ const abilityRefusal = member.data
+ ? await abilityBlockRefusal(serviceRole, {
+ operationId: member.data.id,
+ employeeId: userId,
+ companyId
+ })
+ : null;
+ if (abilityRefusal) {
+ return data({}, await flash(request, error(null, abilityRefusal)));
+ }
+
const inserted = await insertBatchStepRecords(serviceRole, {
batchId,
companyId,
diff --git a/apps/mes/app/routes/x+/end.$operationId.tsx b/apps/mes/app/routes/x+/end.$operationId.tsx
index 37929d950d..b12206606a 100644
--- a/apps/mes/app/routes/x+/end.$operationId.tsx
+++ b/apps/mes/app/routes/x+/end.$operationId.tsx
@@ -13,6 +13,7 @@ import { redirect } from "@carbon/utils";
import type { LoaderFunctionArgs } from "react-router";
import { erpPosting } from "~/services/erp";
import {
+ abilityBlockRefusal,
finishJobOperation,
getNextIncompleteSerialEntity,
getTrackedEntitiesByMakeMethodId,
@@ -79,6 +80,18 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
})
);
}
+ const abilityRefusal = await abilityBlockRefusal(serviceRole, {
+ operationId,
+ employeeId: userId,
+ companyId
+ });
+ if (abilityRefusal) {
+ return redirect(
+ path.to.operation(operationId),
+ await flash(request, error(null, abilityRefusal))
+ );
+ }
+
const completeAll = jobOperation.data?.completeAllOnScan ?? false;
const [jobMakeMethod] = await Promise.all([
diff --git a/docs/content/docs/reference/work-centers.mdx b/docs/content/docs/reference/work-centers.mdx
index d65172bcce..0bdf9f2943 100644
--- a/docs/content/docs/reference/work-centers.mdx
+++ b/docs/content/docs/reference/work-centers.mdx
@@ -27,13 +27,13 @@ A **process** is a capability a work center can perform; work centers and proces
### Requiring an ability
-Turn on **"Requires Ability"** on a process and only qualified people can be scheduled for it and run it on the shop floor. The process has one ability of its own, with the same name; the toggle's description names it. People get it by completing a [training](/docs/reference/training#training-can-grant-an-ability) that grants it, or a manager adds it on their Abilities page.
+Turn on **"Requires Ability"** on a process and only qualified people can be scheduled for it. What the shop floor does with someone who isn't qualified depends on the setting below. The process has one ability of its own, with the same name; the toggle's description names it. People get it by completing a [training](/docs/reference/training#training-can-grant-an-ability) that grants it, or a manager adds it on their Abilities page.
While the toggle is on, **"If an operator isn't qualified"** decides what the shop floor does when someone without the ability opens an operation of this process:
<FieldTable>
<Field name="Warn">The operator sees a warning on the operation and can still work. This is the default.</Field>
- <Field name="Block">The operator sees why they can't work on it, and every production action is refused: starting the timer, logging completed, scrap or rework, marking it done, recording steps, issuing material, and inspection verdicts. Pausing a timer that is already running, maintenance and quality issues stay available.</Field>
+ <Field name="Block">The operator sees why they can't work on it, and these production actions are refused: starting the timer, logging completed, scrap or rework, marking it done, recording steps, issuing material, and inspection verdicts. Pausing a timer that is already running, maintenance and quality issues stay available. Two actions are not blocked: a manager's **"Complete all steps"** override, and picking material for a whole batch at once.</Field>
</FieldTable>
See [running an operation without the ability](/docs/reference/mes#when-you-dont-have-the-required-ability) for what the operator sees.