Skip to content

Commit 867962a

Browse files
committed
fix(app-shell): Save as my view is not offered over a list the reader cannot read
The switcher's Save also needs the list's own object read, under the same unloaded-grants rule as the sys_personal_view grant. The write census grades the two personal-view writes (save, rename) as the caller's own rows. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jVTq2EZveNYXjHFxWS
1 parent cf6a7cc commit 867962a

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

‎ui/packages/app-shell/src/views/ObjectView.personalViews-29635.test.tsx‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ import { MemoryRouter, Routes, Route } from 'react-router-dom';
3434
import { createI18n, I18nProvider } from '@object-ui/i18n';
3535
import { ListViewSchema } from '@objectstack/spec/ui';
3636

37+
/**
38+
* The reader's grants. Unloaded (every action allowed) unless a case loads
39+
* them; `denied` lists the `object:action` pairs a loaded set refuses.
40+
*/
41+
const grants = vi.hoisted(() => ({ isLoaded: false, denied: new Set<string>() }));
42+
3743
vi.mock('@object-ui/permissions', async (importOriginal) => {
3844
const actual = await importOriginal<typeof import('@object-ui/permissions')>();
3945
// Stable identities — `ListView` names `perms` in its fetch dependencies.
@@ -44,10 +50,10 @@ vi.mock('@object-ui/permissions', async (importOriginal) => {
4450
getRowFilter: () => undefined,
4551
getObjectApiOperations: () => undefined,
4652
roles: [],
47-
isLoaded: false,
53+
get isLoaded() { return grants.isLoaded; },
4854
hasCapabilities: () => true,
49-
can: () => true,
50-
cannot: () => false,
55+
can: (object: string, action: string) => !grants.denied.has(`${object}:${action}`),
56+
cannot: (object: string, action: string) => grants.denied.has(`${object}:${action}`),
5157
};
5258
const fieldPerms = { canRead: () => true, canWrite: () => true, permissions: [] };
5359
return { ...actual, usePermissions: () => perms, useFieldPermissions: () => fieldPerms };
@@ -196,6 +202,8 @@ const leadReads = (dataSource: ReturnType<typeof mountLeads>['dataSource']) =>
196202
.map(([, params]) => params);
197203

198204
beforeEach(() => {
205+
grants.isLoaded = false;
206+
grants.denied.clear();
199207
localStorage.clear();
200208
fetchCalls.length = 0;
201209
Object.defineProperty(window, 'innerWidth', { value: 1440, configurable: true, writable: true });
@@ -349,4 +357,24 @@ describe('objectstack#29635 — My views in the list view switcher', () => {
349357
expect(within(menu).queryByTestId('list-view-switcher-save-mine')).toBeNull();
350358
expect(sectionRowIds('list-view-switcher-all')).toEqual(['v1', 'v2']);
351359
});
360+
361+
it('a reader who may save a view but cannot read the list\'s object is not offered Save as my view', async () => {
362+
grants.isLoaded = true;
363+
grants.denied.add('crm_lead:read');
364+
mountLeads('/apps/crm/crm_lead/view/v1');
365+
await listToolbar();
366+
const menu = openSwitcher();
367+
// The reader's own views were read: the section is drawn, Save is not.
368+
await waitFor(() => expect(within(menu).getByTestId('list-view-switcher-mine')).toBeInTheDocument());
369+
expect(within(menu).queryByTestId('list-view-switcher-save-mine')).toBeNull();
370+
});
371+
372+
it('CONTROL: with the same loaded grants and the list\'s object readable, Save as my view is offered', async () => {
373+
grants.isLoaded = true;
374+
mountLeads('/apps/crm/crm_lead/view/v1');
375+
await listToolbar();
376+
const menu = openSwitcher();
377+
await waitFor(() => expect(within(menu).getByTestId('list-view-switcher-mine')).toBeInTheDocument());
378+
expect(within(menu).getByTestId('list-view-switcher-save-mine')).toBeInTheDocument();
379+
});
352380
});

‎ui/packages/app-shell/src/views/ObjectView.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,9 +734,11 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
734734
// objectstack#29635 — Save as my view, and Rename and Delete on the
735735
// reader's own views. Save is offered to any reader the server lets save
736736
// one (`sys_personal_view` read and create), not to admins only; the name
737-
// is asked in `PersonalViewNameDialog`.
737+
// is asked in `PersonalViewNameDialog`. A reader who cannot read the
738+
// list's own object is offered no Save: there is no list to keep.
738739
const personalViewsReady = personalViews.status === 'ready';
739740
const personalGrant = (action: 'create' | 'update') => !perms.isLoaded || perms.can(PERSONAL_VIEW_OBJECT, action);
741+
const listReadable = !perms.isLoaded || perms.can(objectDef.name, 'read');
740742
const [personalViewDialog, setPersonalViewDialog] = useState<{ mode: 'save' } | { mode: 'rename'; viewId: string } | null>(null);
741743
const openPersonalView = (id: string) => {
742744
if (viewId) navigate(`../${id}`, { relative: 'path' });
@@ -949,7 +951,7 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
949951
appSegment: appName,
950952
viewTotal,
951953
personalViewIds,
952-
onSavePersonalView: personalViewsReady && personalGrant('create') && !!activeView && !viewAccess.refusal
954+
onSavePersonalView: personalViewsReady && personalGrant('create') && listReadable && !!activeView && !viewAccess.refusal
953955
? () => setPersonalViewDialog({ mode: 'save' })
954956
: undefined,
955957
onRenamePersonalView: personalViewsReady && personalGrant('update')

‎ui/packages/plugin-form/src/affordanceGrantMap-12082.test.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,11 @@ const WRITE_SITES: Record<string, WriteSite> = {
734734
// record; the list page draws Clone only when that create's row is held.
735735
'packages/app-shell/src/views/metadata-admin/SharingRuleCloneDialog.tsx :: SharingRuleCloneDialog > submit :: create':
736736
mapped(['declarationClone'], RESOURCE_LIST_PAGE),
737+
// The reader's own list views (My views); the delete goes through the owner's door, not a data source.
738+
'packages/app-shell/src/views/personalViews.ts :: usePersonalViews > save :: create':
739+
outOfFamily("the caller's OWN sys_personal_view row (Save as my view), offered behind perms.can(sys_personal_view, create) in ObjectView; the server keeps the rows owner-scoped; no record the caller browses is written"),
740+
'packages/app-shell/src/views/personalViews.ts :: usePersonalViews > rename :: update':
741+
outOfFamily("the caller's OWN sys_personal_view row (Rename), offered behind perms.can(sys_personal_view, update) in ObjectView; the server keeps the rows owner-scoped and fixes the owner; no record the caller browses is written"),
737742
// ── core ──
738743
'packages/core/src/actions/TransactionManager.ts :: TransactionManager > executeBatch :: batch':
739744
door('the action engine\'s transaction executor runs the operations its caller hands it'),

0 commit comments

Comments
 (0)