Skip to content

Commit 48fba2b

Browse files
docs(permissions): recipe for locking a position's fields once a record reaches a stage (field permission when) (#26251)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9SG7rbUyLNjoTR3C1zMwjh7)_ Fixes #26178 Clause-②: no Metadata-protocol: none ## What An administrator-facing recipe for the field permission `when` ("at this stage, these people may no longer change these fields"), which until now only the developer reference described. - `content/docs/permissions/access-recipes.mdx`: a new row in the layer table, and a recipe **Lock fields for a position once a record reaches a stage** on the card's contract case (finance edits drafts, but `governing_law` / `liability_cap` freeze once `status in ["approved", "signing", "active"]`). It carries the editor path (Setup, Access Control, Permission Sets, open the set, expand the object, field row, **When (edit)**, Add condition), the same entries as `definePermissionSet` metadata, how to choose (a lock for everyone is a validation rule; a lock that depends on who edits is a field permission `when`), and the four boundaries from the card: edit only, same-object fields only, the stored record before the write on update, and it locks but does not grant under the most-permissive merge. - `content/docs/permissions/administrator-guide.mdx` Step 5: the field-level security bullet now names the **When (edit)** condition and points to the recipe. - `content/docs/permissions/field-level-security.mdx`: the `when` section links to the recipe. The recipe's metadata block is a self-contained `{/* os:check */}` example, so `check:skill-examples` type-checks it against `@objectstack/spec` from now on. ## Evidence - The block parses against `PermissionSetSchema` from `packages/spec/src` (one-off `tsx` run, not committed): recipe snippet `success: true`; negative control `readable: false` beside the same `when` is refused at `fields.clm_contract.governing_law.when` with the schema's own message ("A `when` reaches the EDIT vote only ..."). - Reverse check of the pin, on committed head 70e79e2: renaming `when` to `whenn` in the block turns `check:skill-examples` red (exit 1, TS2561 at `access-recipes.mdx:67:70`, "Did you mean to write 'when'?"); restored with `git checkout HEAD --`, blob `2c041d93` matches HEAD, `git diff HEAD` empty. - Studio labels checked against `ui/packages/app-shell/src/views/metadata-admin/i18n.ts` (`perm.field.when` = "When (edit)", `perm.field.when.add` = "Add condition") and `PermissionMatrixEditor.tsx` (the condition cell shows only while Read is on). ## Gates (head 70e79e2) - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`: 44 commands derived; all 44 run, each exit captured before any pipe, all exit 0. `--ran` reconciliation: 44 derived, 44 run, 0 NOT-MEASURED (derived from recorded exit codes). Includes `pnpm check:doc-authoring`, `pnpm check:doc-anchors` (606 fragment links resolve), `pnpm check:role-word`, `pnpm --filter @objectstack/spec run check:skill-examples` (263 marked examples, up from 262). - The lychee link check (`Check Documentation Links`, advisory) has no local binary here: NOT MEASURED locally, read from this PR's check run. Every new link targets an existing page (`/docs/data-modeling/validation`, `/docs/permissions/authorization`, `/docs/permissions/field-level-security`, `/docs/permissions/access-recipes`), and the anchors are covered by `check:doc-anchors` above. ## Acceptance notes - `check:role-word` refused the first draft's word "role" in prose (ADR-0090 D3), so the recipe is titled for a **position**, the administrator's unit of assignment. The card's own wording used the reserved word; nothing else changed in meaning. - Docs only: nothing published moves, so `skip-changeset`. --- _Generated by [Claude Code](https://claude.ai/code/session_01GEk1n2M6ejRZucZuYZLamJ)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 26e1453 commit 48fba2b

3 files changed

Lines changed: 54 additions & 1 deletion

File tree

