From f2c45d38634a75c03a6952794e8e04833329cffa Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 21:40:55 +0000 Subject: [PATCH 1/2] fix(console): offer view management on manage_metadata, not isAdmin alone Manage views, the view settings panel, Create View (list page and the data page's Save as view) and a saved shared view's rename and save in place all lead to a view metadata write the server refuses without manage_metadata. They now read mayManageViews(isAdmin, useCanAuthorMetadata()), the answer the Shared choice already reads. Claude-Session: https://claude.ai/code/session_01JQwxbYXZHUaaZK86HquGRP Co-authored-by: Claude --- ...tDataPage.saveAsViewRefusal-11578.test.tsx | 37 ++- .../app-shell/src/views/ObjectDataPage.tsx | 13 +- .../app-shell/src/views/ObjectView.tsx | 35 +-- ...jectView.viewManagementGate-36448.test.tsx | 226 ++++++++++++++++++ .../src/views/objectViewPluginSchema.ts | 15 +- ...wRecordNavigation.phonePush-29074.test.tsx | 2 +- .../src/views/objectViewTitleSwitcher.tsx | 15 +- .../src/views/objectViewViewSharing.test.tsx | 10 +- .../src/views/objectViewViewSharing.ts | 20 +- 9 files changed, 332 insertions(+), 41 deletions(-) create mode 100644 ui/packages/app-shell/src/views/ObjectView.viewManagementGate-36448.test.tsx diff --git a/ui/packages/app-shell/src/views/ObjectDataPage.saveAsViewRefusal-11578.test.tsx b/ui/packages/app-shell/src/views/ObjectDataPage.saveAsViewRefusal-11578.test.tsx index c38b187ac57..d47d0872ddd 100644 --- a/ui/packages/app-shell/src/views/ObjectDataPage.saveAsViewRefusal-11578.test.tsx +++ b/ui/packages/app-shell/src/views/ObjectDataPage.saveAsViewRefusal-11578.test.tsx @@ -93,6 +93,8 @@ function wire() { }); } let client: MetadataClient; +/** objectstack#36448 — the principal's `manage_metadata` answer, set per case. */ +const viewer = vi.hoisted(() => ({ canAuthorMetadata: true })); vi.mock('./metadata-admin/useMetadata', async (importOriginal) => ({ ...(await importOriginal>()), @@ -110,10 +112,14 @@ vi.mock('@object-ui/permissions', async (importOriginal) => { useFieldPermissions: () => ({ canRead: () => true, canWrite: () => true, permissions: [] }), }; }); +vi.mock('../hooks/useCanAuthorMetadata', async (importOriginal) => ({ + ...(await importOriginal>()), + useCanAuthorMetadata: () => viewer.canAuthorMetadata, +})); vi.mock('@object-ui/auth', async (importOriginal) => ({ ...(await importOriginal>()), useAuth: () => ({ user: { id: 'u1', name: 'Ada' }, activeOrganization: null }), - // "Save as view" and its dialog are admin-only. + // "Save as view" and its dialog are for an admin holding `manage_metadata`. useWorkspaceAdminStatus: () => ({ isAdmin: true, isResolved: true }), createAuthenticatedFetch: () => vi.fn(), })); @@ -177,6 +183,7 @@ async function saveAsView() { beforeEach(() => { cleanup(); puts.length = 0; + viewer.canAuthorMetadata = true; client = new MetadataClient({ baseUrl: 'http://localhost', fetch: wire() as unknown as typeof fetch }); vi.spyOn(console, 'error').mockImplementation(() => {}); // objectstack#35624 — the create asks the package list where the app saves @@ -221,3 +228,31 @@ describe('"Save as view" says a refused save, and never reports it as saved (obj expect(screen.queryByTestId('create-view-dialog')).toBeNull(); }); }); + +describe('objectstack#36448 — "Save as view" is offered to an administrator holding manage_metadata', () => { + const mount = () => render( + + + + ({ data: [] })) }} objects={[DEAL]} />} + /> + + + , + ); + + it('an organization administrator without it is not offered the save the server refuses', () => { + viewer.canAuthorMetadata = false; + mount(); + expect(screen.queryByTestId('object-data-save-as-view')).toBeNull(); + expect(screen.queryByTestId('object-data-save-as-view-menu-item')).toBeNull(); + expect(screen.queryByTestId('create-view-dialog')).toBeNull(); + }); + + it('with it, the entry is offered (control)', () => { + mount(); + expect(screen.getByTestId('object-data-save-as-view')).toBeTruthy(); + }); +}); diff --git a/ui/packages/app-shell/src/views/ObjectDataPage.tsx b/ui/packages/app-shell/src/views/ObjectDataPage.tsx index 31d1f7d5808..25162943c71 100644 --- a/ui/packages/app-shell/src/views/ObjectDataPage.tsx +++ b/ui/packages/app-shell/src/views/ObjectDataPage.tsx @@ -99,6 +99,8 @@ import { } from '../preview/PreviewModeContext.js'; import { usePreviewListDataSource } from '../preview/unpublishedObjectReads.js'; import { useTenancyPosture } from '../hooks/useTenancyPosture.js'; +import { useCanAuthorMetadata } from '../hooks/useCanAuthorMetadata.js'; +import { mayManageViews } from './objectViewViewSharing.js'; import { servedObjectLabel, servedObjectPluralLabel } from '../hooks/servedObjectLabel.js'; import type { RowCrudPredicates } from '../utils/crudAffordances.js'; import { servesRecordRead } from '../utils/recordReadServed.js'; @@ -332,6 +334,11 @@ export function ObjectDataPage({ dataSource, objects }: any) { const { canRead } = useFieldPermissions(objectName ?? ''); const { user, activeOrganization } = useAuth(); const { isAdmin } = useWorkspaceAdminStatus(); + // objectstack#36448 — "Save as view" writes `view` metadata, which the + // server refuses without `manage_metadata`: offered to an administrator + // holding it (`mayManageViews`), never to one the save would answer 403. + const canAuthorMetadata = useCanAuthorMetadata(); + const canSaveAsView = mayManageViews(isAdmin, canAuthorMetadata); const metadataClient = useMetadataClient(); // ADR-0105: group posture appends a trailing organization_id attribution // column to the auto-derived columns (reads span all the user's orgs). @@ -908,7 +915,7 @@ export function ObjectDataPage({ dataSource, objects }: any) { {t('console.objectView.new')} ) : null; - const saveAsViewButton = isAdmin ? ( + const saveAsViewButton = canSaveAsView ? (