Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit 1263e40

Browse files
fix(app-shell,plugin-detail): the record activity panel says "no permission to view activity" when its read is refused, instead of an empty list (objectui#11195) (#11217)
Fixes #11195 Clause-②: yes (widening) ## What was wrong An invited member of a hosted AI-built app opened a record (objectstack-ai/cloud#2485). The server refused the record's `sys_activity` read with a 403, and the activity panel showed an empty list with no message. The member could not tell "no activity" from "not allowed to see activity". Every feed read ended in a catch that treated any failure as an empty answer: - `RecordDetailView` (the console record page): both feed reads, `sys_activity` and `sys_comment`, ended in an empty `.catch` handler, and `Promise.allSettled` then counted the failed read as answered. A 403 landed on "No comments yet". - `record:activity` (plugin-detail): the self-fetch's `.catch` set the feed to `[]` for every failure, so a 403 landed on "No activity recorded". ## What changed - **One verdict, reused.** `isRefusedFeedRead(err)` in plugin-detail's `recordActivityFeed.ts`, exported from the package barrel beside `activityRowToFeedItem`. It is the `forbidden` and `unauthorized` kinds of the existing `classifyLoadError` read classifier (`@object-ui/react`), and it reads no status or code of its own. Both surfaces call it. - **`RecordDetailView` keeps a verdict per source.** Each read records "refused or not" under the same per-record key the rows use (`feedRefusalByRecord`), so a refusal on one record never reaches another. An answered read clears it. The host passes `activityDenied` / `commentsDenied` on its `DiscussionContextProvider`. - **`DiscussionContext`** (`@object-ui/react`) gains the two optional members `activityDenied` / `commentsDenied`, in the provider's memo list as primitives. - **`record:activity`** records its self-fetch's refusal in state beside `fetched`. With a host context it shows the host's two flags instead. Host `items` carry no refusal. - **`record:chatter` / `record:discussion`** pass the context's flags through `RecordChatterPanel` to the timeline. - **`RecordActivityTimeline`** takes `activityDenied` / `commentsDenied`. With no rows, a refusal replaces the empty state: a lock and a left-aligned sentence, not the centred inbox glyph. With rows on screen, the rows stay and the notice sits above them. Only the i18n sentence is rendered: no status, no server message, no object name. - **Strings:** `detail.activityAccessDenied` and `detail.commentsAccessDenied`, in all ten locale packs and in `DETAIL_DEFAULT_TRANSLATIONS`. No existing key fit: `attachmentsAccessDenied` names attachments. - Changeset: `minor` for plugin-detail and react, which gain published surface (plugin-detail's root export `isRefusedFeedRead` and the optional `activityDenied` / `commentsDenied` on `RecordActivityTimelineProps` / `RecordChatterPanelProps`; react's `DiscussionContextValue` gains the same two optional members); `patch` for app-shell and i18n. The `record:activity` section of the plugin-detail guide gains "When the read is refused". ## Decisions the card left open, and what this PR does - **A refused `sys_comment` beside an answered `sys_activity`.** The comment half of the same panel gets the same treatment. The activity rows stay on screen, and the notice above them reads "You don't have permission to view comments on this record." Both refused, with no rows, shows both lines. - **401 counts as refused**, per the triage on the card (any refused read: 401 / 403, or a permission envelope). This differs on purpose from `RecordAttachmentsPanel`, whose `denied` state does not claim a 401. The verdict's docblock records why. - **Not refused, so the empty state stays:** a 200 with zero rows; a 404 (the ObjectStack adapter already answers a bare 404 as zero rows; another adapter's 404 classifies as `network`); `OBJECT_API_DISABLED` / `OBJECT_API_METHOD_NOT_ALLOWED` (`api-disabled`: a property of the object, not of the caller); a 400; a 500. The panel has no error state, so a 500 still settles on the empty state. See Acceptance notes. - **No retry.** A refusal is written into state. No effect dependency moves with it, and nothing re-issues the read. Both surfaces pin this. ## Verification (head `df5a91cb4`, after merging `origin/main` at `9419df198`) - New pins, both surfaces: `RecordDetailView.feedRefusal-11195.test.tsx` (7 tests) and `record-activity.refusedRead-11195.test.tsx` (10 tests). They cover: a 403 envelope and a 401 show the no-permission state with no retry; the 200-zero-rows control shows the empty state; a 404 and a 500 do not show "no permission"; a refused comment read keeps the activity rows; the host-context path; and the verdict's refused and not-refused sets. - Merged tree, one run: all `RecordDetailView*` suites, the `record-activity*` / `record-chatter*` renderer suites, `all-locales-key-parity`, `en-zh-key-parity` and `defaults-maps-mirror-en-pack`: **49 files, 355 tests passed**. - Before the merge (branch head `2fbe2df5f`): `packages/plugin-detail/` whole: 226 files passed (1 skipped), 2245 tests passed. The `RecordDetailView*` suites plus `defaults-maps-mirror-en-pack`, `widget-dom-leak-sweep`, `palette-discussion-alias`, apps/console `record-block-record-reach` and `packages/react/src/context`: 57 files, 653 tests passed. `packages/i18n/` whole: 74 files passed, 1216 tests passed (13 skipped). - `type-check`: `@object-ui/plugin-detail`, `@object-ui/app-shell`, `@object-ui/react` and `@object-ui/i18n` all exit 0 (dependency closure built first, `@object-ui/app-shell^...`). - `eslint` on the 21 changed ts/tsx files: 0 errors. - Gates, exit 0: `check-changeset-presence` (1 changeset, 4 released packages), `check:control-bytes`, `check:new-line-citations` (0 new), `check:i18n-keys`, `check:i18n-drift` (2 keys added, 0 en values changed), `check:i18n-dead-keys`, `check:changeset-claims`, `check:pending-changeset-literals`, `markdown-test-inputs --audit`, `check:doc-types`, `check:doc-fences`, `check:doc-example-ids`, `check:phantom-deps`, `check:self-import`, `check:test-path-roots`, `check:vi-mock-specifiers`. - NOT MEASURED: `check:doc-snippets` / `check:doc-examples` (exit 2, precondition not met: packages outside this diff's closure are unbuilt; the docs edit adds prose and no code fence). The root `scripts/__tests__/` suite was not run: the shared verify lock queued for over an hour. This diff edits no script and adds no test that reads markdown. CI runs it. ## Ablation (one leg, at the shared verdict, head `df5a91cb4`) `isRefusedFeedRead` was made to answer "not refused" for every rejection, which turns a refusal back into the empty list on both surfaces. The mutation went through `ablation-replace.mjs`: the anchor was hit 1 time and went to 0, the marker went from 0 to 1, and the blob changed. The subject reaches the tests through the vitest source alias for `@object-ui/plugin-detail`, so no build sat in between. - Mutated: **8 failed, 9 passed (17)**. The 8 red: the 403 and 401 pins and the no-retry pin on each surface, the refused-comment pin, and the verdict's refused set. The 9 green are the 200 / 404 / 500 controls on both surfaces, the two host-context pins, and the verdict's not-refused set. That is the expected direction. - Restored: the blob equals the HEAD blob and `git diff HEAD` is empty. ## Acceptance notes (not filed; observations only) - A read that fails without a refusal (a 500, an unreachable server) still renders the empty state, "No comments yet" / "No activity recorded". That sentence is a claim about the record, made without evidence. The panel has no error state; `RecordAttachmentsPanel`'s `unavailable` state is the house shape for one. The triage said this case "is reported"; it is out of this card's scope. - `DiscussionContextValue.error` is declared, but no host sets it and no renderer reads it. - When the `sys_comment` read is refused, the comment composer still renders. Whether the member may WRITE a comment they may not READ is a server question; this PR does not change the composer. --- _Generated by [Claude Code](https://claude.ai/code/session_011p7ikEivgXefNDaE5S5Uec)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ed498ac commit 1263e40

23 files changed

Lines changed: 779 additions & 17 deletions
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/plugin-detail': minor
4+
'@object-ui/react': minor
5+
'@object-ui/i18n': patch
6+
---
7+
8+
fix(app-shell,plugin-detail): the record feed says "no permission" when its read is refused, instead of showing an empty list
9+
10+
This widens two published surfaces: `@object-ui/plugin-detail` gains the export `isRefusedFeedRead`, and `@object-ui/react`'s `DiscussionContextValue` gains the optional members `activityDenied` and `commentsDenied` (as do `RecordActivityTimelineProps` and `RecordChatterPanelProps`).
11+
12+
When the server refused a record's activity read (401, 403, or a permission
13+
envelope), the record page's discussion panel and the `record:activity` block
14+
rendered the empty state: "No comments yet" or "No activity recorded". A member
15+
who was not allowed to see the activity could not tell that apart from a record
16+
with no history. Every failed feed read ended in a catch that treated it as an
17+
empty answer.
18+
19+
Each feed read now keeps its verdict. A refused read shows a localized
20+
no-permission state in place of the empty state: a lock and "You don't have
21+
permission to view activity on this record." When the other read did answer, its
22+
rows stay on screen and the notice above them names the half that was withheld.
23+
A refused `sys_comment` read shows "You don't have permission to view comments on
24+
this record." in the same way.
25+
26+
- **What counts as refused** is one verdict, `isRefusedFeedRead`, exported from
27+
`@object-ui/plugin-detail`. Both surfaces use it. It is the `forbidden` and
28+
`unauthorized` kinds of the existing `classifyLoadError` read classifier, and
29+
it reads no status of its own.
30+
- **Unchanged:** a read that answers with zero rows, a 404 (`sys_activity` on a
31+
deployment without the audit plugin), and any other failure such as a 500 keep
32+
the empty state. The panel has no error state of its own.
33+
- **Not retried:** a refusal is recorded and shown; the read is not re-issued.
34+
- `DiscussionContext` (`@object-ui/react`) gains two optional members,
35+
`activityDenied` and `commentsDenied`, which the host that owns the fetch
36+
sets. `RecordActivityTimeline` and `RecordChatterPanel` take the same two
37+
optional props.
38+
- Two new `detail.*` strings, `activityAccessDenied` and `commentsAccessDenied`,
39+
are translated in all ten locale packs.

