diff --git a/.changeset/34786-matrix-rollup-reason.md b/.changeset/34786-matrix-rollup-reason.md new file mode 100644 index 00000000000..367e5b1961b --- /dev/null +++ b/.changeset/34786-matrix-rollup-reason.md @@ -0,0 +1,13 @@ +--- +'@object-ui/app-shell': patch +--- + +fix(app-shell): the permission matrix drops a roll-up acknowledgement when Read goes off and keeps it otherwise + +Clause-②: no +Metadata-protocol: none + +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`. + +- 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. +- 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. diff --git a/ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.fieldWhen-25866.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.fieldWhen-25866.test.tsx index 2de30e08d38..5538c15baa4 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.fieldWhen-25866.test.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.fieldWhen-25866.test.tsx @@ -19,11 +19,13 @@ import { MemoryRouter } from 'react-router-dom'; import '@objectstack/formula'; import '@objectstack/lint'; import '@objectstack/spec/identity'; +import { FieldPermissionSchema } from '@objectstack/spec/security'; interface FieldEntry { readable?: boolean; editable?: boolean; when?: string; + rollupSourceUnreadableReason?: string; } interface SavedSet { fields?: Record; @@ -201,3 +203,37 @@ describe('a field row offers a row condition on its edit vote (objectstack#25866 expect(set.fields?.['a_account.amount']).toEqual({ readable: true, editable: false, when: "status == 'approved'" }); }); }); + +/** + * The roll-up acknowledgement (`rollupSourceUnreadableReason`) rides the same + * cascade as the row condition: the spec refuses it beside `readable: false`, + * so Read off removes it in the same edit, and a bulk shortcut that keeps the + * row readable keeps it. + */ +describe('a field row keeps a roll-up acknowledgement only while Read is on', () => { + const REASON = 'Service staff read account totals but not invoice rows'; + + it('Read off removes the reason, so the saved entry is one the spec accepts', async () => { + await renderExpanded({ 'a_account.revenue': { readable: true, editable: false, rollupSourceUnreadableReason: REASON } }); + + fireEvent.click(screen.getByLabelText('a_account.revenue readable')); + expect(screen.getByLabelText('a_account.revenue readable')).not.toBeChecked(); + + const set = await saveAfter(0); + const entry = set.fields?.['a_account.revenue']; + expect(entry).toEqual({ readable: false, editable: false }); + expect(FieldPermissionSchema.safeParse(entry).success).toBe(true); + }); + + it('Write all keeps the reason on a row it rewrites, and the spec accepts the entry', async () => { + await renderExpanded({ 'a_account.revenue': { readable: true, editable: false, rollupSourceUnreadableReason: REASON } }); + + fireEvent.click(screen.getByRole('button', { name: 'Write all' })); + expect(screen.getByLabelText('a_account.revenue editable')).toBeChecked(); + + const set = await saveAfter(0); + const entry = set.fields?.['a_account.revenue']; + expect(entry).toEqual({ readable: true, editable: true, rollupSourceUnreadableReason: REASON }); + expect(FieldPermissionSchema.safeParse(entry).success).toBe(true); + }); +}); diff --git a/ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.tsx b/ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.tsx index 39dba908e62..543c7767fb8 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.tsx @@ -1493,12 +1493,14 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved, // draws (the object grant), so the click changes only the box it lands on. const cur = fieldRuleSeed(fields[key], drawnObjectPerm(prev, objectName)); const next: FieldPerm = { ...cur, [action]: value }; - // Cascade: !readable implies !editable — and no row condition: the spec - // refuses `when` beside `readable: false` (objectstack#25866), so Read - // off clears the condition instead of authoring the refused shape. + // Cascade: !readable implies !editable — and no row condition and no + // roll-up acknowledgement: the spec refuses `when` (objectstack#25866) + // and `rollupSourceUnreadableReason` beside `readable: false`, so Read + // off clears both instead of authoring the refused shape. if (action === 'readable' && !value) { next.editable = false; delete next.when; + delete next.rollupSourceUnreadableReason; } // Cascade: editable implies readable. if (action === 'editable' && value) next.readable = true; diff --git a/ui/packages/app-shell/src/views/metadata-admin/permission-slice.fieldRule-26597.test.ts b/ui/packages/app-shell/src/views/metadata-admin/permission-slice.fieldRule-26597.test.ts index 93a5242e113..5768c9ae95c 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/permission-slice.fieldRule-26597.test.ts +++ b/ui/packages/app-shell/src/views/metadata-admin/permission-slice.fieldRule-26597.test.ts @@ -14,10 +14,12 @@ */ import { describe, expect, it } from 'vitest'; +import { FieldPermissionSchema } from '@objectstack/spec/security'; import { applyFieldBulk, fieldRuleCell, fieldRuleSeed, + withFieldBits, type FieldPerm, type ObjectPerm, } from './permission-slice'; @@ -146,3 +148,32 @@ describe('applyFieldBulk — a shortcut writes only the rows whose boxes change' expect(JSON.stringify(fields)).toBe(before); }); }); + +describe('withFieldBits — a roll-up acknowledgement survives a readable rewrite and never a hidden one', () => { + const REASON = 'Service staff read account totals but not invoice rows'; + const acknowledged: FieldPerm = { readable: true, editable: true, rollupSourceUnreadableReason: REASON }; + + it('keeps the reason while the entry stays readable, and the spec accepts the entry', () => { + const next = withFieldBits(acknowledged, true, false); + expect(next).toEqual({ readable: true, editable: false, rollupSourceUnreadableReason: REASON }); + expect(FieldPermissionSchema.safeParse(next).success).toBe(true); + }); + + it('drops the reason when the entry goes readable:false, the shape the spec refuses it beside', () => { + // The refused shape, measured against the real schema, so the drop below is load-bearing. + const refused = FieldPermissionSchema.safeParse({ readable: false, editable: false, rollupSourceUnreadableReason: REASON }); + expect(refused.success).toBe(false); + expect(refused.error?.issues.map((i) => i.path.join('.'))).toContain('rollupSourceUnreadableReason'); + + const next = withFieldBits(acknowledged, false, false); + expect(next).toEqual({ readable: false, editable: false }); + expect(FieldPermissionSchema.safeParse(next).success).toBe(true); + }); + + it('the bulk Read-only all shortcut keeps the reason on the row it rewrites', () => { + const fields = { 'deal.total': acknowledged }; + const next = applyFieldBulk(fields, 'deal', EDIT_ON, 'readable', ['total']); + expect(next['deal.total']).toEqual({ readable: true, editable: false, rollupSourceUnreadableReason: REASON }); + expect(FieldPermissionSchema.safeParse(next['deal.total']).success).toBe(true); + }); +}); diff --git a/ui/packages/app-shell/src/views/metadata-admin/permission-slice.ts b/ui/packages/app-shell/src/views/metadata-admin/permission-slice.ts index ff4fd96559e..5206a2968c7 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/permission-slice.ts +++ b/ui/packages/app-shell/src/views/metadata-admin/permission-slice.ts @@ -188,6 +188,16 @@ export interface FieldPerm { * off and never authors that shape. */ when?: string; + /** + * The authoring-time acknowledgement `os lint` reads on a set's entry for a + * roll-up `summary` column (`FieldPermissionSchema` in `@objectstack/spec`): + * why holders of the set are meant to read the roll-up although they cannot + * read the child data it aggregates. The spec refuses it beside + * `readable: false` (that entry declares no read to acknowledge), so the + * matrix drops it in the same edit that switches Read off, and keeps it + * whenever Read stays on. + */ + rollupSourceUnreadableReason?: string; } /** @@ -259,10 +269,18 @@ export function fieldRuleSeed(entry: FieldPerm | undefined, objectPerm: ObjectPe * objectstack#25866 — a bulk shortcut rewrites the two booleans and keeps an * authored row condition, so it never silently widens a conditioned entry into * an unconditioned one. Clearing a condition is its own act, in the row. + * + * It keeps an authored `rollupSourceUnreadableReason` while the entry stays + * readable, so a shortcut never silently withdraws the acknowledgement, and + * drops it only when the entry goes `readable: false`, the shape the spec + * refuses it beside. */ export function withFieldBits(cur: FieldPerm | undefined, readable: boolean, editable: boolean): FieldPerm { const next: FieldPerm = { readable, editable }; if (cur?.when !== undefined) next.when = cur.when; + if (readable && cur?.rollupSourceUnreadableReason !== undefined) { + next.rollupSourceUnreadableReason = cur.rollupSourceUnreadableReason; + } return next; }