‎content/docs/permissions/access-recipes.mdx‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Pick the layer that matches the requirement:
1818
|---|---|---|
1919
| Can read/create/edit/delete an object type | Object CRUD | permission-set `objects.{allowCreate/Read/Edit/Delete}` |
2020
| Can see / edit a specific field | Field-level security (FLS) | permission-set `fields`, or field `requiredPermissions` |
21+
| Can no longer edit a field once a record reaches a stage, for some positions only | Row-conditioned FLS | permission-set `fields` entry with `when` ([recipe](#data-lock-fields-for-a-position-once-a-record-reaches-a-stage)) |
2122
| Which *rows* a user sees | Row-level security (RLS) | permission-set `rowLevelSecurity` (CEL `using` / depth `readScope`) |
2223
| A functional capability (export, approve, manage) | Capability | `systemPermissions` ↔ resource `requiredPermissions` |
2324
| Can open an app / nav entry / page | Surface access | `App.requiredPermissions`, `tabPermissions`, nav gating |
@@ -40,6 +41,51 @@ definePermissionSet({
4041
- Grants combine **most-permissively** across a user's sets; the tenant-isolation policy `AND`s on top; the superuser bypass (`viewAllRecords` / `modifyAllRecords`) short-circuits RLS where the object's posture allows it (ADR-0066).
4142
- For genuinely sensitive objects, set `access: { default: 'private' }` so they are **not** covered by blanket wildcard grants — access needs an explicit grant.
4243

44+
### Data: lock fields for a position once a record reaches a stage
45+
46+
> Finance may edit a contract while it is a draft, but once it is approved the legal terms are frozen for finance. Legal still edits them.
47+
48+
Every business app meets this shape: a contract's legal terms after approval, an order's amount after shipping, an invoice after posting, a purchase order's supplier after approval. The answer is a field permission with a **row condition**, `when`, on the permission set that should lose the edit.
49+
50+
**In the permission-set editor** (Setup → Access Control → Permission Sets, then open the set):
51+
52+
1. Expand the object (`clm_contract`) to show its field rows.
53+
2. On each field row to lock (`governing_law`, `liability_cap`), keep **Read** on and **Edit** off.
54+
3. In the row's **When (edit)** column, choose **Add condition** and write the stage condition: `status in ["approved", "signing", "active"]`. The editor lints it like a row-level security clause, and a condition the publish gate would refuse holds the save.
55+
56+
**The same entries as metadata:**
57+
58+
{/* os:check */}
59+
```ts
60+
import { definePermissionSet } from '@objectstack/spec';
61+
62+
definePermissionSet({
63+
name: 'finance',
64+
objects: { clm_contract: { allowRead: true, allowEdit: true } },
65+
fields: {
66+
// Locked for finance from approval onward; a draft stays editable.
67+
'clm_contract.governing_law': { readable: true, editable: false, when: 'status in ["approved", "signing", "active"]' },
68+
'clm_contract.liability_cap': { readable: true, editable: false, when: 'status in ["approved", "signing", "active"]' },
69+
},
70+
});
71+
```
72+
73+
On a row the condition matches, the entry votes as declared (no edit). On every other row the entry is absent, as if the set had not named the field, so a draft stays editable under the object grant.
74+
75+
**How to choose:**
76+
77+
- The field must freeze for **everyone** at that stage → a [validation rule](/docs/data-modeling/validation) on the object. It refuses the write whoever sends it.
78+
- The field freezes depending on **who** is editing → a field permission with `when` on the sets that lose the edit, as above.
79+
80+
**Boundaries:**
81+
82+
- **Edit only, never read.** The condition narrows the edit vote; reads are judged row-blind. Keep `readable: true` on the entry: `readable: false` beside a `when` is refused at parse time.
83+
- **Same object only.** The condition names fields of the entry's own object (compared with a literal or a `current_user.*` value). A condition that reaches across a relation, or names a field the object lacks, is refused at authoring and publish.
84+
- **The record before the write.** On an update the condition reads the stored record, so a write cannot unlock itself by moving `status` back in the same request. On an insert it reads the record as sent.
85+
- **It locks, it does not grant.** Grants merge most-permissively: if the same user holds another set that grants the edit, that grant still wins and the field stays editable. Grant the edit only in the sets that should keep it. A subtractive deny layer is [not yet implemented](/docs/permissions/authorization#combination-semantics-the-fixed-order).
86+
87+
Full semantics, including how a write with no judgeable row is treated: [Row-conditioned edit locks](/docs/permissions/field-level-security#row-conditioned-edit-locks-when).
88+
4389
### Automation: the run-identity is the safety decision
4490

4591
Two separate questions:

‎content/docs/permissions/administrator-guide.mdx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ is a structured spreadsheet — you never hand-write JSON:
155155
bits (Transfer / Restore / Purge), and View All / Modify All, with per-row
156156
bulk buttons (Read / CRUD / All / None) and the object's sharing baseline
157157
(OWD) shown alongside.
158-
- **Field-level security** — expand an object for per-field Read / Edit.
158+
- **Field-level security** — expand an object for per-field Read / Edit, and
159+
a **When (edit)** condition that locks a field for this set's holders once a
160+
record reaches a stage — see the recipe
161+
[Lock fields for a position once a record reaches a stage](/docs/permissions/access-recipes#data-lock-fields-for-a-position-once-a-record-reaches-a-stage).
159162
- **Capabilities** — named grants like `manage_users` or `studio.access`.
160163

161164
Prefer the smallest change that works, in this order: **bind an existing set

‎content/docs/permissions/field-level-security.mdx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ fields: {
7070
holds the save. Switching **Read** off clears the condition, and the
7171
**Read all** / **Write all** shortcuts keep it.
7272

73+
For an administrator's walk-through (the editor path, the matching metadata,
74+
and when a validation rule is the better tool), see the recipe
75+
[Lock fields for a position once a record reaches a stage](/docs/permissions/access-recipes#data-lock-fields-for-a-position-once-a-record-reaches-a-stage).
76+
7377
## Hidden vs. Read-Only
7478

7579
```typescript

0 commit comments

Comments
 (0)