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
13 changes: 13 additions & 0 deletions .changeset/36010-views-refused-read-no-access.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@object-ui/plugin-kanban': patch
'@object-ui/plugin-calendar': patch
'@object-ui/plugin-timeline': patch
'@object-ui/plugin-map': patch
---

fix(ui): the kanban, calendar, timeline and map views draw the no-access state for a refused read, not the raw error

Clause-②: no
Metadata-protocol: none

A reader who may open a page but is not granted the records its kanban board, calendar, timeline or map reads saw the transport's own string where the view would be, untranslated (for example `Error loading kanban data: ApiDataSource: HTTP 403 Forbidden — {…}`). Each of the four views now classifies a failed load with the shared load-error verdict the list page, the related list and the Gantt chart use, and for a permission refusal (a 403, or a `PERMISSION_DENIED` / `FORBIDDEN` code) draws the calm no-access state those surfaces draw: a neutral status panel with the shared `list.loadErrorForbiddenTitle` / `list.loadErrorForbiddenMessage` sentence in the reader's language, and none of the server's text. Every other failure (a 500, a dropped connection) keeps each view's existing error screen. The map's tile-style failure is not a data load and is unchanged.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,29 @@ async function invalidate() {
});
}

/** The shape the ObjectStack adapter throws: status + code decorated on the Error. */
function refusal(): Error {
const err = new Error(
'ApiDataSource: HTTP 403 Forbidden — {"error":"PERMISSION_DENIED: no read access to event"}',
) as Error & { httpStatus?: number; code?: string };
err.httpStatus = 403;
err.code = 'PERMISSION_DENIED';
return err;
}

function serverError(): Error {
const err = new Error('ApiDataSource: HTTP 500 Internal Server Error') as Error & { httpStatus?: number };
err.httpStatus = 500;
return err;
}

async function failWith(d: Deferred<any>, err: Error) {
await act(async () => {
d.reject(err);
await Promise.resolve();
});
}

const CALENDAR = { startDateField: 'due', titleField: 'name' };
const BLOCK = { type: 'object-calendar', objectName: 'event', calendar: CALENDAR };

Expand Down Expand Up @@ -211,3 +234,41 @@ describe('object-calendar clears its error when a later load commits rows (objec
expect(screen.getByText('Handed over')).toBeTruthy();
});
});

