Skip to content

Commit 119d5db

Browse files
fix(app-shell): permission matrix keeps a roll-up acknowledgement only while Read is on (#34954)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBLW6dHPW6sSheA32XPKZzPV)_ Fixes #34786 Clause-②: no Metadata-protocol: none repo:objectstack#3 · os-support-ai · session_01WGufziunkXbDT7wUWqfmWz ## 维护者速读 - 改了什么:控制台权限矩阵里,字段行关掉 Read 时,同一次编辑会删掉 `rollupSourceUnreadableReason`;批量快捷键(只读全部/可写全部)改写字段行时保留这条说明。 - 为什么改:spec 拒收 `readable: false` 旁边的说明,原来关 Read 会留下被拒的形状且无法清除;批量快捷键则会悄悄丢掉管理员写下的说明。 - 风险与回滚:仅限私有包 `@object-ui/app-shell` 的两个函数,无 spec 或接口变化;回滚即 revert 本 PR。 - 先看:`permission-slice.ts`(`withFieldBits` 的 `readable &&` 条件)、`PermissionMatrixEditor.tsx`(`updateFieldPerm` 的 Read off 级联)、`permission-slice.fieldRule-26597.test.ts`。 - 两分钟验证:`cd ui && pnpm exec vitest run packages/app-shell/src/views/metadata-admin/permission-slice.fieldRule-26597.test.ts`,预期全绿,含 3 条 `withFieldBits` 新用例。 - 需要你做的:无,席位落地。 ## What changes - `FieldPerm` (`permission-slice.ts`) declares the optional `rollupSourceUnreadableReason` key, documented against `FieldPermissionSchema`. - `updateFieldPerm` (`PermissionMatrixEditor.tsx`): Read off now deletes the reason beside `when` (the objectstack#25866 cascade), so the editor never authors the shape `FIELD_PERMISSION_ROLLUP_REASON_ON_HIDDEN` refuses. - `withFieldBits` keeps the reason while `readable` stays true and drops it only when `readable` goes false. Its one caller, `applyFieldBulk`, always passes `readable: true`, so the bulk shortcuts now keep the reason instead of dropping it silently. - Changeset: `@object-ui/app-shell` patch. ## Tests - `permission-slice.fieldRule-26597.test.ts`: a new top-level `describe` for `withFieldBits`. It keeps the reason on a readable rewrite and drops it on `readable: false`, and `applyFieldBulk` Read-only all keeps it. Each resulting entry is parsed with the real `FieldPermissionSchema` from `@objectstack/spec/security`, and a control parse proves the refused shape really is refused (the issue path is `rollupSourceUnreadableReason`). - `PermissionMatrixEditor.fieldWhen-25866.test.tsx`: a new top-level `describe` in the existing field-cascade harness. Read off on a stored acknowledged entry saves `{ readable: false, editable: false }`, Write all saves the entry with the reason kept, and both saved entries parse with `FieldPermissionSchema`. ## Acceptance notes - `withFieldBits(cur, false, …)` still keeps `when`. The refused `when` beside `readable: false` shape is reachable only if a caller passes `readable: false`, and no caller does (`applyFieldBulk` passes `true`). I left it alone because it is outside this card. ## Verification <details><summary>Pinned tests, head 5d561af</summary> `os-verify-lock` running `vitest run --maxWorkers=2` on the two files: `Test Files 2 passed (2)`, `Tests 27 passed (27)`, `VERDICT command-exit 0`. </details> <details><summary>Ablations (scripts/ablation-replace.mjs, each restored to blob == HEAD)</summary> - A, delete `delete next.rollupSourceUnreadableReason;` in `updateFieldPerm`: `Read off removes the reason, so the saved entry is one the spec accepts` fails (1 failed). Restored to blob 27768b9, which equals HEAD. - B, `readable && ` guard removed in `withFieldBits`: `drops the reason when the entry goes readable:false` fails (1 failed). Restored to blob 5206a29, which equals HEAD. - C, keep branch disabled in `withFieldBits` (the pre-fix behaviour): 3 failed, namely the slice keep case, bulk Read-only all, and editor Write all. Restored to blob 5206a29, which equals HEAD. - After the script: `git diff HEAD` empty. </details> <details><summary>Type check and gates</summary> - `pnpm --filter @object-ui/app-shell run type-check` (both `tsc` programs): `VERDICT command-exit 0`. - `dispatch-gates --commands`: 38 derived commands. 36 exited 0. Two were NOT MEASURED on the first pass: `pnpm --dir ui exec vitest run scripts/` (the files failed with `Cannot find package '@objectstack/spec/ui'` because the run started before the spec dist existed, an environment fault) and `pnpm check:type-check-debt` (exit 3, its closure build never got a lock turn). The seat report records the re-run result. `dispatch-gates --ran`: 38 derived, 38 run. - `overlap-check` against origin/main c81f498 and open PR #34914: `VERDICT clean exit 0`. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufziunkXbDT7wUWqfmWz)_ <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufziunkXbDT7wUWqfmWz --> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent bb169c3 commit 119d5db

5 files changed

Lines changed: 103 additions & 3 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(app-shell): the permission matrix drops a roll-up acknowledgement when Read goes off and keeps it otherwise
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A permission set's field entry may carry `rollupSourceUnreadableReason`, the acknowledgement `os lint` reads on a roll-up `summary` column. The spec refuses it beside `readable: false`.
11+
12+
- Switching Read off on a field row now removes the reason in the same edit, the way it already removes a row condition. Before, the entry kept the reason beside `readable: false`, a shape the save refused, and the matrix offered no way to clear it.
13+
- The field bulk shortcuts (Read-only all, Write all) now keep the reason on every row they rewrite, because those rows stay readable. Before, they dropped it silently.

‎ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.fieldWhen-25866.test.tsx‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ import { MemoryRouter } from 'react-router-dom';
1919
import '@objectstack/formula';
2020
import '@objectstack/lint';
2121
import '@objectstack/spec/identity';
22+
import { FieldPermissionSchema } from '@objectstack/spec/security';
2223

2324
interface FieldEntry {
2425
readable?: boolean;
2526
editable?: boolean;
2627
when?: string;
28+
rollupSourceUnreadableReason?: string;
2729
}
2830
interface SavedSet {
2931
fields?: Record<string, FieldEntry>;
@@ -201,3 +203,37 @@ describe('a field row offers a row condition on its edit vote (objectstack#25866
201203
expect(set.fields?.['a_account.amount']).toEqual({ readable: true, editable: false, when: "status == 'approved'" });
202204
});
203205
});
206+
207+
/**
208+
* The roll-up acknowledgement (`rollupSourceUnreadableReason`) rides the same
209+
* cascade as the row condition: the spec refuses it beside `readable: false`,
210+
* so Read off removes it in the same edit, and a bulk shortcut that keeps the
211+
* row readable keeps it.
212+
*/
213+
describe('a field row keeps a roll-up acknowledgement only while Read is on', () => {
214+
const REASON = 'Service staff read account totals but not invoice rows';
215+
216+
it('Read off removes the reason, so the saved entry is one the spec accepts', async () => {
217+
await renderExpanded({ 'a_account.revenue': { readable: true, editable: false, rollupSourceUnreadableReason: REASON } });
218+
219+
fireEvent.click(screen.getByLabelText('a_account.revenue readable'));
220+
expect(screen.getByLabelText('a_account.revenue readable')).not.toBeChecked();
221+
222+
const set = await saveAfter(0);
223+
const entry = set.fields?.['a_account.revenue'];
224+
expect(entry).toEqual({ readable: false, editable: false });
225+
expect(FieldPermissionSchema.safeParse(entry).success).toBe(true);
226+
});
227+
228+
it('Write all keeps the reason on a row it rewrites, and the spec accepts the entry', async () => {
229+
await renderExpanded({ 'a_account.revenue': { readable: true, editable: false, rollupSourceUnreadableReason: REASON } });
230+
231+
fireEvent.click(screen.getByRole('button', { name: 'Write all' }));
232+
expect(screen.getByLabelText('a_account.revenue editable')).toBeChecked();
233+
234+
const set = await saveAfter(0);
235+
const entry = set.fields?.['a_account.revenue'];
236+
expect(entry).toEqual({ readable: true, editable: true, rollupSourceUnreadableReason: REASON });
237+
expect(FieldPermissionSchema.safeParse(entry).success).toBe(true);
238+
});
239+
});

