From 8fe15c8bc6de7dce16217d9cfe1d2a31829e0603 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 01:31:50 +0000 Subject: [PATCH 1/4] fix(console): the record edit dialog opens locked with the closed sentence on a closed record (ADR-0162) AppContent reads recordClosedByLock from the hook the dialog already uses and hands ModalForm lockedBy 'closed' (closed wins over an approval hold, as on the record page). The lock rides the existing chain: RecordFieldAccessScope refuses the row with 'record-closed', fieldWriteGate maps it to the 'closed' affordance (no Save), and the notice says the record page's closed sentence (detail.lockedClosedTooltip). Claude-Session: https://claude.ai/code/session_01WGufzhKEbEnW8pwZRgK2gJ Co-authored-by: Claude --- .../app-shell/src/console/AppContent.tsx | 13 +++++- ...tent.editDialogApprovalLock-27138.test.tsx | 41 ++++++++++++++++++- .../src/RecordFieldAccessScope.tsx | 24 +++++++---- ...ieldAccessScope.rowWritable-27138.test.tsx | 16 +++++++- ui/packages/plugin-form/src/ModalForm.tsx | 7 ++-- .../src/closedAffordanceNotice.tsx | 13 ++++-- ui/packages/plugin-form/src/fieldWriteGate.ts | 10 +++-- ...cordFieldAccess.rowWritable-27138.test.tsx | 22 ++++++++++ .../plugin-form/src/recordFieldAccess.tsx | 7 ++-- 9 files changed, 126 insertions(+), 27 deletions(-) diff --git a/ui/packages/app-shell/src/console/AppContent.tsx b/ui/packages/app-shell/src/console/AppContent.tsx index f31819acb4b..2af91edd711 100644 --- a/ui/packages/app-shell/src/console/AppContent.tsx +++ b/ui/packages/app-shell/src/console/AppContent.tsx @@ -16,7 +16,7 @@ import { ConsoleFormOwnerLine } from '../views/consoleFormOwnerLine.js'; import { Empty, EmptyTitle, EmptyDescription, Button, DataErrorState, cn } from '@object-ui/components'; import { toast } from 'sonner'; import { useActionRunner, useGlobalUndo, useMutationInvalidationBridge, notifyDataChanged, FilterScopeProvider, resolveApprovalLock, claimAnswerWarnings, toastRecordSave, type AnswerWarningClaim, type AnsweredLoadFailure, type RecordSaveFeedback } from '@object-ui/react'; -import { useRecordApprovals, openApprovalOf } from '../hooks/useRecordApprovals.js'; +import { useRecordApprovals, openApprovalOf, recordClosedByLock } from '../hooks/useRecordApprovals.js'; import { useObjectTranslation, useObjectLabel, recordSaveMessage as buildRecordSaveMessage } from '@object-ui/i18n'; import type { AppAccessVerdict, ConnectionState } from '@object-ui/data-objectstack'; import { useAuth, useWorkspaceAdminStatus } from '@object-ui/auth'; @@ -1079,6 +1079,15 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps = openApproval: openApprovalOf(formApprovals), recordStatus: undefined, }).locked; + // objectstack#38997 (ADR-0162) — a CLOSED record (a closed state of its + // object holds, its own or its master's), from the same hook's data lock + // read (`recordClosedByLock`, the record page's rule), so the dialog asks + // nothing of its own: on a record page it joins the page's payload answer. + // It opens read-only with the record page's closed sentence; a record both + // closed and held reads as closed, as on the record page. + const formLockedBy: 'closed' | 'approval' | undefined = recordClosedByLock(formApprovals) + ? 'closed' + : formApprovalLocked ? 'approval' : undefined; // objectstack-ai/objectstack#26172 — a record save names the record it wrote // (`ux-conventions.write-feedback`): `Task "Quarterly review" created`. The @@ -1774,7 +1783,7 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps = ({ import { AppContent } from '../AppContent'; import { __resetRecordApprovalsStore } from '../../hooks/useRecordApprovals'; -type Approvals = { requests: any[]; lock: boolean }; +type Approvals = { requests: any[]; lock: boolean; closed?: boolean }; /** What the approvals routes answer; set per test. */ let served: Approvals = { requests: [], lock: false }; @@ -143,7 +148,12 @@ const fetchSpy = vi.fn(async (input: RequestInfo | URL) => { // objectstack#37773 — the dialog's lock is the data layer's one lock read // (`/data/:object/:id/lock`), answering `lockReason: 'approval'` here. const body = /\/data\/[^/]+\/[^/]+\/lock$/.test(url) - ? { success: true, data: served.lock ? { locked: true, lockSource: 'record', lockReason: 'approval' } : { locked: false } } + ? { + success: true, + data: served.closed + ? { locked: true, lockSource: 'record', lockReason: 'closed_state' } + : served.lock ? { locked: true, lockSource: 'record', lockReason: 'approval' } : { locked: false }, + } : url.includes('/approvals/records/') ? { success: true, data: { locked: served.lock } } : url.includes('/approvals/requests?') @@ -238,3 +248,30 @@ describe('[#27138] the console edit dialog reads the approvals record lock', () expect(approvalReads(fetchSpy)).toEqual([]); }); }); + +describe('[#38997] the console edit dialog reads the closed lock (ADR-0162)', () => { + it.each([ + ['a closed record', { requests: [], lock: false, closed: true }], + ['a closed record an approval also holds (closed wins)', { requests: [PENDING], lock: true, closed: true }], + ])('%s: the dialog is handed the closed lock', async (_label, approvals) => { + serveApprovals(approvals); + openAt('/apps/crm/crm_contract?form=r1'); + await waitFor(() => expect(lastModal()?.schema?.mode).toBe('edit')); + await waitFor(() => expect(lastModal().lockedBy).toBe('closed')); + }); + + it('a closed record adds no read: the same three lock-ish reads as an open one', async () => { + const fetchSpy = serveApprovals({ requests: [], lock: false, closed: true }); + openAt('/apps/crm/crm_contract?form=r1'); + await waitFor(() => expect(lastModal()?.lockedBy).toBe('closed')); + await new Promise((r) => setTimeout(r, 20)); + const lockishReads = fetchSpy.mock.calls + .map(([u]) => new URL(String(u), 'http://x').pathname) + .filter((u) => u.includes('/approvals/') || u.endsWith('/lock')); + expect(lockishReads.sort()).toEqual([ + '/api/v1/approvals/records/crm_contract/r1/lock', + '/api/v1/approvals/requests', + '/api/v1/data/crm_contract/r1/lock', + ]); + }); +}); diff --git a/ui/packages/permissions/src/RecordFieldAccessScope.tsx b/ui/packages/permissions/src/RecordFieldAccessScope.tsx index 948fb29ceea..41a8182c0de 100644 --- a/ui/packages/permissions/src/RecordFieldAccessScope.tsx +++ b/ui/packages/permissions/src/RecordFieldAccessScope.tsx @@ -35,9 +35,12 @@ export interface RecordFieldAccessAnswer { * * - `record-not-writable` — the projection answered `writable: false`; * - `record-locked-by-approval` — the host reported a pending approval that - * locks the record (`lockedBy: 'approval'`). + * locks the record (`lockedBy: 'approval'`); + * - `record-closed` — the host reported the record closed: one of its + * object's closed states holds, its own or its master's (`lockedBy: + * 'closed'`, ADR-0162). */ -type RecordWriteRefusal = 'record-not-writable' | 'record-locked-by-approval'; +type RecordWriteRefusal = 'record-not-writable' | 'record-locked-by-approval' | 'record-closed'; export interface RecordFieldAccessScopeProps { /** The object the record belongs to. Matched case-insensitively, as `MePermissionsProvider` matches object names. */ @@ -62,11 +65,14 @@ export interface RecordFieldAccessScopeProps { * A lock on the record that the projection does not judge and the host * reads from its own door: `'approval'` while a pending approval locks the * record (the approvals service's record lock, answered to every reader). - * The row then answers as not writable, exactly as `writable: false` does, - * without waiting for the projection. The host passes the verdict it already - * draws its own lock from; the scope never re-derives it. + * `'closed'` while the record is closed (ADR-0162: a closed state of its + * object holds, its own or its master's, as the data layer's lock read + * answers it). The row then answers as not writable, exactly as + * `writable: false` does, without waiting for the projection. The host + * passes the verdict it already draws its own lock from, and decides which + * one when both hold; the scope never re-derives it. */ - lockedBy?: 'approval'; + lockedBy?: 'approval' | 'closed'; children: ReactNode; } @@ -168,7 +174,8 @@ function scoped( const refusal: RecordWriteRefusal | undefined = answer?.writable === false ? 'record-not-writable' : lockedBy === 'approval' ? 'record-locked-by-approval' - : undefined; + : lockedBy === 'closed' ? 'record-closed' + : undefined; const result = refusal ? refusedRow(value, objKey, recordId, refusal) : value; SCOPE_OF.set(result, key); byAnswer.set(answerKey, result); @@ -238,7 +245,8 @@ function refusedRow( * why. `lockedBy: 'approval'` answers the same way with the reason * `record-locked-by-approval`: the approvals record lock is judged on the * values a save sends, so the projection leaves it out, and the host passes - * the lock it already reads. `writable: true` or an absent `writable` changes + * the lock it already reads. `lockedBy: 'closed'` does too, with the reason + * `record-closed` (ADR-0162's closed-state lock, also outside the projection). `writable: true` or an absent `writable` changes * nothing. Until the answer arrives the row-blind answer stands for the row, * as it does for the fields. * diff --git a/ui/packages/permissions/src/__tests__/RecordFieldAccessScope.rowWritable-27138.test.tsx b/ui/packages/permissions/src/__tests__/RecordFieldAccessScope.rowWritable-27138.test.tsx index ec6c2064cc6..8426a4fc513 100644 --- a/ui/packages/permissions/src/__tests__/RecordFieldAccessScope.rowWritable-27138.test.tsx +++ b/ui/packages/permissions/src/__tests__/RecordFieldAccessScope.rowWritable-27138.test.tsx @@ -66,7 +66,7 @@ const PROJECTION = { editable: ['title', 'summary'] }; function mount( load: (o: string, id: string) => Promise, { lockedBy, principal = ANSWER, nestedLock = false }: { - lockedBy?: 'approval'; + lockedBy?: 'approval' | 'closed'; principal?: MePermissionsResponse; nestedLock?: boolean; } = {}, @@ -137,6 +137,20 @@ describe('[#27138] RecordFieldAccessScope — the row verdict', () => { expect(writable.last().check('rfa_contract', 'update').reason).toBe('record-locked-by-approval'); }); + // objectstack#38997 — ADR-0162: the host's closed lock answers the same way, with its own reason. + it("a host's closed lock refuses the row with record-closed, before any answer and over a writable one", async () => { + let resolve: ((v: any) => void) | undefined; + const pending = mount(() => new Promise((r) => { resolve = r; }), { lockedBy: 'closed' }); + await waitFor(() => expect(resolve).toBeTypeOf('function')); + expect(pending.last().check('rfa_contract', 'update')).toEqual({ allowed: false, reason: 'record-closed' }); + expect(pending.last().checkField('rfa_contract', 'title', 'write')).toBe(false); + expect(pending.last().checkField('rfa_contract', 'title', 'read')).toBe(true); + + const writable = mount(async () => ({ ...PROJECTION, writable: true }), { lockedBy: 'closed' }); + await new Promise((r) => setTimeout(r, 0)); + expect(writable.last().check('rfa_contract', 'update').reason).toBe('record-closed'); + }); + it('an object grant the enclosing provider refuses keeps its own reason', async () => { const { last } = mount(async () => ({ ...PROJECTION, writable: false }), { principal: READ_ONLY_GRANT }); await new Promise((r) => setTimeout(r, 0)); diff --git a/ui/packages/plugin-form/src/ModalForm.tsx b/ui/packages/plugin-form/src/ModalForm.tsx index 2e24a86674e..38a8a59ff0d 100644 --- a/ui/packages/plugin-form/src/ModalForm.tsx +++ b/ui/packages/plugin-form/src/ModalForm.tsx @@ -72,7 +72,7 @@ import { type LoadedRecordSnapshot, } from './sanitize'; import { closedForRecord, closedFormAffordance, fieldWriteGate, gateFormFields } from './fieldWriteGate'; -import { RecordFieldAccessForForm } from './recordFieldAccess'; +import { RecordFieldAccessForForm, type RecordFieldAccessForFormProps } from './recordFieldAccess'; import { ClosedAffordanceNotice } from './closedAffordanceNotice'; import { seedCreateValues } from './schemaDefaults'; import { createWritePayload } from './writePayload'; @@ -317,11 +317,12 @@ export interface ModalFormProps { /** * A lock on the edited record that the host reads and the record's field * projection leaves out: `'approval'` while a pending approval locks it - * (objectstack#27138). The dialog then draws the record read-only, says + * (objectstack#27138), `'closed'` while the record is closed (ADR-0162, + * objectstack#38997). The dialog then draws the record read-only, says * why, and offers no Save, as it does for a row the server answers * `writable: false`. Read on an `edit` form with a `recordId` only. */ - lockedBy?: 'approval'; + lockedBy?: RecordFieldAccessForFormProps['lockedBy']; } /** diff --git a/ui/packages/plugin-form/src/closedAffordanceNotice.tsx b/ui/packages/plugin-form/src/closedAffordanceNotice.tsx index f2518392b87..b7f553610fc 100644 --- a/ui/packages/plugin-form/src/closedAffordanceNotice.tsx +++ b/ui/packages/plugin-form/src/closedAffordanceNotice.tsx @@ -40,7 +40,9 @@ import type { ClosedFormAffordance } from './fieldWriteGate'; * sentence names the record, not the object: the caller may edit other * records of it. `record` is the server's row verdict (sharing, ownership, * row-level security); `approval` a pending approval that locks the record, - * said with the record page's own lock sentence. + * said with the record page's own lock sentence; `closed` a record in one of + * its object's closed states (ADR-0162), said with the record page's own + * closed sentence. * * `role="status"`, the package's pattern for a form state (`UploadInFlightNotice`): * nothing has failed, and an assertive live region would interrupt a @@ -54,6 +56,7 @@ const useClosedAffordanceTranslation = createSafeTranslation( 'form.noPermissionToEdit': "You don't have permission to edit {{object}} records. The fields are read-only.", 'form.noPermissionToEditRecord': "You don't have permission to edit this record. The fields are read-only.", 'detail.lockedTooltip': 'This record has a pending approval request; editing is locked', + 'detail.lockedClosedTooltip': "This record is closed, so it can't be changed.", }, 'form.noPermissionToCreate', ); @@ -87,9 +90,11 @@ export function ClosedAffordanceNotice({ ? t('form.noPermissionToEditRecord') : affordance === 'approval' ? t('detail.lockedTooltip') - : affordance === 'edit' - ? t('form.noPermissionToEdit', { object }) - : t('form.noPermissionToCreate', { object }); + : affordance === 'closed' + ? t('detail.lockedClosedTooltip') + : affordance === 'edit' + ? t('form.noPermissionToEdit', { object }) + : t('form.noPermissionToCreate', { object }); return (