/**
* A refused read draws the calm no-access state, not the raw error.
*
* A reader who may open the page but not read the calendar's object used to see
* the transport's own string ("ApiDataSource: HTTP 403 Forbidden — ..."). The
* calendar now classifies a failed load with the shared `classifyLoadError` and,
* for a `forbidden` read, draws the shared `list.loadErrorForbidden*` sentence
* as a neutral `role="status"` panel. Every other failure keeps the existing
* error screen (CONTROL).
*/
describe('object-calendar: a refused read draws the no-access state', () => {
it('a 403 read draws the no-access state, with none of the server text', async () => {
const { dataSource, finds } = makeDeferredDataSource();
const { container } = mount(dataSource);
await waitFor(() => expect(finds).toHaveLength(1));
await failWith(finds[0], refusal());

const panel = await screen.findByTestId('calendar-no-access');
expect(panel.getAttribute('role')).toBe('status');
expect(panel.textContent).toContain('You don\u2019t have access');
expect(panel.textContent).toContain('You don\u2019t have permission to view these records.');
const text = container.textContent ?? '';
expect(text).not.toContain('Error');
expect(text).not.toContain('PERMISSION_DENIED');
expect(text).not.toContain('HTTP 403');
});

it('CONTROL: a 500 keeps the existing error screen', async () => {
const { dataSource, finds } = makeDeferredDataSource();
mount(dataSource);
await waitFor(() => expect(finds).toHaveLength(1));
await failWith(finds[0], serverError());

expect(errorShown('ApiDataSource: HTTP 500 Internal Server Error')).toBe(true);
expect(screen.queryByTestId('calendar-no-access')).toBeNull();
});
});
29 changes: 28 additions & 1 deletion ui/packages/plugin-calendar/src/ObjectCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ import {
useDataInvalidation,
useFilterScope,
useResolvedFilter,
classifyLoadError,
} from '@object-ui/react';
import {
RECORD_OVERLAY_DEFAULT_WIDTH,
RecordDetailPanel,
deriveRecordPageHref,
} from '@object-ui/plugin-detail';
import { usePermissions } from '@object-ui/permissions';
import { ChevronRight } from 'lucide-react';
import { ChevronRight, Lock } from 'lucide-react';
import {
cn,
useIsMobile,
Expand All @@ -70,6 +71,7 @@ import {
Input,
Label,
NavigationOverlay,
DataEmptyState,
legacyRecordDrawerWidthKey,
recordOverlayWidthStorageKey,
toast,
Expand Down Expand Up @@ -1508,6 +1510,31 @@ export const ObjectCalendar: React.FC<ObjectCalendarComponentProps> = ({
);
}

// A refused read (403 / PERMISSION_DENIED, by the shared `classifyLoadError`
// verdict the list page, the related list and the gantt use) is not a
// failure of anything the reader did: they may open the page without being
// granted the records this calendar reads. It is drawn as the calm no-access
// state (`role="status"`, the shared `list.loadErrorForbidden*` sentence in
// the reader's language), never the server's text. Every other failure
// keeps the error screen below.
// This package has no default-translation table: the `defaultValue`s are the
// provider-less fallback and say exactly what the `en` pack says.
if (error && classifyLoadError(error) === 'forbidden') {
return (
<div className={className}>
<DataEmptyState
data-testid="calendar-no-access"
className="h-96"
icon={<Lock className="size-5 text-muted-foreground" aria-hidden />}
title={t('list.loadErrorForbiddenTitle', { defaultValue: 'You don’t have access' })}
description={t('list.loadErrorForbiddenMessage', {
defaultValue: 'You don’t have permission to view these records. Contact your administrator if you think you should have access.',
})}
/>
</div>
);
}

if (error) {
return (
<div className={className}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,29 @@ async function invalidate() {
});
}

/** The shape the ObjectStack adapter throws: status + code decorated on the Error. */
function refusal(): Error {
const err = new Error(
'ApiDataSource: HTTP 403 Forbidden — {"error":"PERMISSION_DENIED: no read access to deal"}',
) as Error & { httpStatus?: number; code?: string };
err.httpStatus = 403;
err.code = 'PERMISSION_DENIED';
return err;
}

function serverError(): Error {
const err = new Error('ApiDataSource: HTTP 500 Internal Server Error') as Error & { httpStatus?: number };
err.httpStatus = 500;
return err;
}

async function failWith(d: Deferred<any>, err: Error) {
await act(async () => {
d.reject(err);
await Promise.resolve();
});
}

const BLOCK = { type: 'object-kanban', objectName: 'deal', groupBy: 'status', columns: [{ id: 'open', title: 'Open' }] };

function mount(dataSource: ReturnType<typeof makeDeferredDataSource>['dataSource']) {
Expand Down Expand Up @@ -191,3 +214,41 @@ describe('object-kanban clears its error when a later load commits cards (object
expect(errorShown('current run failed'), 'a superseded answer cleared the current error').toBe(true);
});
});