‎ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,12 +1493,14 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved,
14931493
// draws (the object grant), so the click changes only the box it lands on.
14941494
const cur = fieldRuleSeed(fields[key], drawnObjectPerm(prev, objectName));
14951495
const next: FieldPerm = { ...cur, [action]: value };
1496-
// Cascade: !readable implies !editable — and no row condition: the spec
1497-
// refuses `when` beside `readable: false` (objectstack#25866), so Read
1498-
// off clears the condition instead of authoring the refused shape.
1496+
// Cascade: !readable implies !editable — and no row condition and no
1497+
// roll-up acknowledgement: the spec refuses `when` (objectstack#25866)
1498+
// and `rollupSourceUnreadableReason` beside `readable: false`, so Read
1499+
// off clears both instead of authoring the refused shape.
14991500
if (action === 'readable' && !value) {
15001501
next.editable = false;
15011502
delete next.when;
1503+
delete next.rollupSourceUnreadableReason;
15021504
}
15031505
// Cascade: editable implies readable.
15041506
if (action === 'editable' && value) next.readable = true;

‎ui/packages/app-shell/src/views/metadata-admin/permission-slice.fieldRule-26597.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
*/
1515

1616
import { describe, expect, it } from 'vitest';
17+
import { FieldPermissionSchema } from '@objectstack/spec/security';
1718
import {
1819
applyFieldBulk,
1920
fieldRuleCell,
2021
fieldRuleSeed,
22+
withFieldBits,
2123
type FieldPerm,
2224
type ObjectPerm,
2325
} from './permission-slice';
@@ -146,3 +148,32 @@ describe('applyFieldBulk — a shortcut writes only the rows whose boxes change'
146148
expect(JSON.stringify(fields)).toBe(before);
147149
});
148150
});
151+
152+
describe('withFieldBits — a roll-up acknowledgement survives a readable rewrite and never a hidden one', () => {
153+
const REASON = 'Service staff read account totals but not invoice rows';
154+
const acknowledged: FieldPerm = { readable: true, editable: true, rollupSourceUnreadableReason: REASON };
155+
156+
it('keeps the reason while the entry stays readable, and the spec accepts the entry', () => {
157+
const next = withFieldBits(acknowledged, true, false);
158+
expect(next).toEqual({ readable: true, editable: false, rollupSourceUnreadableReason: REASON });
159+
expect(FieldPermissionSchema.safeParse(next).success).toBe(true);
160+
});
161+
162+
it('drops the reason when the entry goes readable:false, the shape the spec refuses it beside', () => {
163+
// The refused shape, measured against the real schema, so the drop below is load-bearing.
164+
const refused = FieldPermissionSchema.safeParse({ readable: false, editable: false, rollupSourceUnreadableReason: REASON });
165+
expect(refused.success).toBe(false);
166+
expect(refused.error?.issues.map((i) => i.path.join('.'))).toContain('rollupSourceUnreadableReason');
167+
168+
const next = withFieldBits(acknowledged, false, false);
169+
expect(next).toEqual({ readable: false, editable: false });
170+
expect(FieldPermissionSchema.safeParse(next).success).toBe(true);
171+
});
172+
173+
it('the bulk Read-only all shortcut keeps the reason on the row it rewrites', () => {
174+
const fields = { 'deal.total': acknowledged };
175+
const next = applyFieldBulk(fields, 'deal', EDIT_ON, 'readable', ['total']);
176+
expect(next['deal.total']).toEqual({ readable: true, editable: false, rollupSourceUnreadableReason: REASON });
177+
expect(FieldPermissionSchema.safeParse(next['deal.total']).success).toBe(true);
178+
});
179+
});

