Skip to content

Commit 751e839

Browse files
feat(security): the access explanation names the channel that opened each field (#38616)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ812XJN3qiB4BunLgsS3T39D)_ Fixes #36051 Clause-②: yes Metadata-protocol: added Skills-docs: none — `fieldChannels` is a read-only key of the access explanation's answer; no metadata author writes it, and `content/docs/permissions/field-level-security.mdx` teaches reading it ## 维护者速读 - 管理员查看某个用户的权限说明时,现在能看到每个字段是被哪个权限集、通过哪种方式打开的;普通用户无感。 - 属于「查看/修改全部只管记录、不管字段」那次权限改造,回答作者「我明明隐藏了这个字段,是哪个权限集又把它打开了」。 - 只改说明、不改实际权限;出错最多是说明写错了打开字段的那个权限集,实际能看到的字段不变,可以直接撤回。 - 无 ## What changes The access explanation (`/api/v1/security/explain`, `ISecurityService.explain`) now names, per field, the channel that cast the winning read vote and the winning edit vote. The premise is the corrected one on the card (comment 7257037135): since protocol 19, View All and Modify All cast no field vote, so there are four channels and the CLI is out of scope. - **Spec** (`packages/spec/src/security/explain.zod.ts`): `ExplainLayer` gains an optional `fieldChannels` list, set on the `fls` layer only. Each entry is a field with optional `read` / `edit`, each a channel with the voting set names: - `own_row`: a set's own field row opens it, and no held set's row closes it. - `other_set_row`: a set's row opens it while another held set's row closes it, which is the union re-opening a field one set hides. - `view_all_fields`: no row opens it, and a set's `viewAllFields` bit casts the read vote. Read axis only: the edit axis has its own three-value enum. - `default`: no held set names the field. It carries no set names. `read` / `edit` is present only where the field merge kept that vote open; the object grant stays the `object_crud` layer's answer. The two channel schemas are not exported, following the pattern of `ExplainRecordVerdictSchema`, so the API surface is unchanged. - **Vote source** (`permission-evaluator.ts`): `PermissionEvaluator.fieldVoteSources(object, sets)` names the readers, hiders, editors, lockers and `viewAllFields` voters per field. It uses the merge's own vote functions: `fieldPermissionVote`, with no judge, and `viewAllFieldsReadVote` asked per set, so a set's own hiding row still beats its own bit. It decides nothing. - **Engine** (`explain-engine.ts`): the decision stays the enforcement mask (capability gates folded in, the D10 intersection), step 4's hidden list and the partial-mask set. A field that mask closes gets no channel on that axis, and a field served only through its masking rule (the detail's PARTIALLY masked list) gets no read channel. The edit axis follows the step 2.5 write gate's two arms: the mask's edit bit (a capability gate folds to `readable:false, editable:false`; the D10 intersection ANDs the delegator's edit bit), and the computed fields the caller is not served whole, which the gate refuses in a payload. That set reaches the engine through a new optional dep, `getComputedFieldsNotServedWhole`, wired in `security-plugin-explain-access.ts` to the gate's own composition (`computedFieldsNotServedWhole` over `computeQueryGuardFieldPerms`), not re-derived. A row's `readable:false` on a stored field closes the read axis only, so a write-only row keeps its edit channel. Fields are listed in schema order. When a field one held set hides is readable through another set, the `fls` detail adds one sentence naming the field and the set. - **Docs**: `content/docs/permissions/field-level-security.mdx` gains a "Which set opened a field" section. The generated references, authorable-surface list and strictness-ledger counts are regenerated. Read-only: no enforcement path changes. ## Why When a field is readable that an author meant to hide, the first question is which permission set opened it. Until now the answer meant reading the merge code. This is step 2 of the ruled field-axis split (#34365, ruling 6912661484 「同意,立决策卡」). ## Tests `packages/plugins/plugin-security/src/explain-engine.test.ts`, new describe "fls names the channel that opened each field". It runs the plugin's own mask wiring (`getFieldPermissions`) and parses each decision through `ExplainDecisionSchema`: - one set hides `f`, another names it on its own row: `other_set_row` naming that set, on read and edit, and the detail names it; - a single set's own row: `own_row`; - `viewAllFields` on another set: `view_all_fields` naming that set, read only; - View All and Modify All beside the hiding set: no channel, and no detail sentence; - a field no set names: `default` on both axes, with no set; - a capability gate the principal lacks closes the field: the opening row is not reported; - a field served only through a gate-less masking rule: no read channel while the detail says PARTIALLY masked, edit still `own_row`; - a write-only row (`readable: false, editable: true`): edit `own_row`, no read channel; - a computed field the write gate refuses (the dep's set): no edit channel while its row opens it. `packages/plugins/plugin-security/src/formula-reads-hidden-field-masking.test.ts` (real `ObjectQL` + SQL driver + `SecurityPlugin`), in "one write verdict": the explanation names no edit channel for a computed field withheld for its input (`open_cases_stored`) or served only through its own masking rule (`plain_masked`), the same two the preview, the write and the projections refuse; control: `name` and, for a caller served the input whole, `open_cases_stored` keep theirs. `packages/spec/src/security/explain.test.ts`: the read axis has exactly four channels and the edit axis three (pinned by introspection); `view_all_fields` is refused on edit, `view_all_records` on both axes, and a layer without the key still parses. Ablation (first round): forcing the row channel to `own_row` turned the `other_set_row` case red (1 failed, 5 passed). The mutation landed on disk through `scripts/ablation-replace.mjs`, and `git diff HEAD` was empty afterwards. Second round: restoring the edit axis's `!hidden.has(field)` turned the write-only case red (1 failed, 7 passed). Third round: dropping the `computedNotWhole` exclusion turned the plugin-level case red with both fields leaking `{ channel: 'default' }`. ## Acceptance notes - `Metadata-protocol: added` (not the claim's `none`): the new key enters the `packages/spec/authorable-surface/security.json` shard, and `Check Changeset` reads any shard move as a protocol kind (`none-baseline-moved`). `@objectstack/spec` is graded `minor`; `@objectstack/plugin-security` stays `patch`. - Review round 1 (seat L1 REWORK + contract-review L2 FAIL on `24a778da`) closed: partial fields lose the read channel, the read/edit wording says what presence means, the edit axis has its own enum, the spec pins both enums, and the evaluator names sets as the engine does. The seat keeps the full per-field list (not sparse). - Review round 2 closed: the edit axis no longer drops a hidden field. The capability gate and the D10 intersection already close `mask.editable`; a row's `readable:false` and a computed field withheld for what it reads gate the response, not the write (`FieldMasker.detectForbiddenWrites` reads the edit bit alone), so no source needs its own exclusion. - Review round 3 closed: the round-2 audit missed the write gate's second arm (`computeForbiddenFieldWrites` refuses a payload naming a computed field not served whole). The edit axis now closes for the gate's own set, handed over through the new dep; this also closes the masking-rule computed field that already diverged at `ed83df68`. Deviation from the order's surface: `security-plugin-explain-access.ts` and `security-plugin.ts` (the explain host) carry the wiring, per the seat's ruling to hand over the gate's set rather than re-derive it. - Under ADR-0090 D10 the channel names the principal's own sets. The delegator's mask only removes a channel, through the intersection. ## Verification Final head `6c9b214e`. CI: all 72 check-runs on it are success or skipped by their selector; none failed. Local subset on `6c9b214e` (round 3): - `explain-engine.test.ts` 150/150; the 27 test files that exercise the explanation: 1647 passed / 7 skipped; `formula-reads-hidden-field-masking.test.ts` 70/70. - `pnpm --filter @objectstack/plugin-security typecheck` (source, scripts and the test layer): exit 0. Spec `src/security` 421/421; `check:generated --fix`: all 14 up to date. Local subset on `1bebf96b` (round 2): - `pnpm --filter @objectstack/spec build`, then `vitest run src/security`: 15/15 files, 421/421 tests. `@objectstack/spec` and `@objectstack/plugin-security` typecheck: exit 0. `explain-engine.test.ts`: 149/149. - `pnpm --filter @objectstack/spec check:generated --fix`: all 14 generated artifacts up to date (the round-2 text change is a docblock; no `.describe()` moved). Local subset on `ed83df68` (round 1): - `pnpm --filter @objectstack/spec build`, then `vitest run src/security`: 15/15 files, 421/421 tests. `@objectstack/spec` and `@objectstack/plugin-security` typecheck: exit 0. `explain-engine.test.ts`: 148/148. - `pnpm --filter @objectstack/spec check:generated --fix` regenerated the stale `check:docs` and `check:strictness-ledger` and re-checked them green. `check:liveness`: exit 0. - `node scripts/pm/dispatch-gates.mjs --commands` derived 119 families (the same set as round 0). `--ran` with exit codes: 118 exit 0, 1 NOT MEASURED, 0 unrun. - First round, on `67523d47`: `pnpm --filter @objectstack/plugin-security test` 290/290 files, 7358 passed / 45 skipped. <details><summary>The 1 NOT MEASURED (exit 3, prerequisite not met in this container; CI runs it)</summary> - `node scripts/check-plugin-teardown-shape.mjs --self-test`: its pinned positive control needs an unshallowed clone. </details> Not run locally: `test:repo`, full dogfood (no `!` in the title and no narrowing arm), and `pnpm lint`. All of these belong to CI. Two-minute check: `pnpm --filter @objectstack/plugin-security exec vitest run --maxWorkers=2 src/explain-engine.test.ts -t "names the channel"` shows 9 passed. Read first, by risk: `explain-engine.ts` `fieldChannelsOf` (whether a channel can claim a field the mask or the write gate closes), `security-plugin-explain-access.ts` `getComputedFieldsNotServedWhole` (parity with `computeForbiddenFieldWrites`), `permission-evaluator.ts` `fieldVoteSources` (parity with `getFieldPermissions`), `explain.zod.ts` (the new optional key). ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes (CI). - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01JQwxba7R1thfXzYipYgzGJ <!-- signed: repo:objectstack#2 · os-warren · session_01JQwxba7R1thfXzYipYgzGJ --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 43eaf5e commit 751e839

14 files changed

Lines changed: 493 additions & 12 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/plugin-security': patch
4+
---
5+
6+
feat(security): the access explanation names the channel that opened each field
7+
8+
Clause-②: yes
9+
Metadata-protocol: added
10+
11+
The `fls` layer of the access explanation (`/api/v1/security/explain`, `ISecurityService.explain`) gains an optional `fieldChannels` list. For each field of the object it names the channel that cast the winning read vote and the one that cast the winning edit vote, with the permission sets that cast it:
12+
13+
- `own_row`: a set's own field row opens the field, and no held set's row closes it;
14+
- `other_set_row`: a set's row opens it while another held set's row closes it, so that set re-opens a field the other hides;
15+
- `view_all_fields`: no row opens it and a set's `viewAllFields` bit casts the read vote (read only, never an edit channel);
16+
- `default`: no held set names the field, so it follows the object grant.
17+
18+
View All and Modify All are not channels: they cast no field vote. `read` / `edit` is present only where the field merge kept that vote open: a field a row hides carries no `read` entry, a field a row locks carries no `edit` entry, a capability gate or the delegator closes the axis it closes, a field served only through its masking rule carries no `read` entry, and a computed field the caller is not served whole carries no `edit` entry (the write gate refuses a payload naming it). A write-only row on a stored field reports an `edit` channel with no `read`. Whether the object grant allows the operation is the `object_crud` layer's answer. When a field one held set hides is readable through another set, the layer's `detail` names the field and that set.
19+
20+
The explanation is read-only: enforcement is unchanged. Existing consumers keep parsing, because the key is optional. `PermissionEvaluator.fieldVoteSources(object, sets)` (`@objectstack/plugin-security`) is the vote source the explanation reads: the sets behind each field vote, from the same vote functions the field merge uses.

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,40 @@ For an administrator's walk-through (the editor path, the matching metadata,
189189
and when a validation rule is the better tool), see the recipe
190190
[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).
191191

