From 2e47ffd2a79ed0ffb66519f596a119880a80c501 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 28 Oct 2026 02:57:01 +0000 Subject: [PATCH 1/2] fix(plugin-dashboard): leave a tile out when the server refuses its data to the viewer Outside design mode, a dataset tile whose query the server refuses as a read refusal is dropped from the dashboard layout, so the viewer sees no permission-error tile and the other tiles reflow. Design mode keeps the no-access state so the author can still select the tile. Claude-Session: https://claude.ai/code/session_01JQwxbacRXrqkMrm5LGBGYE Co-Authored-By: Claude --- .../src/DashboardRenderer.tsx | 17 +++ .../plugin-dashboard/src/DatasetWidget.tsx | 15 +- ...shboardRenderer.refusedTile-26971.test.tsx | 140 ++++++++++++++++++ 3 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 ui/packages/plugin-dashboard/src/__tests__/DashboardRenderer.refusedTile-26971.test.tsx diff --git a/ui/packages/plugin-dashboard/src/DashboardRenderer.tsx b/ui/packages/plugin-dashboard/src/DashboardRenderer.tsx index 0e8e6bd8431..87301437798 100644 --- a/ui/packages/plugin-dashboard/src/DashboardRenderer.tsx +++ b/ui/packages/plugin-dashboard/src/DashboardRenderer.tsx @@ -381,6 +381,20 @@ const DashboardRendererInner = forwardRef>(() => new Set()); + const markTileRefused = useCallback((tileKey: string) => { + setRefusedTiles((prev) => (prev.has(tileKey) ? prev : new Set(prev).add(tileKey))); + }, []); + // Dashboard-level filters (framework#2501). Filter values live as // dashboard variables — the outer DashboardRenderer mounts a // PageVariablesProvider when the schema declares filters, so @@ -1087,6 +1101,8 @@ const DashboardRendererInner = forwardRef markTileRefused(refusedTileKey) : undefined} heading={datasetMetric ? { title: resolvedTitle || '', description: resolvedDescription || undefined } : undefined} diff --git a/ui/packages/plugin-dashboard/src/DatasetWidget.tsx b/ui/packages/plugin-dashboard/src/DatasetWidget.tsx index 570a1171666..4ee3579ed0c 100644 --- a/ui/packages/plugin-dashboard/src/DatasetWidget.tsx +++ b/ui/packages/plugin-dashboard/src/DatasetWidget.tsx @@ -658,7 +658,19 @@ function MetricHeadingRow({ heading, label }: { heading: DatasetMetricHeading; l ); } -export function DatasetWidget({ widget, dataSource, heading }: { widget: any; dataSource: unknown; heading?: DatasetMetricHeading }) { +export function DatasetWidget({ widget, dataSource, heading, onForbidden }: { + widget: any; + dataSource: unknown; + heading?: DatasetMetricHeading; + /** + * Called when the server refuses this widget's query as a READ refusal + * (`classifyLoadError(e) === 'forbidden'`). A host that can leave the tile + * out of its layout does so for a viewer (objectstack#26971); the widget + * itself still draws its no-access state (objectui#10899) for a host that + * keeps it on screen. The 403 stays the enforcement: this only reports it. + */ + onForbidden?: () => void; +}) { const datasetName = String(widget?.dataset ?? ''); const dimensions: string[] = useMemo(() => (Array.isArray(widget?.dimensions) ? widget.dimensions.filter(Boolean) : []), [widget]); const values: string[] = useMemo(() => (Array.isArray(widget?.values) ? widget.values.filter(Boolean) : []), [widget]); @@ -951,6 +963,7 @@ export function DatasetWidget({ widget, dataSource, heading }: { widget: any; da // agnostic `classifyLoadError`, never by matching the message text. if (classifyLoadError(e) === 'forbidden') { setState({ status: 'error', rows: [], forbidden: true }); + onForbidden?.(); return; } setState({ status: 'error', rows: [], error: String((e as Error)?.message ?? e) }); diff --git a/ui/packages/plugin-dashboard/src/__tests__/DashboardRenderer.refusedTile-26971.test.tsx b/ui/packages/plugin-dashboard/src/__tests__/DashboardRenderer.refusedTile-26971.test.tsx new file mode 100644 index 00000000000..d169bb95aff --- /dev/null +++ b/ui/packages/plugin-dashboard/src/__tests__/DashboardRenderer.refusedTile-26971.test.tsx @@ -0,0 +1,140 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * objectstack#26971 item 1 — a viewer who may not read the data behind a + * dataset tile does not see a permission-error tile, and the other tiles + * still render. + * + * Measured on HotCRM's Sales Performance dashboard: a viewer holding only a + * marketing permission set saw 14 tiles answer and the 15th draw "You don't + * have permission to view the data behind this widget" (its dataset query + * answered 403). Outside design mode `DashboardRenderer` now leaves that tile + * out of the layout, Card frame and title included, once the server refuses + * the query as a READ refusal (`DatasetWidget`'s `onForbidden`). The 403 stays + * the enforcement: nothing is hidden before the server answers. + * + * CONTROLS: in design mode the refused tile stays and draws the no-access + * state (objectui#10899), so the author can still see and select it; and a + * failure that is not a read refusal keeps the tile and its error alert. + * + * The refusal carries the two fields `@object-ui/data-objectstack`'s + * `AnalyticsForbiddenError` declares (`httpStatus: 403`, + * `code: 'PERMISSION_DENIED'`), as `DatasetWidget.forbiddenState-10899.test.tsx` + * builds it. + */ + +import '@testing-library/jest-dom/vitest'; +import * as React from 'react'; +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import { render, screen, cleanup, waitFor } from '@testing-library/react'; +import type { DashboardComponentSchema } from '@object-ui/types'; +// Module scope (AGENTS.md 测试纪律): the table tile renders onward through the +// registry this barrel populates. +import '@object-ui/components'; +import { DashboardRenderer } from '../DashboardRenderer'; + +beforeEach(() => { + // The dimension-label metadata probe (`useDatasetDimensionMeta`) falls back + // to the global fetch; answer it locally so no case reaches the network. + vi.stubGlobal('fetch', vi.fn(async () => ({ ok: true, status: 200, json: async () => ({}), text: async () => '{}' }))); +}); +afterEach(() => { + vi.unstubAllGlobals(); + cleanup(); +}); + +const dashboard = (...widgets: Record[]): DashboardComponentSchema => + ({ type: 'dashboard', name: 'sales_performance', widgets }) as unknown as DashboardComponentSchema; + +const READABLE = { + id: 'pipeline_by_stage', + type: 'table', + title: 'Pipeline by Stage', + dataset: 'opportunity_metrics', + dimensions: ['stage'], + values: ['deal_count'], +}; +const REFUSED = { + id: 'quota_attainment', + type: 'table', + title: 'Quota Attainment by Rep', + dataset: 'forecast_metrics', + dimensions: ['owner'], + values: ['attainment'], +}; + +function readRefusal() { + return Object.assign(new Error('Analytics query refused: this user may not read the data behind dataset "forecast_metrics".'), { + name: 'AnalyticsForbiddenError', + httpStatus: 403, + code: 'PERMISSION_DENIED', + }); +} + +/** Answers every dataset but `forecast_metrics`, which it refuses with `failure()`. */ +function source(failure: () => Error = readRefusal) { + return { + queryDataset: vi.fn(async (dataset: string) => { + if (dataset === 'forecast_metrics') throw failure(); + return { + rows: [{ stage: 'Closed Won', deal_count: 7 }], + fields: [ + { name: 'stage', label: 'Stage', type: 'text' }, + { name: 'deal_count', label: 'Deals', type: 'number' }, + ], + object: 'opportunity', + }; + }), + }; +} + +describe('DashboardRenderer — a tile whose data the viewer may not read is left out (objectstack#26971)', () => { + it('drops the refused tile, frame and title included, and keeps the readable one', async () => { + const src = source(); + render(); + + // The readable tile answers. + expect(await screen.findByText('Closed Won')).toBeInTheDocument(); + expect(screen.getByText('Pipeline by Stage')).toBeInTheDocument(); + // The refused tile was asked (no client-side guess), and once the server + // refused it, nothing of it is left: no no-access state, no titled frame. + expect(src.queryDataset).toHaveBeenCalledWith('forecast_metrics', expect.anything()); + await waitFor(() => expect(screen.queryByText('Quota Attainment by Rep')).toBeNull()); + expect(screen.queryByTestId('dataset-widget-forbidden')).toBeNull(); + expect(screen.queryByText(/don’t have (access|permission)/)).toBeNull(); + }); + + it('CONTROL — in design mode the refused tile stays and draws the no-access state', async () => { + render( + {}} + />, + ); + + expect(await screen.findByTestId('dataset-widget-forbidden')).toHaveTextContent('You don’t have access'); + expect(screen.getByTestId('dashboard-preview-widget-quota_attainment')).toHaveTextContent('Quota Attainment by Rep'); + expect(await screen.findByText('Closed Won')).toBeInTheDocument(); + }); + + it('CONTROL — a failure that is not a read refusal keeps the tile and its error', async () => { + render( + new Error('Dataset query failed: 400 Bad Request — relationship not declared in include'))} + />, + ); + + expect(await screen.findByText(/relationship not declared in include/)).toBeInTheDocument(); + expect(screen.getByText('Quota Attainment by Rep')).toBeInTheDocument(); + expect(await screen.findByText('Closed Won')).toBeInTheDocument(); + }); +}); From 52ed28395eb612e2eccfd69080a958c587e2130b Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 28 Oct 2026 03:03:21 +0000 Subject: [PATCH 2/2] chore(changeset): plugin-dashboard patch for the refused-tile drop Claude-Session: https://claude.ai/code/session_01JQwxbacRXrqkMrm5LGBGYE Co-Authored-By: Claude --- .../26971-dashboard-refused-tile-left-out.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .changeset/26971-dashboard-refused-tile-left-out.md diff --git a/.changeset/26971-dashboard-refused-tile-left-out.md b/.changeset/26971-dashboard-refused-tile-left-out.md new file mode 100644 index 00000000000..9a0aeb2a1de --- /dev/null +++ b/.changeset/26971-dashboard-refused-tile-left-out.md @@ -0,0 +1,14 @@ +--- +'@object-ui/plugin-dashboard': patch +--- + +fix(plugin-dashboard): a dashboard tile whose data the viewer may not read is left out, not drawn as a permission error + +Clause-②: no +Metadata-protocol: none + +A viewer who may not read the data behind one dataset tile used to see that tile draw "You don't have permission to view the data behind this widget" among tiles that answered. Outside design mode, `DashboardRenderer` now leaves such a tile out of the layout, frame and title included, once the server refuses its query as a read refusal (403 / `PERMISSION_DENIED`), and the remaining tiles reflow. The server's refusal stays the only verdict: every tile is still queried, and nothing is hidden on a guess. + +- In design mode the tile stays and draws the no-access state, so an author can still see and select it. +- A failure that is not a read refusal keeps the tile and its error, as before. +- The editable grid layout (`DashboardGridLayout`) keeps the tile and its no-access state, unchanged.