Skip to content
Draft
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
14 changes: 14 additions & 0 deletions .changeset/39406-approval-snapshot-no-field-access.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@object-ui/i18n': patch
---

fix(app-shell): an approver who may read none of the submitted record's fields is told so instead of seeing an empty pane

Clause-②: no
Metadata-protocol: none

Who sees it: an approver who opens an approval request on an object they may not read, or whose fields they may not read.

- **The submitted-record card now says "You don't have access to this object's fields; ask an administrator."** where it used to draw nothing. The approver can tell an access gap from an empty submission.
- **Nothing more is shown than before.** The snapshot is still redacted for the reader, and the notice names no field and shows no value.
- New locale key `approvalsInbox.snapshotNoFieldAccess`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
//
// [#39406] An approver whose permission sets do not mention the object under
// approval is served the request's snapshot whole, keys and labels, on a real
// boot.
//
// ## Why this is pinned here
//
// The approval page draws the submitted record from the request's snapshot.
// `payload-redaction.ts` states the serve-time contract: redaction is by FIELD
// and "does not gate on OBJECT-level access", because an approver routinely has
// no read on the object they approve. The unit pins of that seam drive it with
// a stand-in field-visibility source, so nothing proved the real
// `SecurityPlugin` answers that way for a reader whose sets never name the
// object. This file does, end to end, and the page's rework (draw the served
// snapshot when the object's definition is withheld) stands on it.
//
// ## The composition
//
// `bootStack` with the real `SecurityPlugin`, `ObjectQL`, SQL driver, REST and
// auth layers, plus automation, the record-change trigger and the approvals
// plugin. One synthetic object with three plain fields; a flow routes each new
// record to a position the approver holds.
//
// - The approver's only set names `sys_approval_request` and nothing else:
// no entry for the object, no field entries.
// - The submitter holds a set that may create and read the object.
//
// ## What is asserted
//
// - The scene is real first: the stored snapshot carries every field, and the
// approver is refused the record on the data plane and the object's
// definition on the metadata plane (the reason the page has no definition).
// - The approver's inbox item and inbox list row carry every snapshot key with
// its stored value, and a label for every key (`payload_labels`).
//
// Fixtures are synthetic. `@objectstack/plugin-approvals` and
// `@objectstack/trigger-record-change` resolve to SOURCE here (this project's
// alias), so the verdict is about the checkout, not the last build.

import { describe, it, expect } from 'vitest';
import { bootStack, type VerifyStack } from '@objectstack/verify';
import { ApprovalsServicePlugin } from '@objectstack/plugin-approvals';
import { RecordChangeTriggerPlugin } from '@objectstack/trigger-record-change';
import { defineStack, defineFlow } from '@objectstack/spec';
import { ObjectSchema, Field } from '@objectstack/spec/data';
import { PermissionSetSchema } from '@objectstack/spec/security';
import { SecurityPlugin, securityDefaultPermissionSets } from '@objectstack/plugin-security';
import { catalogPermissionSet } from './catalog-permission-set.js';

const OBJECT = 'noread_order';
const POSITION = 'noread_reviewer';
const SYS = { context: { isSystem: true } } as const;

/** The record as submitted: synthetic values for every declared field. */
const SUBMITTED = { name: 'Order one', device: 'Pump 3', fault: 'Seal leaks' };
const LABELS = { name: 'Order No', device: 'Device', fault: 'Fault' };

const NoreadOrder = ObjectSchema.create({
name: OBJECT,
label: 'No-read Order',
pluralLabel: 'No-read Orders',
fields: {
name: Field.text({ label: LABELS.name, required: true }),
device: Field.text({ label: LABELS.device }),
fault: Field.text({ label: LABELS.fault }),
},
});

const NoreadFlow = defineFlow({
name: 'noread_flow',
label: 'No-read Flow',
description: 'Routes each new order to the reviewer position.',
type: 'autolaunched',
status: 'active',
nodes: [
{ id: 'start', type: 'start', label: 'On Create', config: { objectName: OBJECT, triggerType: 'record-after-create' } },
{
id: 'gate',
type: 'approval',
label: 'Gate',
config: { approvers: [{ type: 'position', value: POSITION }], behavior: 'first_response' },
},
{ id: 'approved', type: 'end', label: 'Approved' },
{ id: 'rejected', type: 'end', label: 'Rejected' },
],
edges: [
{ id: 'e1', source: 'start', target: 'gate' },
{ id: 'e2', source: 'gate', target: 'approved', label: 'approve' },
{ id: 'e3', source: 'gate', target: 'rejected', label: 'reject' },
],
});

const noreadStack = defineStack({
manifest: {
id: 'com.dogfood.snapshot-no-object-read',
namespace: 'noread',
version: '0.0.0',
type: 'app',
name: 'Snapshot No Object Read Fixture',
description: 'One object, one approval flow, an approver whose sets never name the object.',
},
// ADR-0097: the flow's record-change start node needs both capabilities.
requires: ['automation', 'triggers'],
objects: [NoreadOrder],
flows: [NoreadFlow],
});

/** Every fresh member, the approver included: the request object only. The order object is not named. */
const requestOnlySet = PermissionSetSchema.parse({
name: 'noread_request_only',
label: 'No-read request only',
objects: {
sys_approval_request: { allowRead: true, allowCreate: false, allowEdit: false, allowDelete: false },
},
});
/** The submitter: may create and read the order. */
const submitterSet = PermissionSetSchema.parse({
name: 'noread_submitter',
label: 'No-read submitter',
objects: {
[OBJECT]: { allowRead: true, allowCreate: true, allowEdit: false, allowDelete: false },
sys_approval_request: { allowRead: true, allowCreate: false, allowEdit: false, allowDelete: false },
},
});