192+
## Which set opened a field
193+
194+
When a field is readable that you meant to hide, ask the access explanation
195+
(`/api/v1/security/explain`, see [Authorization](/docs/permissions/authorization)).
196+
Its `fls` layer carries `fieldChannels`: for each field of the object, the
197+
channel that cast the winning read vote and the one that cast the winning edit
198+
vote, with the sets that cast it.
199+
200+
| Channel | Meaning |
201+
| :--- | :--- |
202+
| `own_row` | A set's own field row opens it, and no held set's row closes it. |
203+
| `other_set_row` | A set's row opens it while another held set's row closes it: grants union across sets, so that set re-opens the field. |
204+
| `view_all_fields` | No row opens it; a set's `viewAllFields` bit casts the read vote. Read only, so it never appears as an edit channel. |
205+
| `default` | No held set names the field, so it follows the object grant. No set is named. |
206+
207+
```json
208+
{ "field": "collected_total",
209+
"read": { "channel": "other_set_row", "sets": ["finance"] } }
210+
```
211+
212+
View All and Modify All never appear: they cast no field vote. `read` or
213+
`edit` is present only where the field merge kept that vote open. A field a
214+
row hides has no `read` entry, a field a row locks has no `edit` entry, a
215+
capability gate closes both, and a field served only through its masking rule
216+
has no `read` entry. A computed field the caller is not served whole has no
217+
`edit` entry either, because a write naming it is refused. A write-only row
218+
(`readable: false, editable: true`) on a stored field reports an `edit`
219+
channel and no `read` channel. Whether
220+
the object grant allows the operation at all is the `object_crud` layer's
221+
answer. When a field one held set hides is readable through another set, the
222+
layer's `detail` names the field and that set. To close it, remove the
223+
re-opening row or `viewAllFields` bit, or move a sensitive field behind its
224+
own `requiredPermissions`.
225+
192226
## Hidden vs. Read-Only
193227

