Skip to content

Commit c07eb98

Browse files
committed
fix(metadata-core,fields,components): hand lock never opens for a denied viewer or locks a new line-item row
Contract delta S5/S6 and N6: a new line-item row (no id) does not judge uiReadonlyWhen; the FLS scrub serves uiReadonly: true when it deletes a uiReadonlyWhen that reads a denied field; the form's hand-lock fault check short-circuits on readonlyWhen on both evaluation paths. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CXSuJCALDHFWaV6Bv5
1 parent 116e042 commit c07eb98

8 files changed

Lines changed: 103 additions & 10 deletions

File tree

‎.changeset/36806-field-ui-readonly-hand-lock.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ A status column that only moves through actions, or a field an integration fills
3333
| conditional | `readonlyWhen` | `uiReadonlyWhen` (CEL, the same scope as `readonlyWhen`) |
3434

3535
- **`uiReadonly: true` / `uiReadonlyWhen`.** These console surfaces lock the field: the create and edit dialogs (the field is left off them and out of the payload they submit, so a create from the console lands on the field's `defaultValue`, and a `required` field therefore needs one), the record page's inline edit and stage path, the highlight-strip chip, grid inline edit and its multi-row save, kanban drag between columns grouped by the field, calendar drag, and the line-item grid (a `uiReadonly` child field is not a derived column, and an authored column over it is locked; a `uiReadonlyWhen` one locks its cell per row). The Gantt, the timesheet cell, the kanban swimlane drag and the in-app assistant do not read the keys yet. The engine never reads either key, so REST, import, declarative and script actions, and flows write the field, and the object's validations (a `state_machine`, for one) judge each write.
36-
- **`uiReadonlyWhen` is judged on an existing record only** (the create dialog does not read it), over the host's predicate scope on every surface. Grids and list views fetch the operands of a shown or dragged field's lock predicates. A predicate that cannot be evaluated LOCKS the field (no server judges the hand lock), the edit dialog refuses to submit until it is fixed, and `os validate` checks it as it checks `readonlyWhen`.
36+
- **`uiReadonlyWhen` is judged on an existing record only** (the create dialog does not read it, nor does a new line-item row), over the host's predicate scope on every surface. Grids and list views fetch the operands of a shown or dragged field's lock predicates. A predicate that cannot be evaluated LOCKS the field (no server judges the hand lock), the edit dialog refuses to submit until it is fixed, and `os validate` checks it as it checks `readonlyWhen`.
3737
- **Refused: `uiReadonly: true` beside `readonly: true`** (at `['uiReadonly']`, at every door that parses a field: `defineStack`, `os validate`, metadata save). Keep one: `readonly` when no client may write the field, `uiReadonly` when people at the console may not. `uiReadonlyWhen` beside `readonlyWhen` is accepted.
3838
- **Kanban: a `readonly` lane field no longer drags.** The board read no field lock before, so a card grouped by a `readonly` field could be dragged and its PATCH was silently stripped. The board now reads both locks.
3939
- **`@object-ui/core` exports the one verdict:** `fieldReadOnlyByHand(def, record?, context?)`, `fieldStaticallyReadOnlyByHand(def)`, `fieldHasConditionalHandLock(def)`. `resolveFieldRuleState` takes `uiReadonlyWhen` in its rules and `uiReadonly` in its statics. The import wizard's target mapping and the Studio/designer reads stay on the raw `readonly`.
4040
- **MCP `describe_object`** reports `uiReadonly` and `uiReadonlyWhen` as their own keys where set (never folded into `readonly`, which tells an agent to leave the field out of a write), on the HTTP and the stdio transport, and the tool description names them.
41-
- **Censuses and Studio.** The FLS reference scrub classifies both keys (`@objectstack/metadata-core`: `uiReadonly` kept, `uiReadonlyWhen` an expression position). The Studio field form offers both rows beside Read-only and Read-only when, with their labels and help translated in every metadata-forms locale pack (`@objectstack/platform-objects`).
41+
- **Censuses and Studio.** The FLS reference scrub classifies both keys (`@objectstack/metadata-core`: `uiReadonly` kept, `uiReadonlyWhen` an expression position). A caller denied a field the `uiReadonlyWhen` reads is served the field with `uiReadonly: true` in place of the predicate, so the lock never opens for them. The Studio field form offers both rows beside Read-only and Read-only when, with their labels and help translated in every metadata-forms locale pack (`@objectstack/platform-objects`).

‎packages/metadata-core/src/object-schema-fls-references.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,29 @@ describe('[ADR-0106 D1] references to a denied field — inside a READABLE field
449449
expect(served.fields.title).not.toHaveProperty('inlineAmountField');
450450
});
451451