interface Reads {
item: Record<string, unknown>;
itemLabels: Record<string, unknown>;
list: Record<string, unknown>;
listLabels: Record<string, unknown>;
}

/** The inbox item and the inbox list row, as one caller. */
async function readInboxAs(stack: VerifyStack, token: string): Promise<Reads> {
const listRes = await stack.apiAs(token, 'GET', '/approvals/requests?status=pending');
expect(listRes.status).toBe(200);
const listBody = (await listRes.json()) as { data: Array<Record<string, unknown>> };
const rows = listBody.data.filter((r) => r.object_name === OBJECT);
expect(rows).toHaveLength(1);
const itemRes = await stack.apiAs(token, 'GET', `/approvals/requests/${String(rows[0].id)}`);
expect(itemRes.status).toBe(200);
const item = (await itemRes.json()) as Record<string, unknown>;
return {
item: (item.payload ?? {}) as Record<string, unknown>,
itemLabels: (item.payload_labels ?? {}) as Record<string, unknown>,
list: (rows[0].payload ?? {}) as Record<string, unknown>,
listLabels: (rows[0].payload_labels ?? {}) as Record<string, unknown>,
};
}

describe('[#39406] an approver whose sets do not mention the object is served the snapshot whole', () => {
it(
'serves every submitted key, value and label to that approver, who is refused the record and the definition',
async () => {
const stack = await bootStack(noreadStack as unknown as Parameters<typeof bootStack>[0], {
automation: true,
security: new SecurityPlugin({
defaultPermissionSets: [...securityDefaultPermissionSets, requestOnlySet, submitterSet],
fallbackPermissionSet: requestOnlySet.name,
}),
extraPlugins: [new RecordChangeTriggerPlugin(), new ApprovalsServicePlugin()],
});
try {
const ql = (await stack.kernel.getServiceAsync('objectql')) as any;
const idOf = async (email: string) =>
String((await ql.findOne('sys_user', { where: { email }, context: { isSystem: true } }))?.id ?? '');

const submitterToken = await stack.signUp('noread-submitter@verify.test');
const approverToken = await stack.signUp('noread-approver@verify.test');
const submitterId = await idOf('noread-submitter@verify.test');
const approverId = await idOf('noread-approver@verify.test');
expect(submitterId && approverId).toBeTruthy();

// Staff the position BEFORE the record exists: the slate resolves at
// request creation, and the assignment carries the holder's
// organization, as a write through a door does.
const membership = await ql.findOne('sys_member', { where: { user_id: approverId }, context: { isSystem: true } });
await ql.insert(
'sys_user_position',
{ id: 'hold_noread_a', user_id: approverId, position: POSITION, organization_id: membership?.organization_id },
SYS,
);
const granted = await catalogPermissionSet(ql, submitterSet.name);
expect(granted, 'fixture permission set served by the security catalog').toBeTruthy();
await ql.insert('sys_user_permission_set', { user_id: submitterId, permission_set: granted.name }, SYS);

const createRes = await stack.apiAs(submitterToken, 'POST', `/data/${OBJECT}`, SUBMITTED);
expect(createRes.status).toBe(201);
const created = (await createRes.json()) as { id?: string; record?: { id?: string } };
const recordId = String(created.id ?? created.record?.id ?? '');
expect(recordId).toBeTruthy();

// The scene, before any served read is believed. The snapshot at rest
// carries every submitted field, and the request names the approver.
const atRest = await ql.findOne('sys_approval_request', { where: { object_name: OBJECT }, context: { isSystem: true } });
expect(atRest, 'the flow opened an approval request').toBeTruthy();
expect(JSON.parse(String(atRest.payload_json))).toMatchObject(SUBMITTED);

// The approver may not read the object: the record is refused on the
// data plane, and the definition is withheld on the metadata plane.
const dataRes = await stack.apiAs(approverToken, 'GET', `/data/${OBJECT}/${recordId}`);
expect(dataRes.status, 'the approver is refused the record').toBeGreaterThanOrEqual(400);
const metaRes = await stack.apiAs(approverToken, 'GET', `/meta/object/${OBJECT}`);
expect(metaRes.status, "the approver is refused the object's definition").toBe(404);
// Control: the submitter, who may read the object, is served both.
expect((await stack.apiAs(submitterToken, 'GET', `/data/${OBJECT}/${recordId}`)).status).toBe(200);
expect((await stack.apiAs(submitterToken, 'GET', `/meta/object/${OBJECT}`)).status).toBe(200);

const approver = await readInboxAs(stack, approverToken);
for (const [key, value] of Object.entries(SUBMITTED)) {
expect(approver.item[key], `inbox item serves ${key}`).toBe(value);
expect(approver.list[key], `inbox list serves ${key}`).toBe(value);
expect(approver.itemLabels[key], `inbox item labels ${key}`).toBe(LABELS[key as keyof typeof LABELS]);
expect(approver.listLabels[key], `inbox list labels ${key}`).toBe(LABELS[key as keyof typeof LABELS]);
}
} finally {
await stack.stop();
}
},
120_000,
);
});
Loading
Loading