194228
```typescript

‎content/docs/references/security/explain.mdx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ ADR-0095 D2 posture rung — PLATFORM_ADMIN crosses the tenant wall where object
132132
| **verdict** | `Enum<'grants' \| 'denies' \| 'narrows' \| 'widens' \| 'neutral' \| 'not_applicable'>` | ✅ | |
133133
| **detail** | `string` | ✅ | |
134134
| **contributors** | `{ kind: Enum<'permission_set' \| 'position' \| 'system'>; name: string; via?: string; state?: Enum<'active' \| 'expired' \| 'deactivated'> }[]` | optional (default: `[]`) | |
135+
| **fieldChannels** | `{ field: string; read?: object; edit?: object }[]` | optional | fls layer only: per field, the channel that cast the winning read and edit vote — own_row, other_set_row (re-opens a field another held set hides), view_all_fields (read axis only) or default (no held set names the field) — with the voting set names. |
135136
| **record** | `{ outcome: Enum<'admitted' \| 'excluded' \| 'not_evaluated'>; rowFilter?: any; matchesRecord?: boolean; rules?: object[]; … }` | optional | Row-level determination for the specific record under explanation; set only for record-grained requests. |
136137

137138
### Nested Shape: `ExplainDecision.record`
@@ -164,8 +165,17 @@ ADR-0095 D2 posture rung — PLATFORM_ADMIN crosses the tenant wall where object
164165
| **verdict** | `Enum<'grants' \| 'denies' \| 'narrows' \| 'widens' \| 'neutral' \| 'not_applicable'>` | ✅ | |
165166
| **detail** | `string` | ✅ | |
166167
| **contributors** | `{ kind: Enum<'permission_set' \| 'position' \| 'system'>; name: string; via?: string; state?: Enum<'active' \| 'expired' \| 'deactivated'> }[]` | optional (default: `[]`) | |
168+
| **fieldChannels** | `{ field: string; read?: object; edit?: object }[]` | optional | fls layer only: per field, the channel that cast the winning read and edit vote — own_row, other_set_row (re-opens a field another held set hides), view_all_fields (read axis only) or default (no held set names the field) — with the voting set names. |
167169
| **record** | `{ outcome: Enum<'admitted' \| 'excluded' \| 'not_evaluated'>; rowFilter?: any; matchesRecord?: boolean; rules?: object[]; … }` | optional | Row-level determination for the specific record under explanation; set only for record-grained requests. |
168170

171+
### Nested Shape: `ExplainLayer.fieldChannels[number]`
172+
173+
| Property | Type | Required | Description |
174+
| :--- | :--- | :--- | :--- |
175+
| **field** | `string` | ✅ | The field name, without the object prefix. |
176+
| **read** | `{ channel: Enum<'own_row' \| 'other_set_row' \| 'view_all_fields' \| 'default'>; sets?: string[] }` | optional | The channel that cast the winning read vote; present when the field merge kept the read vote open and the value is served whole, absent otherwise. The object grant is the object_crud layer's answer. |
177+
| **edit** | `{ channel: Enum<'own_row' \| 'other_set_row' \| 'default'>; sets?: string[] }` | optional | The channel that cast the winning edit vote; present when the field merge kept the edit vote open, absent otherwise. The object grant is the object_crud layer's answer. |
178+
169179
### Nested Shape: `ExplainLayer.record`
170180

171181
| Property | Type | Required | Description |

‎docs/audits/2026-07-unknown-key-strictness-ledger.counts/security.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The `strict` column is the one the campaign schedules against; it counts both th
2121

2222
| Dir | Sites | strict | passthrough | catchall | strip |
2323
|---|---|---|---|---|---|
24-
| `security/` | 24 | 11 | 0 | 0 | 13 |
24+
| `security/` | 27 | 11 | 0 | 0 | 16 |
2525

2626
## `security/` — sites
2727

@@ -31,32 +31,32 @@ classify and is not listed (it becomes reportable the day it grows its first sit
3131

3232
| File | Sites |
3333
|---|---|
34-
| `explain.zod.ts` | 11 |
34+
| `explain.zod.ts` | 14 |
3535
| `permission.zod.ts` | 4 |
3636
| `queue.zod.ts` | 2 |
3737
| `rls.zod.ts` | 5 |
3838
| `sharing.zod.ts` | 2 |
39-
| **total** | **24** |
39+
| **total** | **27** |
4040

4141
## `security/` — open
4242

4343
Per file, how many of its sites still silently discard unknown keys. The `Class`
4444
column that decides the bucket split is hand-written in the ledger; the arithmetic
4545
over it is here.
4646

47-
**13 strip of 24**, in 2 file(s).
47+
**16 strip of 27**, in 2 file(s).
4848

4949
| File | Strip | Sites |
5050
|---|---|---|
51-
| `explain.zod.ts` | 11 | 11 |
51+
| `explain.zod.ts` | 14 | 14 |
5252
| `rls.zod.ts` | 2 | 5 |
53-
| **total** | **13** | **24** |
53+
| **total** | **16** | **27** |
5454

5555
| Bucket | Sites |
5656
|---|---|
5757
| authorable — the ruling's forced scope | 0 |
5858
| unresolved — needs a per-schema verdict | 0 |
59-
| wire / open — out of forced scope | 13 |
59+
| wire / open — out of forced scope | 16 |
6060
| no door — no carrier, ADR-0049 territory | 0 |
6161
| no gate — carrier live, no parse | 0 |
6262
| covered — no carrier, no parse, guarded at every consumer | 0 |

‎packages/plugins/plugin-security/src/explain-engine.test.ts‎

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,3 +2280,135 @@ describe('explainAccess — a transfer is reported only where the record could b
22802280
}
22812281
});
22822282
});
2283+
2284+
// ---------------------------------------------------------------------------
2285+
// [Field-axis split, ruling of record 6912661484] fls names the channel that
2286+
// opened each field. Since protocol 19 View All / Modify All cast no field
2287+
// vote, so the channels are four: a set's own row, another set's row (the
2288+
// union re-opening a field one held set hides), `viewAllFields` (read only),
2289+
// and the default (no held set names the field). The mask below is the
2290+
// plugin's own wiring (`getFieldPermissions`), so the channel and the
2291+
// enforcement mask are read off the same merge.
2292+
// ---------------------------------------------------------------------------
2293+
describe('explainAccess — fls names the channel that opened each field', () => {
2294+
const OBJ = 'leave_request';
2295+
const SCHEMA = { name: OBJ, sharingModel: 'private', fields: { name: {}, f: {}, notes: {} } };
2296+
const HIDER = PermissionSetSchema.parse({
2297+
name: 'hider',
2298+
objects: { [OBJ]: { allowRead: true, allowEdit: true } },
2299+
fields: { [`${OBJ}.f`]: { readable: false, editable: false } },
2300+
});
2301+
const channelsOf = async (sets: any[], extra: Partial<ExplainEngineDeps> = {}) => {
2302+
const deps = makeDeps({ sets, schema: SCHEMA, ...extra });
2303+
const d = await explainAccess(
2304+
{ ...deps, getFieldMask: (s, o) => deps.evaluator.getFieldPermissions(o, s), ...extra },
2305+
{ object: OBJ, operation: 'read', context: CTX },
2306+
);
2307+
ExplainDecisionSchema.parse(d);
2308+
const fls = d.layers.find((l) => l.layer === 'fls')!;
2309+
return { fls, byField: Object.fromEntries((fls.fieldChannels ?? []).map((e) => [e.field, e])) };
2310+
};
2311+
2312+
it('another set\'s row re-opens a field one set hides: other_set_row, naming that set', async () => {
2313+
const opener = PermissionSetSchema.parse({
2314+
name: 'finance',
2315+
objects: { [OBJ]: { allowRead: true } },
2316+
fields: { [`${OBJ}.f`]: { readable: true, editable: true } },
2317+
});
2318+
const { fls, byField } = await channelsOf([HIDER, opener]);
2319+
expect(byField.f).toEqual({
2320+
field: 'f',
2321+
read: { channel: 'other_set_row', sets: ['finance'] },
2322+
edit: { channel: 'other_set_row', sets: ['finance'] },
2323+
});
2324+
expect(fls.detail).toContain('f (row of "finance")');
2325+
});
2326+
2327+
it('a set\'s own row with no closing row elsewhere: own_row', async () => {
2328+
const own = PermissionSetSchema.parse({
2329+
name: 'reader',
2330+
objects: { [OBJ]: { allowRead: true } },
2331+
fields: { [`${OBJ}.f`]: { readable: true, editable: false } },
2332+
});
2333+
const { byField } = await channelsOf([own]);
2334+
expect(byField.f).toEqual({ field: 'f', read: { channel: 'own_row', sets: ['reader'] } });
2335+
});
2336+
2337+
it('viewAllFields re-opens the hidden field for read only: view_all_fields, naming the set', async () => {
2338+
const vaf = PermissionSetSchema.parse({
2339+
name: 'auditor',
2340+
objects: { [OBJ]: { allowRead: true, viewAllFields: true } },
2341+
});
2342+
const { fls, byField } = await channelsOf([HIDER, vaf]);
2343+
expect(byField.f).toEqual({ field: 'f', read: { channel: 'view_all_fields', sets: ['auditor'] } });
2344+
expect(fls.detail).toContain('f (viewAllFields of "auditor")');
2345+
});
2346+
2347+
it('View All and Modify All open nothing: the field another set hides stays without a channel', async () => {
2348+
const bypass = PermissionSetSchema.parse({
2349+
name: 'records_admin',
2350+
objects: { [OBJ]: { allowRead: true, allowEdit: true, viewAllRecords: true, modifyAllRecords: true } },
2351+
});
2352+
const { fls, byField } = await channelsOf([HIDER, bypass]);
2353+
expect(byField.f).toEqual({ field: 'f' });
2354+
expect(fls.detail).not.toContain('readable through another set');
2355+
});
2356+
2357+
it('a field no held set names follows the object grant: default, on both axes, with no set', async () => {
2358+
const { byField } = await channelsOf([HIDER]);
2359+
expect(byField.notes).toEqual({ field: 'notes', read: { channel: 'default' }, edit: { channel: 'default' } });
2360+
expect(byField.f).toEqual({ field: 'f' });
2361+
});
2362+
2363+
it('a field served only through a gate-less masking rule gets no read channel (the detail calls it PARTIALLY masked)', async () => {
2364+
const opener = PermissionSetSchema.parse({
2365+
name: 'finance',
2366+
objects: { [OBJ]: { allowRead: true } },
2367+
fields: { [`${OBJ}.f`]: { readable: true, editable: true } },
2368+
});
2369+
const { fls, byField } = await channelsOf([opener], {
2370+
getPartialMaskRules: async () => ({ f: 'email' as any }),
2371+
});
2372+
expect(fls.detail).toContain('PARTIALLY masked');
2373+
expect(byField.f?.read).toBeUndefined();
2374+
expect(byField.f?.edit).toEqual({ channel: 'own_row', sets: ['finance'] });
2375+
});
2376+
2377+
it('a write-only row hides the field but keeps it editable: an edit channel and no read channel', async () => {
2378+
// `hidden` closes the read axis only: a row's `readable: false` gates the
2379+
// response, not the write (the write gate reads the edit bit alone).
2380+
const writer = PermissionSetSchema.parse({
2381+
name: 'intake',
2382+
objects: { [OBJ]: { allowRead: true, allowEdit: true } },
2383+
fields: { [`${OBJ}.f`]: { readable: false, editable: true } },
2384+
});
2385+
const { fls, byField } = await channelsOf([writer]);
2386+
expect(fls.detail).toContain('masked from responses');
2387+
expect(byField.f).toEqual({ field: 'f', edit: { channel: 'own_row', sets: ['intake'] } });
2388+
});
2389+
2390+
it('a computed field the write gate refuses (not served whole) gets no edit channel, whatever row opens it', async () => {
2391+
const opener = PermissionSetSchema.parse({
2392+
name: 'finance',
2393+
objects: { [OBJ]: { allowRead: true, allowEdit: true } },
2394+
fields: { [`${OBJ}.f`]: { readable: true, editable: true } },
2395+
});
2396+
const { byField } = await channelsOf([opener], {
2397+
getComputedFieldsNotServedWhole: async () => new Set(['f']),
2398+
});
2399+
expect(byField.f).toEqual({ field: 'f', read: { channel: 'own_row', sets: ['finance'] } });
2400+
expect(byField.notes).toEqual({ field: 'notes', read: { channel: 'default' }, edit: { channel: 'default' } });
2401+
});
2402+
2403+
it('a field capability gate the principal lacks closes the field: the opening row is not reported', async () => {
2404+
const opener = PermissionSetSchema.parse({
2405+
name: 'finance',
2406+
objects: { [OBJ]: { allowRead: true } },
2407+
fields: { [`${OBJ}.f`]: { readable: true, editable: true } },
2408+
});
2409+
const { byField } = await channelsOf([opener], {
2410+
getFieldMask: () => ({ f: { readable: false, editable: false } }),
2411+
});
2412+
expect(byField.f).toEqual({ field: 'f' });
2413+
});
2414+
});

0 commit comments

Comments
 (0)