= new Map([ ['record-not-writable', 'record'], ['record-locked-by-approval', 'approval'], + ['record-closed', 'closed'], ]); /** @@ -302,7 +304,7 @@ const ROW_REFUSALS: ReadonlyMap = new Map { + it.each([ + ['a writable row', { ...PROJECTION, writable: true }], + ['a data source without the record projection', null], + ])('on %s, a closed record is drawn read-only with the closed sentence and no Save', async (_label, access) => { + const ds = makeDS(access); + render( + + + , + ); + await drawn(); + await waitFor(() => expect(locked()).toEqual({ title: true, summary: true })); + expect(notice()?.getAttribute('data-affordance')).toBe('closed'); + expect(notice()?.textContent).toBe("This record is closed, so it can't be changed."); + expect(saveButtons()).toBe(0); + }); +}); diff --git a/ui/packages/plugin-form/src/recordFieldAccess.tsx b/ui/packages/plugin-form/src/recordFieldAccess.tsx index 6e872c6bac5..a430dcfc4d1 100644 --- a/ui/packages/plugin-form/src/recordFieldAccess.tsx +++ b/ui/packages/plugin-form/src/recordFieldAccess.tsx @@ -41,14 +41,15 @@ * `writable: false` the scope refuses every field of the record and the * record's update, so the form draws read-only, says why and offers no Save. * A host that reads a lock the projection leaves out — a pending approval - * that locks the record — passes it as `lockedBy`, and it reaches the same + * that locks the record, or the record being closed (ADR-0162) — passes it as + * `lockedBy`, and it reaches the same * gates the same way. A form edits a stored record under that lock even on a * data source without the projection: the scope then has no answer to ask * for, and only the host's lock narrows the row. */ import React, { useEffect, useState } from 'react'; -import { RecordFieldAccessScope } from '@object-ui/permissions'; +import { RecordFieldAccessScope, type RecordFieldAccessScopeProps } from '@object-ui/permissions'; import { useDataInvalidation } from '@object-ui/react'; import type { DataSource } from '@object-ui/types'; @@ -56,7 +57,7 @@ export interface RecordFieldAccessForFormProps { schema: { objectName?: string; mode?: string; recordId?: string | number | null }; dataSource?: DataSource | null; /** A lock the host reads on the record and the projection leaves out (`RecordFieldAccessScope`'s `lockedBy`). */ - lockedBy?: 'approval'; + lockedBy?: RecordFieldAccessScopeProps['lockedBy']; children: React.ReactNode; } From c564f4854e9a1f6239789233dd4a0d439f8fed84 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 01:32:40 +0000 Subject: [PATCH 2/4] chore(changeset): the edit dialog's closed lock Claude-Session: https://claude.ai/code/session_01WGufzhKEbEnW8pwZRgK2gJ Co-authored-by: Claude --- .changeset/38997-edit-dialog-closed-lock.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .changeset/38997-edit-dialog-closed-lock.md diff --git a/.changeset/38997-edit-dialog-closed-lock.md b/.changeset/38997-edit-dialog-closed-lock.md new file mode 100644 index 00000000000..82f99012d47 --- /dev/null +++ b/.changeset/38997-edit-dialog-closed-lock.md @@ -0,0 +1,16 @@ +--- +'@object-ui/permissions': patch +'@object-ui/plugin-form': patch +'@object-ui/app-shell': patch +--- + +fix(console): the record edit dialog opens locked with the closed sentence on a closed record + +Clause-②: no +Metadata-protocol: none + +The console's full-record edit dialog now opens read-only on a closed record (one of its object's `closedStates` holds, its own or its master's, ADR-0162). It says "This record is closed, so it can't be changed." (the record page's sentence, `detail.lockedClosedTooltip`) and offers no Save. Before, it opened editable and the server's refusal of the save was the user's first notice. + +- The dialog reads the closed state from the data lock the record page reads (`recordClosedByLock` on `useRecordApprovals`). It sends no request of its own: on a record page it uses the page's answer. +- A record that is closed and also held by an approval reads as closed, as on the record page. A record held only by an approval reads as before. +- `RecordFieldAccessScope`, `ModalForm` and `RecordFieldAccessForForm` accept `lockedBy: 'closed'` beside `'approval'`. The scope refuses the row's update with the new reason `record-closed`, and `closedFormAffordance` answers it as the new `'closed'` affordance, which `closedForRecord` treats like `'approval'` (no Save). From a05e21e7e792edd7a005a7439edcefeccf3e5782 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 02:38:39 +0000 Subject: [PATCH 3/4] =?UTF-8?q?chore(changeset):=20declare=20the=20edit=20?= =?UTF-8?q?dialog's=20closed=20lock=20a=20Clause-=E2=91=A1=20widening=20(#?= =?UTF-8?q?38997)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The exported lockedBy prop of RecordFieldAccessScopeProps and ModalFormProps now accepts 'closed' beside 'approval': a widening of two published packages. Claude-Session: https://claude.ai/code/session_01WGufzhKEbEnW8pwZRgK2gJ Co-authored-by: Claude --- .changeset/38997-edit-dialog-closed-lock.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/38997-edit-dialog-closed-lock.md b/.changeset/38997-edit-dialog-closed-lock.md index 82f99012d47..5fe7e9d6dc7 100644 --- a/.changeset/38997-edit-dialog-closed-lock.md +++ b/.changeset/38997-edit-dialog-closed-lock.md @@ -6,7 +6,7 @@ fix(console): the record edit dialog opens locked with the closed sentence on a closed record -Clause-②: no +Clause-②: yes (widening: the exported `lockedBy` prop of `RecordFieldAccessScopeProps` in `@object-ui/permissions` and of `ModalFormProps` in `@object-ui/plugin-form` accepts `'closed'` beside `'approval'`) Metadata-protocol: none The console's full-record edit dialog now opens read-only on a closed record (one of its object's `closedStates` holds, its own or its master's, ADR-0162). It says "This record is closed, so it can't be changed." (the record page's sentence, `detail.lockedClosedTooltip`) and offers no Save. Before, it opened editable and the server's refusal of the save was the user's first notice. From 9e70d532b4f275d1616bcd338020b549218c9c41 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 02:39:07 +0000 Subject: [PATCH 4/4] =?UTF-8?q?chore(changeset):=20spell=20the=20Clause-?= =?UTF-8?q?=E2=91=A1=20line=20as=20the=20reader's=20fixed=20form=20(#38997?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude-Session: https://claude.ai/code/session_01WGufzhKEbEnW8pwZRgK2gJ Co-authored-by: Claude --- .changeset/38997-edit-dialog-closed-lock.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.changeset/38997-edit-dialog-closed-lock.md b/.changeset/38997-edit-dialog-closed-lock.md index 5fe7e9d6dc7..f11fd2aaabf 100644 --- a/.changeset/38997-edit-dialog-closed-lock.md +++ b/.changeset/38997-edit-dialog-closed-lock.md @@ -6,9 +6,11 @@ fix(console): the record edit dialog opens locked with the closed sentence on a closed record -Clause-②: yes (widening: the exported `lockedBy` prop of `RecordFieldAccessScopeProps` in `@object-ui/permissions` and of `ModalFormProps` in `@object-ui/plugin-form` accepts `'closed'` beside `'approval'`) +Clause-②: yes (widening) Metadata-protocol: none +The widening: the exported `lockedBy` prop of `RecordFieldAccessScopeProps` (`@object-ui/permissions`) and of `ModalFormProps` (`@object-ui/plugin-form`) accepts `'closed'` beside `'approval'`. + The console's full-record edit dialog now opens read-only on a closed record (one of its object's `closedStates` holds, its own or its master's, ADR-0162). It says "This record is closed, so it can't be changed." (the record page's sentence, `detail.lockedClosedTooltip`) and offers no Save. Before, it opened editable and the server's refusal of the save was the user's first notice. - The dialog reads the closed state from the data lock the record page reads (`recordClosedByLock` on `useRecordApprovals`). It sends no request of its own: on a record page it uses the page's answer.