‎ui/packages/app-shell/src/views/metadata-admin/permission-slice.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,16 @@ export interface FieldPerm {
188188
* off and never authors that shape.
189189
*/
190190
when?: string;
191+
/**
192+
* The authoring-time acknowledgement `os lint` reads on a set's entry for a
193+
* roll-up `summary` column (`FieldPermissionSchema` in `@objectstack/spec`):
194+
* why holders of the set are meant to read the roll-up although they cannot
195+
* read the child data it aggregates. The spec refuses it beside
196+
* `readable: false` (that entry declares no read to acknowledge), so the
197+
* matrix drops it in the same edit that switches Read off, and keeps it
198+
* whenever Read stays on.
199+
*/
200+
rollupSourceUnreadableReason?: string;
191201
}
192202

193203
/**
@@ -259,10 +269,18 @@ export function fieldRuleSeed(entry: FieldPerm | undefined, objectPerm: ObjectPe
259269
* objectstack#25866 — a bulk shortcut rewrites the two booleans and keeps an
260270
* authored row condition, so it never silently widens a conditioned entry into
261271
* an unconditioned one. Clearing a condition is its own act, in the row.
272+
*
273+
* It keeps an authored `rollupSourceUnreadableReason` while the entry stays
274+
* readable, so a shortcut never silently withdraws the acknowledgement, and
275+
* drops it only when the entry goes `readable: false`, the shape the spec
276+
* refuses it beside.
262277
*/
263278
export function withFieldBits(cur: FieldPerm | undefined, readable: boolean, editable: boolean): FieldPerm {
264279
const next: FieldPerm = { readable, editable };
265280
if (cur?.when !== undefined) next.when = cur.when;
281+
if (readable && cur?.rollupSourceUnreadableReason !== undefined) {
282+
next.rollupSourceUnreadableReason = cur.rollupSourceUnreadableReason;
283+
}
266284
return next;
267285
}
268286

0 commit comments

Comments
 (0)