‎content/docs/plugins/plugin-detail.mdx‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,21 @@ Three sources, in precedence order:
218218
rows per page. This is what makes it work on a hand-authored record page
219219
with no host feeding it.
220220

221+
### When the read is refused
222+
223+
A refused read is not an empty feed. When the server refuses the feed's read
224+
(401, 403, or a permission envelope), the panel shows a no-permission state, a
225+
lock and "You don't have permission to view activity on this record.", in place
226+
of "No activity recorded". If some rows did load (the comments were readable and
227+
the activity was not, or the other way round), the rows stay and the notice
228+
above them names the half that is withheld. The console's record page applies
229+
the same rule to both of its reads, `sys_activity` and `sys_comment`.
230+
231+
Everything else keeps the empty state: a read that answers with zero rows, a 404
232+
(`sys_activity` on a deployment without the audit plugin), and any other
233+
failure, such as a 500. A refusal is not retried. `isRefusedFeedRead`, exported
234+
from this package, is the verdict both surfaces use.
235+
221236
`sys_activity` rows map to feed items like this:
222237
`created` / `updated` / `deleted` / `assigned` / `shared` → `field_change`,
223238
`completed` → `task`, `scheduled` → `event`, `system` → `system`.
Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* RecordDetailView: a REFUSED feed read is not an empty feed (objectui#11195).
6+
*
7+
* The record page owns the two reads behind its discussion panel,
8+
* `sys_activity` and `sys_comment`. Each used to end in `.catch(() => {})`, so
9+
* a 403 settled exactly like a 200 with zero rows: an invited member of a
10+
* hosted AI-built app opened a record, the server refused the activity read,
11+
* and the panel said "No comments yet" with nothing to tell a permission wall
12+
* from an empty record (objectstack-ai/cloud#2485).
13+
*
14+
* What is pinned, each on the rendered panel:
15+
* 1. a refused `sys_activity` read (403 envelope, and 401) shows the
16+
* no-permission state, and the read is not retried;
17+
* 2. the control: a 200 with zero rows shows the empty state, unchanged;
18+
* 3. a 404 is not a refusal, so the empty state stays;
19+
* 4. a 500 is not a refusal either, so the panel never says "no permission"
20+
* for it;
21+
* 5. a refused `sys_comment` read beside an answered `sys_activity` read
22+
* keeps the activity rows and says the comments are withheld.
23+
*
24+
* The harness is `RecordDetailView.feedLoading.test.tsx`'s: the synthesized
25+
* record page composes `record:discussion`, so the panel arrives through the
26+
* host's `DiscussionContextProvider` and the `record:chatter` renderer.
27+
*/
28+
29+
import * as React from 'react';
30+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
31+
import { render, screen, cleanup } from '@testing-library/react';
32+
import { MemoryRouter } from 'react-router-dom';
33+
import { MetadataCtx } from '@object-ui/react';
34+
35+
vi.mock('@object-ui/auth', async (importOriginal) => ({
36+
...(await importOriginal<Record<string, unknown>>()),
37+
useAuth: () => ({ user: { id: 'u1', name: 'Ada', image: null }, activeOrganization: null }),
38+
createAuthenticatedFetch: () => vi.fn(),
39+
}));
40+
41+
vi.mock('@object-ui/collaboration', async (importOriginal) => ({
42+
...(await importOriginal<Record<string, unknown>>()),
43+
useRecordPresence: () => [],
44+
PresenceAvatars: () => null,
45+
}));
46+
47+
vi.mock('sonner', () => ({
48+
toast: Object.assign(vi.fn(), {
49+
success: vi.fn(),
50+
error: vi.fn(),
51+
info: vi.fn(),
52+
warning: vi.fn(),
53+
loading: vi.fn(),
54+
dismiss: vi.fn(),
55+
}),
56+
}));
57+
58+
vi.mock('./ActionConfirmDialog', () => ({ ActionConfirmDialog: () => null }));
59+
vi.mock('./ActionParamDialog', () => ({ ActionParamDialog: () => null }));
60+
vi.mock('./ActionResultDialog', () => ({ ActionResultDialog: () => null }));
61+
vi.mock('./FlowRunner', () => ({ FlowRunner: () => null }));
62+
vi.mock('./MetadataInspector', () => ({
63+
MetadataPanel: () => null,
64+
useMetadataInspector: () => ({ showDebug: false, toggle: () => {} }),
65+
}));
66+
67+
import { RecordDetailView } from './RecordDetailView';
68+
69+
const EMPTY_COMMENTS = 'No comments yet';
70+
const ACTIVITY_DENIED = "You don't have permission to view activity on this record.";
71+
const COMMENTS_DENIED = "You don't have permission to view comments on this record.";
72+
const OBJECT_NAME = 'crm_account';
73+
const RECORD_ID = 'rec-alpha';
74+
75+
const OBJECTS = [
76+
{
77+
name: OBJECT_NAME,
78+
label: 'Account',
79+
managedBy: 'platform',
80+
fields: {
81+
id: { type: 'text', label: 'Id' },
82+
name: { type: 'text', label: 'Name' },
83+
},
84+
},
85+
];
86+
87+
/**
88+
* A rejected read in the shape the ObjectStack client throws it: the HTTP
89+
* status on `httpStatus` and the ADR-0112 code on `code`.
90+
*/
91+
const rejection = (httpStatus: number, code: string) =>
92+
Object.assign(new Error(`${httpStatus} ${code}`), { httpStatus, code });
93+
94+
interface FeedResponses {
95+
sys_comment: () => Promise<any>;
96+
sys_activity: () => Promise<any>;
97+
}
98+
99+
function makeDataSource(feed: FeedResponses) {
100+
const find = vi.fn((objectName: string) => {
101+
if (objectName === 'sys_comment') return feed.sys_comment();
102+
if (objectName === 'sys_activity') return feed.sys_activity();
103+
return Promise.resolve({ data: [] });
104+
});
105+
return {
106+
find,
107+
findOne: vi.fn(async () => ({ id: RECORD_ID, name: 'Alpha' })),
108+
create: vi.fn(async () => ({})),
109+
update: vi.fn(async () => ({})),
110+
delete: vi.fn(async () => ({})),
111+
} as any;
112+
}
113+
114+
function makeMetadata() {
115+
return {
116+
objects: OBJECTS,
117+
pages: [],
118+
loading: false,
119+
error: null,
120+
refresh: async () => {},
121+
invalidate: () => {},
122+
ensureType: async () => [],
123+
getItem: async () => null,
124+
getItemsByType: () => [],
125+
} as any;
126+
}
127+
128+
function renderDetail(dataSource: any) {
129+
return render(
130+
<MemoryRouter initialEntries={[`/app/demo/${OBJECT_NAME}/${RECORD_ID}`]}>
131+
<MetadataCtx.Provider value={makeMetadata()}>
132+
<RecordDetailView
133+
dataSource={dataSource}
134+
objects={OBJECTS}
135+
onEdit={() => {}}
136+
objectNameOverride={OBJECT_NAME}
137+
recordIdOverride={RECORD_ID}
138+
embedded
139+
/>
140+
</MetadataCtx.Provider>
141+
</MemoryRouter>,
142+
);
143+
}
144+
145+
const readsOf = (dataSource: any, objectName: string) =>
146+
dataSource.find.mock.calls.filter((call: unknown[]) => call[0] === objectName).length;
147+
148+
/** Let every settled read's follow-up render land before counting reads. */
149+
const settle = () => new Promise((resolve) => setTimeout(resolve, 50));
150+
151+
beforeEach(() => {
152+
cleanup();
153+
vi.stubGlobal(
154+
'fetch',
155+
vi.fn(async () =>
156+
new Response(JSON.stringify({ data: [] }), {
157+
status: 200,
158+
headers: { 'content-type': 'application/json' },
159+
}),
160+
),
161+
);
162+
});
163+
164+
afterEach(() => {
165+
vi.unstubAllGlobals();
166+
vi.clearAllMocks();
167+
});
168+
169+
describe('RecordDetailView: a refused sys_activity read shows the no-permission state (objectui#11195)', () => {
170+
it('a 403 PERMISSION_DENIED envelope shows the no-permission state, not the empty state', async () => {
171+
const dataSource = makeDataSource({
172+
sys_comment: () => Promise.resolve({ data: [] }),
173+
sys_activity: () => Promise.reject(rejection(403, 'PERMISSION_DENIED')),
174+
});
175+
176+
renderDetail(dataSource);
177+
178+
const notice = await screen.findByTestId('activity-access-denied');
179+
expect(notice.textContent).toContain(ACTIVITY_DENIED);
180+
expect(notice.querySelector('[data-denied-source="activity"]')).not.toBeNull();
181+
expect(notice.querySelector('[data-denied-source="comments"]')).toBeNull();
182+
// Visually distinct from the empty state, which is not rendered at all.
183+
expect(screen.queryByText(EMPTY_COMMENTS)).toBeNull();
184+
expect(screen.queryByTestId('activity-loading')).toBeNull();
185+
// The message never names the object's internal name, or the table.
186+
expect(notice.textContent).not.toContain(OBJECT_NAME);
187+
expect(notice.textContent).not.toContain('sys_activity');
188+
});
189+
190+
it('does not retry a refused read', async () => {
191+
// The baseline is the SAME page answered with zero rows: the refusal may
192+
// issue the read no more often than an answered read is issued.
193+
const answered = makeDataSource({
194+
sys_comment: () => Promise.resolve({ data: [] }),
195+
sys_activity: () => Promise.resolve({ data: [] }),
196+
});
197+
renderDetail(answered);
198+
await screen.findByText(EMPTY_COMMENTS);
199+
await settle();
200+
const answeredReads = readsOf(answered, 'sys_activity');
201+
expect(answeredReads).toBeGreaterThan(0);
202+
cleanup();
203+
204+
const refused = makeDataSource({
205+
sys_comment: () => Promise.resolve({ data: [] }),
206+
sys_activity: () => Promise.reject(rejection(403, 'PERMISSION_DENIED')),
207+
});
208+
renderDetail(refused);
209+
await screen.findByTestId('activity-access-denied');
210+
await settle();
211+
212+
expect(readsOf(refused, 'sys_activity')).toBe(answeredReads);
213+
});
214+
215+
it('a 401 is a refused read too', async () => {
216+
const dataSource = makeDataSource({
217+
sys_comment: () => Promise.resolve({ data: [] }),
218+
sys_activity: () => Promise.reject(rejection(401, 'UNAUTHORIZED')),
219+
});
220+
221+
renderDetail(dataSource);
222+
223+
const notice = await screen.findByTestId('activity-access-denied');
224+
expect(notice.textContent).toContain(ACTIVITY_DENIED);
225+
expect(screen.queryByText(EMPTY_COMMENTS)).toBeNull();
226+
});
227+
228+
it('control: a 200 with zero rows shows the empty state, unchanged', async () => {
229+
const dataSource = makeDataSource({
230+
sys_comment: () => Promise.resolve({ data: [] }),
231+
sys_activity: () => Promise.resolve({ data: [] }),
232+
});
233+
234+
renderDetail(dataSource);
235+
236+
expect(await screen.findByText(EMPTY_COMMENTS)).toBeTruthy();
237+
expect(screen.queryByTestId('activity-access-denied')).toBeNull();
238+
expect(screen.queryByText(ACTIVITY_DENIED)).toBeNull();
239+
});
240+
241+
it('a 404 is not a refusal: the empty state stays', async () => {
242+
const dataSource = makeDataSource({
243+
sys_comment: () => Promise.resolve({ data: [] }),
244+
sys_activity: () => Promise.reject(rejection(404, 'OBJECT_NOT_FOUND')),
245+
});
246+
247+
renderDetail(dataSource);
248+
249+
expect(await screen.findByText(EMPTY_COMMENTS)).toBeTruthy();
250+
expect(screen.queryByTestId('activity-access-denied')).toBeNull();
251+
});
252+
253+
it('a 500 is not "no permission"', async () => {
254+
const dataSource = makeDataSource({
255+
sys_comment: () => Promise.resolve({ data: [] }),
256+
sys_activity: () => Promise.reject(rejection(500, 'INTERNAL_ERROR')),
257+
});
258+
259+
renderDetail(dataSource);
260+
261+
// The panel has no error state of its own, so a failure that is not a
262+
// refusal still settles on the empty state.
263+
expect(await screen.findByText(EMPTY_COMMENTS)).toBeTruthy();
264+
expect(screen.queryByTestId('activity-access-denied')).toBeNull();
265+
expect(screen.queryByText(ACTIVITY_DENIED)).toBeNull();
266+
});
267+
});
268+
269+
describe('RecordDetailView: a refused sys_comment read beside an answered sys_activity read (objectui#11195)', () => {
270+
it('keeps the activity rows and says the comments are withheld', async () => {
271+
const dataSource = makeDataSource({
272+
sys_comment: () => Promise.reject(rejection(403, 'PERMISSION_DENIED')),
273+
sys_activity: () =>
274+
Promise.resolve({
275+
data: [
276+
{
277+
id: 'act-1',
278+
type: 'updated',
279+
summary: 'Stage moved to qualified',
280+
timestamp: '2026-01-02T00:00:00.000Z',
281+
actor_name: 'Grace',
282+
},
283+
],
284+
}),
285+
});
286+
287+
renderDetail(dataSource);
288+
289+
expect(await screen.findByText('Stage moved to qualified')).toBeTruthy();
290+
const notice = await screen.findByTestId('activity-access-denied');
291+
expect(notice.textContent).toContain(COMMENTS_DENIED);
292+
expect(notice.textContent).not.toContain(ACTIVITY_DENIED);
293+
expect(notice.querySelector('[data-denied-source="comments"]')).not.toBeNull();
294+
expect(notice.querySelector('[data-denied-source="activity"]')).toBeNull();
295+
});
296+
});

0 commit comments

Comments
 (0)