diff --git a/.changeset/39709-approver-served-snapshot.md b/.changeset/39709-approver-served-snapshot.md new file mode 100644 index 00000000000..5393e85b72f --- /dev/null +++ b/.changeset/39709-approver-served-snapshot.md @@ -0,0 +1,16 @@ +--- +'@object-ui/app-shell': patch +'@objectstack/plugin-security': patch +--- + +fix(approvals): a pending approver whose only read of the record comes from the approval sees the submitted fields on the request page + +Clause-②: no +Metadata-protocol: none + +Who sees it: an approver whose permission sets grant no read on the object they approve, and who reads the record only because an approval step is pending on them. + +- **The request page draws the submitted record.** When the object's definition is served, the page used to filter the snapshot again by the approver's own permissions. Those grant no read of the object, so every field was dropped and the left pane stayed blank. The page now draws the snapshot as the server served it: the server has already removed the fields this reader may not read. Field permissions still narrow the page for a reader whose permission sets do grant read of the object. +- **No blank pane.** When the reader's field permissions leave no submitted field to draw, the page shows "You don't have access to this object's fields; ask an administrator." instead of an empty pane. +- **Access explanation.** For a read granted by a pending approval, the `object_crud` layer's detail now opens with that grant ("read on 'X' is granted via approval request N: …") and says after it that no permission set grants the read. It used to open with the permission sets' denial. +- The record page (`//record/`) is unchanged here. diff --git a/packages/plugins/plugin-security/src/explain-engine.ts b/packages/plugins/plugin-security/src/explain-engine.ts index fcd3e99d196..61927d1c9da 100644 --- a/packages/plugins/plugin-security/src/explain-engine.ts +++ b/packages/plugins/plugin-security/src/explain-engine.ts @@ -3440,10 +3440,13 @@ async function explainObjectPass(deps: ExplainEngineDeps, input: ExplainInput, a ? `No resolved permission set grants ${operation} on '${object}'; the business units the principal's ` + `delegated admin scope covers are read as delegated administration (ADR-0090 D12), and no other ` + `(see readFilter).` + // [#39709] A granting verdict's sentence opens with what grants it: the + // pending approval's read, then why no permission set is named. : pendingApprover !== null - ? `No resolved permission set grants ${operation} on '${object}'; the records a pending approval step ` + - `waits on the principal for are read via approval request ${pendingApprover.requestIds.join(', ')}, ` + - `and no other, until the step resolves (see readFilter).` + ? `${operation} on '${object}' is granted via approval request ${pendingApprover.requestIds.join(', ')}: ` + + `the principal may read, as a pending approver, the records the request's pending step waits on ` + + `them for, and no other, until the step resolves (see readFilter). No resolved permission set ` + + `grants ${operation} on '${object}'.` : (transferHalves ? `${operation} on '${object}' is granted: edit by [${transferHalves.edit.join(', ')}] and the transfer ` + `grant by [${transferHalves.grant.join(', ')}]` diff --git a/packages/plugins/plugin-security/src/pending-approver-read-admission.test.ts b/packages/plugins/plugin-security/src/pending-approver-read-admission.test.ts index c6bb1cf5b1b..f4ce1ed0097 100644 --- a/packages/plugins/plugin-security/src/pending-approver-read-admission.test.ts +++ b/packages/plugins/plugin-security/src/pending-approver-read-admission.test.ts @@ -216,6 +216,9 @@ describe('[#39485] one admission, answered the same way by the read door, canRea const crud = d.explained.layers.find((l: any) => l.layer === 'object_crud'); expect(crud.verdict).toBe('grants'); expect(crud.detail).toContain(`approval request ${request}`); + // [#39709] A granting verdict's sentence opens with what grants the read, + // never with the permission sets' denial. + expect(crud.detail.startsWith(`read on '${object}' is granted via approval request ${request}:`), crud.detail).toBe(true); }); it('explain of one record: the vouched row is visible, another row is not', async () => { diff --git a/ui/packages/app-shell/src/views/approval-decision/ApprovalDecisionPanel.noReadableFields-39406.test.tsx b/ui/packages/app-shell/src/views/approval-decision/ApprovalDecisionPanel.noReadableFields-39406.test.tsx index a153d0dbd79..123dbefea2a 100644 --- a/ui/packages/app-shell/src/views/approval-decision/ApprovalDecisionPanel.noReadableFields-39406.test.tsx +++ b/ui/packages/app-shell/src/views/approval-decision/ApprovalDecisionPanel.noReadableFields-39406.test.tsx @@ -23,8 +23,8 @@ * 3. definition withheld, no field served: the notice, and no field; * 4. definition served, no field served: the notice; * 5. definition served, snapshot served whole, the reader's field - * permissions deny every field: no value is drawn, and no notice either, - * because the service did serve fields. + * permissions deny every field: no value is drawn, and the notice stands in + * their place, never a blank pane (objectstack#39709). * * Controls: a definition that is absent while the reader may read the object * (a deleted object) draws nothing and claims no gap; a reader who may read @@ -90,10 +90,13 @@ function mount(opts: { payload: Record; /** What the service serves beside the snapshot. */ served?: { payload_labels?: Record; payload_display?: Record; object_label?: string }; + /** The record as the data API serves it now; absent = the read is refused. */ + currentRow?: Record; }) { const adapter = { getObjectSchema: vi.fn(async (name: string) => (name === 'repair_order' ? opts.definition : null)), findOne: vi.fn(async () => { + if (opts.currentRow) return opts.currentRow; throw Object.assign(new Error('forbidden'), { status: 403, code: 'PERMISSION_DENIED' }); }), find: vi.fn(async () => ({ data: [] })), @@ -204,13 +207,12 @@ describe('the request page draws the snapshot an approver is served (objectstack expectNoValueLeaks(panel); }); - it('5: definition served, fields served, the reader\'s field permissions deny every one: no value, and no notice', async () => { + it('5: definition served, fields served, the reader\'s field permissions deny every one: no value, and the notice in place of a blank pane (objectstack#39709)', async () => { access.readableFields = new Set(); const panel = mount({ definition: REPAIR_ORDER, payload: SUBMITTED }); - await waitFor(() => expect(within(panel).getByTestId('declared-actions-probe')).toBeTruthy()); - await new Promise((resolve) => setTimeout(resolve, 20)); + const notice = await within(panel).findByTestId('submitted-record-no-access'); + expect(notice.textContent).toBe(NOTICE); expectNoValueLeaks(panel); - expect(within(panel).queryByTestId('submitted-record-no-access')).toBeNull(); }); it('CONTROL: an absent definition the reader is allowed to read draws nothing and claims no gap', async () => { @@ -230,3 +232,99 @@ describe('the request page draws the snapshot an approver is served (objectstack expect(within(panel).queryByTestId('submitted-record-no-access')).toBeNull(); }); }); + +/** + * The read of the record comes from the pending approval, not from the + * reader's permission sets (objectstack#39709): the definition is served, the + * client's permissions hold no read of the object, so every client field + * verdict on it fails closed. The service has already redacted the snapshot + * per reader by FIELD (`payload-redaction.ts` in plugin-approvals), so the page + * draws what it was served, and narrows nothing again by a verdict that only + * says the reader's permission sets do not name the object. + */ +describe('the request page draws the served snapshot to an approver whose read comes from the approval (objectstack#39709)', () => { + beforeEach(() => { + access.objectReadable = false; + access.readableFields = new Set(); + }); + + const labelOf = (card: HTMLElement, key: string) => card.querySelector(`[data-submitted-field="${key}"] dt`)?.textContent; + const valueOf = (card: HTMLElement, key: string) => card.querySelector(`[data-submitted-field="${key}"] dd`)?.textContent; + + it('definition served, no object read, snapshot served whole: every served field, under its label, no notice', async () => { + const panel = mount({ + definition: REPAIR_ORDER, + payload: SUBMITTED, + served: { payload_labels: SERVED_LABELS, object_label: 'Repair Order' }, + }); + const card = await within(panel).findByTestId('submitted-record'); + // In the layout of the object's default record page, a long-form field last. + expect(fieldKeys(card)).toEqual(['name', 'device', 'estimate', 'fault']); + expect(labelOf(card, 'device')).toBe('Device'); + expect(labelOf(card, 'fault')).toBe('Fault'); + expect(valueOf(card, 'device')).toBe('Pump 3'); + expect(valueOf(card, 'fault')).toBe('Seal leaks'); + expect(within(panel).queryByTestId('submitted-record-no-access')).toBeNull(); + }); + + it('definition served, no object read: a field the service withheld appears nowhere', async () => { + const panel = mount({ + definition: REPAIR_ORDER, + payload: { id: 'ro_1', name: 'RO-7', device: 'Pump 3' }, + served: { payload_labels: { name: 'Order No', device: 'Device' } }, + }); + const card = await within(panel).findByTestId('submitted-record'); + expect(fieldKeys(card)).toEqual(['name', 'device']); + expect(panel.textContent).not.toContain('Seal leaks'); + expect(panel.textContent).not.toContain('1,200'); + }); + + it('definition served, no object read, no field served: the notice, and no field', async () => { + const panel = mount({ definition: REPAIR_ORDER, payload: { id: 'ro_1' } }); + const notice = await within(panel).findByTestId('submitted-record-no-access'); + expect(notice.textContent).toBe(NOTICE); + expectNoValueLeaks(panel); + }); + + it('definition served, no object read, the record read through the approval: a field changed since is marked', async () => { + const panel = mount({ + definition: REPAIR_ORDER, + payload: SUBMITTED, + currentRow: { ...SUBMITTED, device: 'Pump 4' }, + }); + const card = await within(panel).findByTestId('submitted-record'); + await waitFor(() => expect(card.getAttribute('data-current')).toBe('readable')); + const changed = [...card.querySelectorAll('[data-changed="true"]')].map((el) => el.getAttribute('data-submitted-field')); + expect(changed).toEqual(['device']); + expect(card.querySelector('[data-submitted-field="device"] [data-submitted-current]')?.textContent).toContain('Pump 4'); + }); + + it('object read, the field permissions withhold every declared field and leave an undeclared key: the notice, never a blank pane', async () => { + access.objectReadable = true; + access.readableFields = new Set(['legacy_note']); + const panel = mount({ definition: REPAIR_ORDER, payload: { ...SUBMITTED, legacy_note: 'kept' } }); + const notice = await within(panel).findByTestId('submitted-record-no-access'); + expect(notice.textContent).toBe(NOTICE); + expectNoValueLeaks(panel); + }); + + it('CONTROL: object read, a snapshot of undeclared keys only, nothing withheld: nothing drawn and no gap claimed', async () => { + access.objectReadable = true; + access.readableFields = new Set(['legacy_note']); + const panel = mount({ definition: REPAIR_ORDER, payload: { id: 'ro_1', legacy_note: 'kept' } }); + await waitFor(() => expect(within(panel).getByTestId('declared-actions-probe')).toBeTruthy()); + await new Promise((resolve) => setTimeout(resolve, 20)); + expect(within(panel).queryByTestId('submitted-record')).toBeNull(); + expect(within(panel).queryByTestId('submitted-record-no-access')).toBeNull(); + }); + + it('CONTROL: object read, the reader\'s field permissions deny one served field: that field is not drawn, the rest are', async () => { + access.objectReadable = true; + access.readableFields = new Set(['name', 'device', 'estimate']); + const panel = mount({ definition: REPAIR_ORDER, payload: SUBMITTED }); + const card = await within(panel).findByTestId('submitted-record'); + expect(fieldKeys(card)).toEqual(['name', 'device', 'estimate']); + expect(panel.textContent).not.toContain('Seal leaks'); + expect(within(panel).queryByTestId('submitted-record-no-access')).toBeNull(); + }); +}); diff --git a/ui/packages/app-shell/src/views/approval-decision/SubmittedRecord.tsx b/ui/packages/app-shell/src/views/approval-decision/SubmittedRecord.tsx index 36df40e32d6..1a5db719f39 100644 --- a/ui/packages/app-shell/src/views/approval-decision/SubmittedRecord.tsx +++ b/ui/packages/app-shell/src/views/approval-decision/SubmittedRecord.tsx @@ -63,12 +63,18 @@ * * A field is drawn when the object declares it, it is not `hidden: true`, it * is not framework bookkeeping (`isSystemManagedField`), and at least one of - * the two rows serves it to this reader. Both rows pass through - * `withoutDeniedFields` with the reader's field permissions first, as every - * surface that draws a whole row does (objectui#10594), and the service has - * already redacted the snapshot per reader. So a field the reader may not read - * is never drawn, from either row. A field whose value is empty is drawn with - * the empty placeholder, so the reader sees that it was submitted empty. + * the two rows serves it to this reader. The service has already redacted the + * snapshot per reader by field, and the data API serves the current row the + * same way. Where the reader's permissions grant read of the object, both rows + * also pass through `withoutDeniedFields` with the reader's field + * permissions, as every surface that draws a whole row does (objectui#10594): + * those verdicts are the ones the service applied. Where they grant no read of + * the object, the read comes from the pending approval (see "Read through the + * approval" below), every client field verdict on the object fails closed + * only because the reader's permission sets do not name it, and the rows are + * drawn as served. So a field the service withholds is never drawn, from + * either row. A field whose value is empty is drawn with the empty + * placeholder, so the reader sees that it was submitted empty. * * Each value is drawn through the record page's own cell for its type. A * reference the service resolved is drawn by `payload_display`, the name the @@ -87,6 +93,17 @@ * Add, edit, delete or row action: the request page never edits the record. * They are drawn only once the record itself read. * + * ## Read through the approval: the snapshot as served + * + * A pending approver routinely holds no read of the object they approve; the + * approval is what lets them read it (the snapshot, and the record itself + * while the step is pending). The reader's own permissions then answer no + * read of the object, and every field verdict on it fails closed. Those + * verdicts describe the data API's rule for the reader's permission sets, not + * the approval's door, so they narrow nothing here (objectstack#39709): the + * served definition draws the rows as the service served them, already + * redacted by field for this reader. + * * ## A withheld definition: the snapshot as served * * The service serves the snapshot redacted by FIELD and does not gate it on @@ -106,14 +123,17 @@ * definition that is absent while the reader may read the object draws * nothing, as before. * - * ## The notice: the service served no field + * ## The notice: no served field is left to draw * - * When the service served no field of the snapshot (framework bookkeeping + * When no field of the snapshot is left for the reader (framework bookkeeping * aside), the card says so in place of the fields: "You don't have access to - * this object's fields; ask an administrator." It appears on that condition - * alone ({@link SubmittedRecordModel.noFieldAccess}), with or without the - * definition. A snapshot that holds only keys the object does not declare is - * a served snapshot: the card draws nothing for it and claims no gap. + * this object's fields; ask an administrator." It appears when the service + * served no field, with or without the definition, and when the reader's + * field permissions withheld what it served so that nothing is left to draw + * ({@link SubmittedRecordModel.noFieldAccess}): a pane narrowed to nothing is + * never left blank. A snapshot that holds only keys the object does not + * declare, with nothing withheld, is a served snapshot: the card draws + * nothing for it and claims no gap. * * Module-internal: nothing re-exports it from the package entry. */ @@ -171,8 +191,8 @@ export interface SubmittedRecordModel { plan: SubmittedRecordPlan; current: CurrentRecordState; /** - * The service served no field of the snapshot (see "The notice" above): the - * card draws the notice in place of the fields. + * No served field of the snapshot is left for the reader (see "The notice" + * above): the card draws the notice in place of the fields. */ noFieldAccess: boolean; /** @@ -332,10 +352,13 @@ export function useSubmittedRecord(request: { const labels = request.payload_labels ?? undefined; const objectLabel = typeof request.object_label === 'string' && request.object_label !== '' ? request.object_label : undefined; + // The reader's permissions grant no read of the object: what they read of + // it comes from the approval (see "Read through the approval" above). + const readThroughApproval = target !== null && perms?.isLoaded === true && !perms.can(target, 'read'); // The definition is withheld because the reader may not read the object, // not because it is still loading or names no object. const definitionWithheld = target !== null && hasSnapshot && objectDef === null && !definitionLoading - && perms?.isLoaded === true && !perms.can(target, 'read'); + && readThroughApproval; return React.useMemo(() => { if (target === null || !hasSnapshot) return null; @@ -343,13 +366,18 @@ export function useSubmittedRecord(request: { if (!definitionWithheld) return null; return servedModel(target, recordId, payload as Record, labels, objectLabel, display, current); } - const snapshot = withoutDeniedFields(payload as Record, perms, target); - const currentRow = current.status === 'readable' ? withoutDeniedFields(current.row, perms, target) : null; + const served = payload as Record; + const asServed = (row: T): T => (readThroughApproval ? row : withoutDeniedFields(row, perms, target)); + const snapshot = asServed(served); + const currentRow = current.status === 'readable' ? asServed(current.row) : null; const sections = resolveSections(objectDef, sectionLabel, t); const plan = planSubmittedRecord(sections, objectDef.fields, snapshot, currentRow); - const noFieldAccess = servedFieldKeys(payload as Record).length === 0; + const left = servedFieldKeys(snapshot); + const withheld = left.length < servedFieldKeys(served).length; + const drawsNothing = plan.sections.length === 0 && plan.attachments.length === 0; + const noFieldAccess = left.length === 0 || (withheld && drawsNothing); return { objectName: target, recordId, objectDef, snapshot, display, plan, current, noFieldAccess, face: 'declared' }; - }, [target, recordId, objectDef, definitionWithheld, hasSnapshot, payload, perms, current, sectionLabel, t, display, labels, objectLabel]); + }, [target, recordId, objectDef, definitionWithheld, readThroughApproval, hasSnapshot, payload, perms, current, sectionLabel, t, display, labels, objectLabel]); } /**