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
15 changes: 15 additions & 0 deletions .changeset/33343-record-page-member-meta-404.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@object-ui/app-shell': patch
---

fix(app-shell): a member's record page asks no object definition the metadata door would answer as absent

Clause-②: no
Metadata-protocol: none

A member (a caller with no administrator grant) opening a record page logged two `404`s, `GET /api/v1/meta/object/sys_business_unit` and `GET /api/v1/meta/object/sys_comment_reaction`. The metadata door serves an object's definition only to a caller its read check admits, and answers any other caller as if the object did not exist; the stock member grants hold no read on either object, so both answers are correct, and the page should not have asked.

- The record and list routes ask the definitions of their object's lookup targets, for the cells that link and name them. They no longer ask the target of a field declared `hidden: true`, which no cell draws. That includes the system scope fields the platform adds to an object (`organization_id` and `owning_business_unit_id`), which point at `sys_organization` and `sys_business_unit`; those two reads are gone for every caller.
- The record page asks whether the deployment has `sys_comment_reaction` to choose where reactions are stored. A caller whose loaded grants hold no read on that object is no longer asked: it takes the reactions path the absent answer took before. With no permission provider mounted, the page asks as before.

Nothing a member or an administrator sees on the page changes, and no server answer changes.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const OBJECTS = [
{ name: 'sys_user', _packageId: 'plugin.auth', fields: {} },
];

