Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/34786-matrix-rollup-reason.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, FieldEntry>;
Expand Down Expand Up @@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
});
});
18 changes: 18 additions & 0 deletions ui/packages/app-shell/src/views/metadata-admin/permission-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}

Expand Down
Loading