/**
* A refused read draws the calm no-access state, not the raw error.
*
* A reader who may open the page but not read the kanban's object used to see
* the transport's own string ("ApiDataSource: HTTP 403 Forbidden — ..."). The
* kanban now classifies a failed load with the shared `classifyLoadError` and,
* for a `forbidden` read, draws the shared `list.loadErrorForbidden*` sentence
* as a neutral `role="status"` panel. Every other failure keeps the existing
* error screen (CONTROL).
*/
describe('object-kanban: a refused read draws the no-access state', () => {
it('a 403 read draws the no-access state, with none of the server text', async () => {
const { dataSource, finds } = makeDeferredDataSource();
const { container } = mount(dataSource);
await waitFor(() => expect(finds).toHaveLength(1));
await failWith(finds[0], refusal());

const panel = await screen.findByTestId('kanban-no-access');
expect(panel.getAttribute('role')).toBe('status');
expect(panel.textContent).toContain('You don\u2019t have access');
expect(panel.textContent).toContain('You don\u2019t have permission to view these records.');
const text = container.textContent ?? '';
expect(text).not.toContain('Error');
expect(text).not.toContain('PERMISSION_DENIED');
expect(text).not.toContain('HTTP 403');
});

it('CONTROL: a 500 keeps the existing error screen', async () => {
const { dataSource, finds } = makeDeferredDataSource();
mount(dataSource);
await waitFor(() => expect(finds).toHaveLength(1));
await failWith(finds[0], serverError());

expect(errorShown('ApiDataSource: HTTP 500 Internal Server Error')).toBe(true);
expect(screen.queryByTestId('kanban-no-access')).toBeNull();
});
});
28 changes: 28 additions & 0 deletions ui/packages/plugin-kanban/src/ObjectKanban.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ import {
useFilterScope,
useResolvedFilter,
usePredicateScope,
classifyLoadError,
} from '@object-ui/react';
import {
NavigationOverlay,
DataEmptyState,
legacyRecordDrawerWidthKey,
recordOverlayWidthStorageKey,
toast,
} from '@object-ui/components';
import { createSafeTranslation } from '@object-ui/i18n';
import { Lock } from 'lucide-react';
import {
RECORD_OVERLAY_DEFAULT_WIDTH,
RecordDetailPanel,
Expand Down Expand Up @@ -91,6 +94,12 @@ import { lanesFromOptions, type LaneLifecycleKind } from './kanbanLaneLifecycle'
const KANBAN_DEFAULT_TRANSLATIONS: Record<string, string> = {
'detail.recordDetail': 'Record Detail',
'detail.recordDetailWithLabel': '{{label}} Detail',
// The refused-read state reuses the shared no-access sentence the list page
// and the related list draw, so a host pack that translates them translates
// this board too; these rows are the provider-less fallback and say exactly
// what the `en` pack says.
'list.loadErrorForbiddenTitle': 'You don’t have access',
'list.loadErrorForbiddenMessage': 'You don’t have permission to view these records. Contact your administrator if you think you should have access.',
};

/**
Expand Down Expand Up @@ -1953,6 +1962,25 @@ export const ObjectKanban: React.FC<ObjectKanbanComponentProps> = ({

// Error branch renders only after every hook above has run, so hook order
// stays stable across renders (no early return before the hooks).
// A refused read (403 / PERMISSION_DENIED, by the shared `classifyLoadError`
// verdict the list page, the related list and the gantt use) is not a
// failure of anything the reader did: they may open the page without being
// granted the records this board reads. It is drawn as the calm no-access
// state (`role="status"`, the shared `list.loadErrorForbidden*` sentence in
// the reader's language), never the server's text. Every other failure
// keeps the error screen below.
if (error && classifyLoadError(error) === 'forbidden') {
return (
<DataEmptyState
data-testid="kanban-no-access"
className="h-96"
icon={<Lock className="size-5 text-muted-foreground" aria-hidden />}
title={t('list.loadErrorForbiddenTitle')}
description={t('list.loadErrorForbiddenMessage')}
/>
);
}

if (error) {
return (
<div className="p-4 border border-destructive/50 rounded bg-destructive/10 text-destructive">
Expand Down
57 changes: 57 additions & 0 deletions ui/packages/plugin-map/src/ObjectMap.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,60 @@ describe('ObjectMap', () => {
});
});
});

/**
* A refused read draws the calm no-access state, not the raw error.
*
* A reader who may open the page but not read the map's object used to see
* the transport's own string ("Error: ApiDataSource: HTTP 403 Forbidden — ...").
* The map now classifies a failed load with the shared `classifyLoadError` and,
* for a `forbidden` read, draws the shared `list.loadErrorForbidden*` sentence
* as a neutral `role="status"` panel. Every other failure keeps the existing
* error screen (CONTROL).
*/
describe('ObjectMap: a refused read draws the no-access state', () => {
const schema: any = {
type: 'map',
map: { latitudeField: 'latitude', longitudeField: 'longitude', titleField: 'name' },
data: { provider: 'object', object: 'locations' },
};

function failingSource(err: Error): DataSource {
return {
find: vi.fn(async () => { throw err; }),
findOne: vi.fn(),
create: vi.fn(),
update: vi.fn(),
delete: vi.fn(),
getObjectSchema: vi.fn(),
} as unknown as DataSource;
}

it('a 403 read draws the no-access state, with none of the server text', async () => {
const err = new Error(
'ApiDataSource: HTTP 403 Forbidden — {"error":"PERMISSION_DENIED: no read access to locations"}',
) as Error & { httpStatus?: number; code?: string };
err.httpStatus = 403;
err.code = 'PERMISSION_DENIED';
const { container } = render(<ObjectMap schema={schema} dataSource={failingSource(err)} />);

const panel = await screen.findByTestId('map-no-access');
expect(panel.getAttribute('role')).toBe('status');
expect(panel.textContent).toContain('You don’t have access');
expect(panel.textContent).toContain('You don’t have permission to view these records.');
const text = container.textContent ?? '';
expect(text).not.toContain('Error');
expect(text).not.toContain('PERMISSION_DENIED');
expect(text).not.toContain('HTTP 403');
expect(screen.queryByLabelText('Map')).toBeNull();
});

it('CONTROL: a 500 keeps the existing error screen', async () => {
const err = new Error('ApiDataSource: HTTP 500 Internal Server Error') as Error & { httpStatus?: number };
err.httpStatus = 500;
render(<ObjectMap schema={schema} dataSource={failingSource(err)} />);

expect(await screen.findByText('Error: ApiDataSource: HTTP 500 Internal Server Error')).toBeTruthy();
expect(screen.queryByTestId('map-no-access')).toBeNull();
});
});
31 changes: 30 additions & 1 deletion ui/packages/plugin-map/src/ObjectMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ import {
useResolvedFilter,
useObjectTranslation,
useHostMapStyle,
classifyLoadError,
} from '@object-ui/react';
import { NavigationOverlay, cn, useIsMobile } from '@object-ui/components';
import { NavigationOverlay, DataEmptyState, LazyIcon, cn, useIsMobile } from '@object-ui/components';
import { usePermissions } from '@object-ui/permissions';
import { RecordDetailPanel } from '@object-ui/plugin-detail';
import {
Expand Down Expand Up @@ -1386,6 +1387,34 @@ export const ObjectMap: React.FC<ObjectMapProps> = ({
);
}

// A refused read (403 / PERMISSION_DENIED, by the shared `classifyLoadError`
// verdict the list page, the related list and the gantt use) is not a
// failure of anything the reader did: they may open the page without being
// granted the records this map reads. It is drawn as the calm no-access
// state (`role="status"`, the shared `list.loadErrorForbidden*` sentence in
// the reader's language), never the server's text. Every other failure
// keeps the error screen below.
// This package has no default-translation table, so the `defaultValue`s are
// the provider-less fallback (they say exactly what the `en` pack says), and
// the Lock glyph comes through the shared `LazyIcon`: it declares no icon
// library of its own. The style/tile failure (`mapStyleError`) is not a data
// load and is not routed here.
if (error && classifyLoadError(error) === 'forbidden') {
return (
<div className={cn("min-w-0 overflow-hidden", className)}>
<DataEmptyState
data-testid="map-no-access"
className="h-96"
icon={<LazyIcon name="lock" className="size-5 text-muted-foreground" aria-hidden />}
title={t('list.loadErrorForbiddenTitle', { defaultValue: 'You don’t have access' })}
description={t('list.loadErrorForbiddenMessage', {
defaultValue: 'You don’t have permission to view these records. Contact your administrator if you think you should have access.',
})}
/>
</div>
);
}

if (error) {
return (
<div className={cn("min-w-0 overflow-hidden", className)}>
Expand Down
Loading
Loading