function makeAdapter(calls: string[], apps: unknown[]) {
function makeAdapter(calls: string[], apps: unknown[], objects: readonly { name: string }[] = OBJECTS) {
return {
clearCache: vi.fn(),
invalidateCache: vi.fn(),
Expand All @@ -53,13 +53,13 @@ function makeAdapter(calls: string[], apps: unknown[]) {
meta: {
getItems: (type: string, options?: { packageId?: string }) => {
calls.push(options?.packageId ? `${type}?package=${options.packageId}` : type);
const all = type === 'object' ? OBJECTS : type === 'app' ? apps : [];
const all = type === 'object' ? objects : type === 'app' ? apps : [];
const items = options?.packageId ? all.filter((o: any) => o._packageId === options.packageId) : all;
return Promise.resolve({ type, items: structuredClone(items) });
},
getItem: (type: string, name: string) => {
calls.push(`${type}/${name}`);
const item = (type === 'object' ? OBJECTS : []).find((o) => o.name === name);
const item = (type === 'object' ? objects : []).find((o) => o.name === name);
return item ? Promise.resolve({ item: structuredClone(item) }) : Promise.reject(new Error('404'));
},
},
Expand All @@ -72,12 +72,12 @@ function Prefetch() {
return null;
}

function mount(url: string, apps: unknown[]): string[] {
function mount(url: string, apps: unknown[], objects?: readonly { name: string }[]): string[] {
// Each mount reads its own app list, not the one a previous mount cached.
sessionStorage.clear();
const calls: string[] = [];
render(
<MetadataProvider adapter={makeAdapter(calls, apps)}>
<MetadataProvider adapter={makeAdapter(calls, apps, objects)}>
<MemoryRouter initialEntries={[url]}>
<Prefetch />
</MemoryRouter>
Expand Down Expand Up @@ -251,3 +251,43 @@ describe('objectstack#29551 — a packaged app asks its lookup targets without v
expect(scope()).toBe('crm_account[crm_account.all],crm_contact[crm_contact.all]');
});
});

describe('objectstack#33343 — a hidden lookup asks no definition of its target', () => {
/**
* The route object carries the injected system scope anchors as the server
* serves them: `organization_id` and `owning_business_unit_id`, hidden
* lookups to `sys_organization` and `sys_business_unit`. No cell draws a
* hidden field, and the metadata door answers a definition the caller may
* not read as absent, so a member was answered 404 on every route.
*/
const withAnchors = (hidden: boolean) => [
{
name: 'crm_account',
_packageId: CRM,
fields: {
owner: { type: 'lookup', reference: 'sys_user' },
organization_id: { type: 'lookup', reference: 'sys_organization', hidden, system: true },
owning_business_unit_id: { type: 'lookup', reference: 'sys_business_unit', hidden, system: true },
},
},
{ name: 'sys_user', _packageId: 'plugin.auth', fields: {} },
{ name: 'sys_organization', _packageId: 'plugin.auth', fields: {} },
{ name: 'sys_business_unit', _packageId: 'plugin.security', fields: {} },
];

it('the route asks its drawn lookup target by name, and never the targets of its hidden lookups', async () => {
const calls = mount('/apps/crm/crm_account', APPS, withAnchors(true));
await waitFor(() => expect(calls).toContain('object/sys_user'));
await new Promise((resolve) => setTimeout(resolve, 50));
expect(objectCalls(calls)).toEqual([`object?package=${CRM}`, 'object/sys_user']);
});

it('CONTROL: the same lookups drawn ask every target by name', async () => {
const calls = mount('/apps/crm/crm_account', APPS, withAnchors(false));
await waitFor(() => expect(calls).toContain('object/sys_business_unit'));
await new Promise((resolve) => setTimeout(resolve, 50));
expect([...objectCalls(calls)].sort()).toEqual(
[`object?package=${CRM}`, 'object/sys_business_unit', 'object/sys_organization', 'object/sys_user'].sort(),
);
});
});
14 changes: 13 additions & 1 deletion ui/packages/app-shell/src/console/appObjectScope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,12 +430,24 @@ function hasRecordFormOverlay(search: string): boolean {
return sp.has(RECORD_FORM_PARAM) || sp.has(RECORD_FORM_OBJECT_PARAM);
}

/** The objects an object's lookup and master-detail fields point at. */
/**
* The objects an object's drawn lookup and master-detail fields point at.
*
* A target is read for the cell that links and names it, so a field declared
* `hidden: true` asks for none: no surface this scope serves draws it. That
* includes the injected system scope anchors (`organization_id` and
* `owning_business_unit_id`), which point at `sys_organization` and
* `sys_business_unit` from every object; asking their definitions read nothing
* a page draws, and for a caller the object read check refuses, the metadata
* door answers that definition as absent (ADR-0106 as amended by ruling record
* 6787890900), so the read answered 404 on every route of every object.
*/
function lookupTargetNames(def: any): string[] {
const fields = def?.fields;
const defs: any[] = Array.isArray(fields) ? fields : Object.values((fields ?? {}) as Record<string, any>);
const out = new Set<string>();
for (const field of defs) {
if (field?.hidden === true) continue;
if ((field?.type === 'lookup' || field?.type === 'master_detail') && typeof field.reference === 'string' && field.reference) {
out.add(field.reference);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,68 @@ describe('on the column store the reaction control reads feedReactionColumn: upd
expect(!!addReaction(view)).toBe(offered);
});
});

/**
* Which store the chatter uses is asked of the object registry only by a
* caller who may read `sys_comment_reaction` (objectstack#33343). The metadata
* door serves an object's definition only to a caller its read check admits,
* so a caller whose grants hold no read on the object was answered 404 on every
* record page; that answer took the column store. Here the registry is the
* by-name scope reader, which records each name the page asks.
*/
describe('the reaction store is asked of the registry only by a caller who may read sys_comment_reaction (objectstack#33343)', () => {
/** Mounts the page over a by-name registry; returns the object names it was asked. */
async function mountAsking(perms: MePermissionsResponse | null, registry: unknown[], dataSource = makeDataSource()) {
const asked: string[] = [];
const pages = [PAGE];
const readObjectScope = (scope: { packageId?: string; names?: readonly string[] }) => {
asked.push(...(scope.names ?? []).filter((name) => typeof name === 'string' && name !== ''));
const served = scope.names
? registry.filter((o) => scope.names!.includes((o as { name: string }).name))
: registry;
return { objects: served, served, missing: [], settled: true, failed: [], refused: {}, answers: {}, views: [] };
};
const metadata = {
...metadataFor(registry),
readObjectScope,
getTypeStatus: (type: string) => (type === 'object' ? 'idle' : 'ready'),
ensureType: async () => pages,
} as any;
const page = (
<MemoryRouter initialEntries={[`/app/demo/${OBJECT_NAME}/${RECORD_ID}`]}>
<MetadataCtx.Provider value={metadata}>
<RecordDetailView
dataSource={dataSource}
objects={OBJECTS}
onEdit={() => {}}
objectNameOverride={OBJECT_NAME}
recordIdOverride={RECORD_ID}
embedded
/>
</MetadataCtx.Provider>
</MemoryRouter>
);
const view = render(perms ? <MePermissionsProvider initialPermissions={perms}>{page}</MePermissionsProvider> : page);
await within(view.container).findByText(COMMENT_BODY);
await act(async () => {});
const reactionReads = dataSource.find.mock.calls.filter(([objectName]: [string]) => objectName === REACTION);
return { asked, reactionReads };
}

it('a caller whose grants hold no read on sys_comment_reaction is not asked about it, and takes the column store its absence took', async () => {
const { asked, reactionReads } = await mountAsking(answer({ [COMMENT]: SHAPE.full }), REGISTRY.column);
expect(asked).not.toContain(REACTION);
expect(reactionReads).toEqual([]);
});

it('CONTROL — a caller who may read it asks the registry, and the records store reads its rows', async () => {
const { asked, reactionReads } = await mountAsking(answer({ [COMMENT]: SHAPE.full, [REACTION]: SHAPE.readOnly }), REGISTRY.records);
expect(asked).toContain(REACTION);
expect(reactionReads).toHaveLength(1);
});

it('CONTROL — with no permission provider every grant reads open: the registry is asked, as before', async () => {
const { asked } = await mountAsking(null, REGISTRY.records);
expect(asked).toContain(REACTION);
});
});
22 changes: 16 additions & 6 deletions ui/packages/app-shell/src/views/RecordDetailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3176,12 +3176,22 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
// path, and every uncertain answer takes the records path. `null` until the
// registry has answered, and the feed read waits for it: comments and their
// reactions are read as one answer.
const reactionPresence = useObjectPresence(COMMENT_REACTION_OBJECT);
const reactionStore: 'records' | 'column' | null = !reactionPresence.settled
? null
: reactionPresence.presence === 'absent'
? 'column'
: 'records';
//
// A caller whose loaded grants hold no read on the object is not asked about
// it: the metadata door serves an object's definition only to a caller its
// read check admits (ADR-0106 as amended by ruling record 6787890900), and
// the object declares no `schemaReadDelegate`, so that read could only
// answer absent (a 404 on every record page). It takes the path that answer
// takes. With no permission provider every grant reads open, as before.
const reactionReadRefused = perms.isLoaded && !perms.can(COMMENT_REACTION_OBJECT, 'read');
const reactionPresence = useObjectPresence(reactionReadRefused ? '' : COMMENT_REACTION_OBJECT);
const reactionStore: 'records' | 'column' | null = reactionReadRefused
? 'column'
: !reactionPresence.settled
? null
: reactionPresence.presence === 'absent'
? 'column'
: 'records';
/**
* The signed-in user's own reaction rows, per comment (`[thread, comment]`)
* and emoji: the row id a click that takes the reaction back deletes. Filled
Expand Down
Loading