452+
// [#36806] No server judges the hand lock, and the console fails it closed:
453+
// a predicate the caller cannot be served must not silently OPEN the field.
454+
it('[#36806] serves a field locked by hand (`uiReadonly: true`) when its `uiReadonlyWhen` reads the denied field', () => {
455+
const served = mask({ name: 'thing', fields: fieldsWith({ uiReadonlyWhen: 'record.secret_score > 0' }) });
456+
expect(served.fields.title).not.toHaveProperty('uiReadonlyWhen');
457+
expect(served.fields.title.uiReadonly).toBe(true);
458+
});
459+
460+
it('[#36806] CONTROL: a `uiReadonlyWhen` over readable fields is served as written, with no static lock added', () => {
461+
const served = mask({ name: 'thing', fields: fieldsWith({ uiReadonlyWhen: "record.id != ''" }) });
462+
expect(served.fields.title.uiReadonlyWhen).toBe("record.id != ''");
463+
expect(served.fields.title).not.toHaveProperty('uiReadonly');
464+
});
465+
466+
it('[#36806] CONTROL: a deleted `readonlyWhen` adds no hand lock (the server still judges it), nor does a field already `readonly`', () => {
467+
const served = mask({ name: 'thing', fields: fieldsWith({ readonlyWhen: 'record.secret_score > 0' }) });
468+
expect(served.fields.title).not.toHaveProperty('readonlyWhen');
469+
expect(served.fields.title).not.toHaveProperty('uiReadonly');
470+
const locked = mask({ name: 'thing', fields: fieldsWith({ readonly: true, uiReadonlyWhen: 'record.secret_score > 0' }) });
471+
expect(locked.fields.title).not.toHaveProperty('uiReadonly');
472+
expect(locked.fields.title.readonly).toBe(true);
473+
});
474+
452475
it('drops a `lookupAutofill` pair whose target is denied, and keeps a source named on the referenced object', () => {
453476
// #27945 — `target` is a field of THIS object; `source` names a field of
454477
// the lookup's `reference` object, which this projection cannot judge.

‎packages/metadata-core/src/object-schema-fls-references.ts‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,9 @@ export const FIELD_REFERENCE_POSITIONS: Readonly<Record<string, Scrub>> = {
684684
visibleWhen: expression,
685685
readonlyWhen: expression,
686686
// The hand lock's predicate (#36806), CEL over this object's record as
687-
// `readonlyWhen` is.
687+
// `readonlyWhen` is. Deleted when it mentions a denied field, and the
688+
// field is then served `uiReadonly: true` (`readableField` below): no
689+
// server judges the hand lock, so a deleted predicate must not open it.
688690
uiReadonlyWhen: expression,
689691
requiredWhen: expression,
690692
// The deadline's settle predicate (#22227), a `visibleWhen`-family CEL over
@@ -705,7 +707,27 @@ export const FIELD_REFERENCE_POSITIONS: Readonly<Record<string, Scrub>> = {
705707
...PROTECTION_ENVELOPE,
706708
};
707709

708-
const readableField = block(FIELD_REFERENCE_POSITIONS);
710+
/**
711+
* [#36806] A served field whose hand lock's predicate (`uiReadonlyWhen`) the
712+
* caller may not evaluate — it mentions a field denied to them, so the table
713+
* deletes it — is served LOCKED by hand instead (`uiReadonly: true`). Every
714+
* other predicate the table deletes is still judged where it matters: the
715+
* server evaluates `readonlyWhen` / `requiredWhen` on the write. Nothing
716+
* judges the hand lock but the console, and the console fails it CLOSED, so
717+
* deleting the predicate outright would silently OPEN the field for exactly the
718+
* caller who cannot see why it is locked. A field already `readonly: true` is
719+
* locked harder and gains nothing (the spec refuses the pair).
720+
*/
721+
const readableFieldTable = block(FIELD_REFERENCE_POSITIONS);
722+
const readableField: Scrub = (value, denied, scope) => {
723+
const out = readableFieldTable(value, denied, scope);
724+
if (out === value || !out || typeof out !== 'object' || Array.isArray(out)) return out;
725+
const before = value as Record<string, unknown>;
726+
const after = out as Record<string, unknown>;
727+
const lockDeleted = before.uiReadonlyWhen != null && !('uiReadonlyWhen' in after);
728+
if (!lockDeleted || after.readonly === true || after.uiReadonly === true) return out;
729+
return { ...after, uiReadonly: true };
730+
};
709731

710732
// ── Object level ──────────────────────────────────────────────────────────────
711733

‎ui/packages/components/src/renderers/form/__tests__/uiReadonlyWhen-fault-refuses-submit-36806.test.tsx‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ describe('objectstack#36806 — a faulted uiReadonlyWhen refuses an edit form\'s
100100
expect(onSubmit).not.toHaveBeenCalled();
101101
});
102102

103+
// Contract delta N6: the same verdict on both evaluation paths — a field the
104+
// server lock already holds never has its hand lock judged.
105+
it('CONTROL — a field readonlyWhen already locks submits, with or without a visibleWhen', async () => {
106+
for (const extra of [{}, { visibleWhen: 'true' }]) {
107+
const onSubmit = vi.fn().mockResolvedValue(undefined);
108+
const view = renderForm(base({ ...extra, readonlyWhen: "record.stage == 'open'", uiReadonlyWhen: BROKEN }), onSubmit, EDIT);
109+
submit();
110+
await waitFor(() => expect(onSubmit).toHaveBeenCalledTimes(1));
111+
view.unmount();
112+
}
113+
});
114+
103115
it('CONTROL — a uiReadonlyWhen that evaluates submits', async () => {
104116
const onSubmit = vi.fn().mockResolvedValue(undefined);
105117
renderForm(base({ uiReadonlyWhen: "record.stage == 'won'" }), onSubmit, EDIT);

‎ui/packages/components/src/renderers/form/form.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2268,8 +2268,11 @@ ComponentRegistry.register('form',
22682268
const visibleOn = (f as any).visibleOn;
22692269
const uiReadonlyWhen = isCreateForm ? undefined : (f as any).uiReadonlyWhen;
22702270
if (uiReadonlyWhen != null && visibleWhen == null && f.type !== 'section-divider') {
2271+
// `readonlyWhen` rides along so the verdict short-circuits exactly as
2272+
// on the `visibleWhen` path below: a field the server lock already
2273+
// holds never has its hand lock judged, so it never blocks the save.
22712274
const handLock = resolveFieldRuleState(
2272-
{ uiReadonlyWhen },
2275+
{ readonlyWhen: (f as any).readonlyWhen, uiReadonlyWhen },
22732276
ruleRecord,
22742277
{ readonly: (f as any).readonly === true },
22752278
previousRecord,

‎ui/packages/fields/src/widgets/GridField.handLock-36806.test.tsx‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('line-item grid hand lock (uiReadonlyWhen, #36806)', () => {
3030
it('locks the cell where the predicate is TRUE, per row and over the header', () => {
3131
render(
3232
<GridField
33-
value={[{ product: 'A', qty: 1, shipped: true }, { product: 'B', qty: 2, shipped: false }]}
33+
value={[{ id: 'l1', product: 'A', qty: 1, shipped: true }, { id: 'l2', product: 'B', qty: 2, shipped: false }]}
3434
onChange={() => {}}
3535
field={field}
3636
contextRecord={{ status: 'draft' }}
@@ -45,7 +45,7 @@ describe('line-item grid hand lock (uiReadonlyWhen, #36806)', () => {
4545
it('locks every row when the header makes the predicate TRUE', () => {
4646
render(
4747
<GridField
48-
value={[{ product: 'B', qty: 2, shipped: false }]}
48+
value={[{ id: 'l2', product: 'B', qty: 2, shipped: false }]}
4949
onChange={() => {}}
5050
field={field}
5151
contextRecord={{ status: 'approved' }}
@@ -54,6 +54,31 @@ describe('line-item grid hand lock (uiReadonlyWhen, #36806)', () => {
5454
expect((screen.getAllByLabelText('Qty')[0] as HTMLInputElement).disabled).toBe(true);
5555
});
5656

57+
// Contract delta S5: a create is not judged. A new line (no id) seeds only
58+
// the grid's columns, so an operand that is not a column (`status`, a
59+
// hand-locked child field) is absent and the fail-closed verdict would lock
60+
// the cell on every new line.
61+
it('does not judge uiReadonlyWhen on a new line, even when its operand is not a column', () => {
62+
render(
63+
<GridField
64+
value={[{ id: 'stored', product: 'A', qty: 1 }, { product: 'B', qty: null }]}
65+
onChange={() => {}}
66+
field={{
67+
columns: [
68+
{ name: 'product', label: 'Product', type: 'text' },
69+
{ name: 'qty', label: 'Qty', type: 'number', uiReadonlyWhen: "record.status != 'draft'" },
70+
],
71+
} as any}
72+
contextRecord={{}}
73+
/>,
74+
);
75+
const qty = screen.getAllByLabelText('Qty') as HTMLInputElement[];
76+
// The stored line has no `status`: judged, faulted, locked (fail-closed).
77+
expect(qty[0].disabled).toBe(true);
78+
// The new line is not judged: editable.
79+
expect(qty[1].disabled).toBe(false);
80+
});
81+
5782
// REWORK S3(a): an authored column over a `uiReadonly` child field carries
5883
// `uiReadonly: true` (plugin-form's `hydrateColumns`), and the cell reads it.
5984
it('a column carrying uiReadonly locks every row', () => {

‎ui/packages/fields/src/widgets/grid-field/GridFieldWidget.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,13 @@ function GridFieldBody({
847847
// row, no predicate to judge.
848848
const uiReadonly = (c as { uiReadonly?: boolean }).uiReadonly === true;
849849
if (uiReadonly) return { readonly: true, required: !!c.required };
850-
const uiReadonlyWhen = (c as { uiReadonlyWhen?: FieldRulePredicate }).uiReadonlyWhen;
850+
// The hand lock's predicate judges a STORED line only (objectstack#36806,
851+
// S5): a create is not judged, as the create dialog does not judge it,
852+
// and a new line seeds only the grid's columns, so an operand that is not
853+
// a column is an absent key the fail-closed verdict would lock on.
854+
const uiReadonlyWhen = rowHasId(row)
855+
? (c as { uiReadonlyWhen?: FieldRulePredicate }).uiReadonlyWhen
856+
: undefined;
851857
if (!c.readonlyWhen && !uiReadonlyWhen && !c.requiredWhen) {
852858
return { readonly: false, required: !!c.required };
853859
}

‎ui/packages/plugin-list/src/ListView.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4540,8 +4540,10 @@ export const ListView = React.forwardRef<ListViewHandle, ListViewProps>(({
45404540
// faulted `No such key`: open for `readonlyWhen` (the server drops
45414541
// the write), locked for the hand lock (nothing behind it judges
45424542
// one). Through `addSpeculative`, like every binding here: an
4543-
// operand the viewer may not read is never requested, and that
4544-
// field then stays locked by hand.
4543+
// operand the viewer may not read is never requested — and that
4544+
// viewer is never served the predicate either: the definition's FLS
4545+
// scrub (`@objectstack/metadata-core`) deletes it and serves the
4546+
// field `uiReadonly: true` in its place, so it stays locked by hand.
45454547
const lockDefs = objectDef?.fields as Record<string, { readonlyWhen?: unknown; uiReadonlyWhen?: unknown } | undefined> | undefined;
45464548
const editedInPlace = [
45474549
...cols,

0 commit comments

Comments
 (0)