Skip to content

Commit 59833c2

Browse files
committed
fix(record-page): offer ✓ and Edit on others' comments only where the server admits them (#36075)
The platform's row floor lets a rank-and-file member update only the rows they created, before the comment rules run, so a member's ✓ on a colleague's thread and a record editor's Edit of a colleague's comment were refused (measured 403 on the dev rig). The panel now asks the explain engine once, on the first top-level comment the viewer did not write, when the reader first reaches into the open panel; ✓ and Edit on others' rows need its definite allow (new DiscussionContext.updatesOthersComments). Delete keeps its own gate. Also from the declaration review: the moderation verdict needs `allowed` beside `record.visible` (S3); a resolver the page cannot name is read by id from sys_user instead of the capped mention list (S2); prose says the gate the code uses (S1); a page case pins the gates apart (N3). Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6bhgT8AtWDue4oTFNAE6H
1 parent 9d503c6 commit 59833c2

12 files changed

Lines changed: 362 additions & 61 deletions

‎.changeset/36075-comments-resolved.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
'@object-ui/i18n': patch
77
---
88

9-
feat(record-page): the desktop comment panel resolves and reopens threads, filters them, counts the unresolved ones, and offers Edit and Delete on other people's comments to a member who may edit the record
9+
feat(record-page): the desktop comment panel resolves and reopens threads, filters them, counts the unresolved ones, and offers Edit and Delete on other people's comments only where the server admits them
1010

11-
Clause-②: yes (widening) — `@object-ui/react`'s `DiscussionContextValue` adds two optional members: `onResolveComment(itemId, resolved)` and `moderatesComments`. `@object-ui/types`' `FeedItem` adds five optional members: `resolved`, `resolvedById`, `resolvedByName`, `resolvedAt`, `mentionsViewer`. `@object-ui/plugin-detail` adds exports `useRecordVerdict` (the three-state verdict `useRecordEditable` fails open on; `useRecordEditable` reads exactly as before), `threadResolvable`, `threadResolved`, `threadInvolvesViewer`, `filterCommentThreads`, `unresolvedThreadCount`, `DEFAULT_COMMENT_THREAD_FILTER` and the type `CommentThreadFilter`; `RecordCommentsData` adds `resolvable`, `onResolveComment` and `moderates`, and its `count` is now the unresolved threads; `CommentItemActions` adds `onResolve` and `resolved`; `CommentHoverActionsProps` adds `resolved`; `RecordCommentThreadProps['comments']` may carry `onResolveComment` and `moderates`. `@object-ui/i18n` adds ten keys to every pack: `detail.reopenThread`, `detail.threadResolved`, `detail.threadResolvedBy`, `detail.filterComments`, `detail.showResolvedComments`, `detail.commentsInvolvingMe`, `detail.noUnresolvedComments`, `detail.noCommentsInvolvingMe`, `detail.showAllComments`, `detail.commentResolveFailed`. Nothing existing is removed or re-typed.
11+
Clause-②: yes (widening) — `@object-ui/react`'s `DiscussionContextValue` adds three optional members: `onResolveComment(itemId, resolved)`, `moderatesComments` and `updatesOthersComments`. `@object-ui/types`' `FeedItem` adds five optional members: `resolved`, `resolvedById`, `resolvedByName`, `resolvedAt`, `mentionsViewer`. `@object-ui/plugin-detail` adds exports `useRecordVerdict` (the three-state verdict `useRecordEditable` fails open on; a definite allow is the explain answer's `allowed` together with its `record.visible`, as the server admits a by-id write, so `useRecordEditable` reads as before except that an answer whose `allowed` is false beside a visible record, such as an on-behalf-of session whose delegator is gone, now reads not editable), `threadResolvable`, `threadResolved`, `threadInvolvesViewer`, `filterCommentThreads`, `unresolvedThreadCount`, `DEFAULT_COMMENT_THREAD_FILTER` and the type `CommentThreadFilter`; `RecordCommentsData` adds `resolvable`, `onResolveComment`, `moderates` and `updatesOthers`, and its `count` is now the unresolved threads; `CommentItemActions` adds `onResolve` and `resolved`; `CommentHoverActionsProps` adds `resolved`; `RecordCommentThreadProps['comments']` may carry `onResolveComment`, `moderates` and `updatesOthers`. `@object-ui/i18n` adds ten keys to every pack: `detail.reopenThread`, `detail.threadResolved`, `detail.threadResolvedBy`, `detail.filterComments`, `detail.showResolvedComments`, `detail.commentsInvolvingMe`, `detail.noUnresolvedComments`, `detail.noCommentsInvolvingMe`, `detail.showAllComments`, `detail.commentResolveFailed`. Nothing existing is removed or re-typed.
1212
Metadata-protocol: none
1313
Skills-docs: none — no skill under `skills/**` teaches the console's comment panel; `content/docs/frontend/plugins/plugin-detail.mdx` and the plugin-detail README gain resolved threads, the filter and the moderator's Edit and Delete in this change.
1414

1515
The desktop record page's comment panel (objectstack#36075) gains the resolved threads #36071 stores:
1616

17-
- ✓ in a thread's first comment's action row marks the thread resolved: it leaves the list and the comments icon's number, now the unresolved threads, drops by one. Anyone who may comment on the record may resolve (maintainer ruling 7063285032).
17+
- ✓ in a thread's first comment's action row marks the thread resolved: it leaves the list and the comments icon's number, now the unresolved threads, drops by one. ✓ is offered under the `sys_comment` update grant: on a thread the viewer started, and on anyone's only where the explain engine admits the viewer's update of a comment they did not write. Today the platform's row floor admits that for administrators, not for rank-and-file members, so a member resolves only the threads they started until the server carries ruling 7063285032 (any reader of the record may resolve) past that floor.
1818
- The filter menu at the panel's top right holds 「显示已解决」, which shows resolved threads marked 「已由 X 解决」 (their ✓ reopens them), and 「只看我参与的」, the threads the viewer started, replied in or is mentioned in. The filter is not stored. With every thread resolved, the panel says so and offers to show them all.
1919
- A reply into a resolved thread shows the thread reopened, as the platform stores it.
20-
- Edit and Delete under More are offered on other members' comments to a member the explain engine admits to update the record by id, the server's own rule for editing someone else's comment; only on a definite allow, so a member is never offered a write the server refuses. Their own comments keep them as before.
20+
- The resolver is named from the people the page already knows (the viewer and the discussion's authors); any other resolver is named by one `sys_user` read of exactly those ids, after the discussion is drawn. Where that read is refused, the mark reads 「已解决」.
21+
- Edit and Delete under More are offered on other members' comments to a viewer the explain engine admits to update the record by id, the server's rule for moderating someone else's comment; Edit also needs the explain engine to admit their update of a comment they did not write (the row floor above). Both are asked only on a definite allow: pending, a refusal, an error or a deployment without the explain service offers them on the viewer's own comments alone. Their own comments keep them as before.
2122

22-
Unchanged: no server permission changes; a deployment whose comment rows carry no `is_resolved` shows no ✓ and no filter, and the icon counts every thread; hand-written record pages and the phone keep their feed as before.
23+
Unchanged: no server permission changes (a deployment without the explain service shows ✓ and Edit on the viewer's own rows only, administrators included); a deployment whose comment rows carry no `is_resolved` shows no ✓ and no filter, and the icon counts every thread; hand-written record pages and the phone keep their feed as before.

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,14 @@ the record drawer), and no longer inside the 动态 (Activity) tab
210210
first, the comment box at the foot. A thread's replies fold to 「N 条回复」
211211
and open in place. A comment's actions (Reply, an emoji, ✓ on a thread's
212212
first comment, and More with Edit and Delete) appear at its top right while
213-
the pointer is over it. Edit and Delete are on your own comments, and on
214-
everyone's for a member who may edit the record (the server lets them).
215-
- **Resolved threads**: ✓ marks a thread resolved (anyone who may comment on
216-
the record may) and it leaves the list; the icon's number drops by one. The
213+
the pointer is over it. Edit and Delete are on your own comments. On other
214+
people's they appear only where the server would accept them: Delete for a
215+
member who may edit the record, Edit when the server also lets you change a
216+
comment you did not write (today, administrators).
217+
- **Resolved threads**: ✓ marks a thread resolved and it leaves the list; the
218+
icon's number drops by one. It is on the threads you started, and on other
219+
people's only where the server would accept it: today administrators, since
220+
the platform lets a member change only the rows they wrote. The
217221
filter menu at the panel's top right holds 「显示已解决」, which shows resolved
218222
threads marked with who resolved them (their ✓ reopens them), and
219223
「只看我参与的」, the threads you started, replied in or are mentioned in. A

‎ui/packages/app-shell/src/views/RecordDetailView.commentsResolved-36075.test.tsx‎

Lines changed: 120 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,11 @@ const AUTHORED_PAGE = {
120120
],
121121
};
122122

123-
function makeDataSource() {
123+
function makeDataSource(rows: ReadonlyArray<Record<string, unknown>> = ROWS, users: ReadonlyArray<Record<string, unknown>> = []) {
124124
return {
125125
find: vi.fn(async (objectName: string) => {
126-
if (objectName === 'sys_comment') return { data: ROWS.map((r) => ({ ...r })) };
126+
if (objectName === 'sys_comment') return { data: rows.map((r) => ({ ...r })) };
127+
if (objectName === 'sys_user') return { data: users.map((u) => ({ ...u })) };
127128
return { data: [] };
128129
}),
129130
findOne: vi.fn(async (_o: string, id: string) => ({ id, subject: `Case ${id}` })),
@@ -170,10 +171,12 @@ interface MountOptions {
170171
objectName?: string;
171172
pages?: unknown[];
172173
embedded?: boolean;
174+
rows?: ReadonlyArray<Record<string, unknown>>;
175+
users?: ReadonlyArray<Record<string, unknown>>;
173176
}
174177

175-
async function mount({ objectName = OBJECT_NAME, pages = [], embedded = false }: MountOptions = {}) {
176-
const dataSource = makeDataSource();
178+
async function mount({ objectName = OBJECT_NAME, pages = [], embedded = false, rows, users }: MountOptions = {}) {
179+
const dataSource = makeDataSource(rows, users);
177180
const rendered = render(
178181
<I18nProvider config={{ defaultLanguage: 'en', detectBrowserLanguage: false }} persistLanguage={false}>
179182
<MePermissionsProvider initialPermissions={PERMS}>
@@ -202,19 +205,30 @@ const panel = (root: HTMLElement) => root.querySelector('[data-comments-panel]')
202205
const placement = (root: HTMLElement) =>
203206
root.querySelector('[data-comments-placement]')?.getAttribute('data-comments-placement') ?? null;
204207

205-
/** The explain engine's answer to every `POST /security/explain`: `verdict` true, false, or none. */
206-
function stubExplain(verdict: boolean | null) {
208+
/**
209+
* The explain engine's answer to every `POST /security/explain`: true, false,
210+
* or none (`null`): `verdict` for the record, `commentVerdict` for a
211+
* `sys_comment` row (the row floor on a comment the viewer did not write).
212+
*/
213+
function stubExplain(verdict: boolean | null, commentVerdict: boolean | null = verdict) {
207214
vi.stubGlobal(
208215
'fetch',
209-
vi.fn(async (url: unknown) => {
216+
vi.fn(async (url: unknown, init?: { body?: unknown }) => {
217+
let asked: { object?: string; recordId?: string } = {};
218+
try { asked = JSON.parse(String(init?.body ?? '{}')); } catch { /* not a JSON body */ }
219+
const answer = asked.object === 'sys_comment' ? commentVerdict : verdict;
210220
const body =
211-
String(url).includes('/security/explain') && verdict !== null
212-
? { allowed: true, record: { recordId: RECORD_ID, visible: verdict } }
221+
String(url).includes('/security/explain') && answer !== null
222+
? { allowed: true, record: { recordId: asked.recordId ?? RECORD_ID, visible: answer } }
213223
: { data: [] };
214224
return new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
215225
}),
216226
);
217227
}
228+
const explainAsked = () =>
229+
((globalThis.fetch as any).mock.calls as Array<[unknown, { body?: unknown }?]>)
230+
.filter(([url]) => String(url).includes('/security/explain'))
231+
.map(([, init]) => JSON.parse(String(init?.body ?? '{}')));
218232

219233
function setWindowWidth(width: number) {
220234
Object.defineProperty(window, 'innerWidth', { configurable: true, writable: true, value: width });
@@ -242,11 +256,15 @@ const commentIn = (root: HTMLElement, text: string) =>
242256
el.querySelector(':scope > .pl-7 [data-comment-body]')?.textContent?.includes(text),
243257
) as HTMLElement | undefined;
244258

259+
/** The reader reaches into the open panel: the pointer enters it. */
260+
const engage = (root: HTMLElement) => fireEvent.pointerEnter(root.querySelector('[data-comments-placement]')!);
261+
245262
async function openPanel() {
246263
const mounted = await mount();
247264
await waitFor(() => expect(button(mounted.container)).not.toBeNull());
248265
fireEvent.click(button(mounted.container)!);
249266
await within(panel(mounted.container)!).findByText(ADA_BODY);
267+
engage(mounted.container);
250268
return mounted;
251269
}
252270

@@ -268,6 +286,27 @@ describe('resolved threads in the record comment panel (objectstack#36075)', ()
268286
expect(p.getByText('Resolved by Linus')).toBeInTheDocument();
269287
});
270288

289+
it('a resolver the page cannot name is read by id, once, and named', async () => {
290+
const rows = ROWS.map((r) => (r.id === 'c-grace' ? { ...r, resolved_by: 'u-zoe' } : r));
291+
const { container, dataSource } = await mount({ rows, users: [{ id: 'u-zoe', name: 'Zoe' }] });
292+
await waitFor(() => expect(button(container)).not.toBeNull());
293+
fireEvent.click(button(container)!);
294+
await within(panel(container)!).findByText(ADA_BODY);
295+
await showResolved();
296+
expect(await within(panel(container)!).findByText('Resolved by Zoe')).toBeInTheDocument();
297+
const userReads = dataSource.find.mock.calls.filter(([o]: [string]) => o === 'sys_user');
298+
expect(userReads).toEqual([
299+
['sys_user', { $filter: { id: { $in: ['u-zoe'] } }, $top: 1, $select: ['id', 'name'] }],
300+
]);
301+
});
302+
303+
it('reads no user when every resolver is named on the page', async () => {
304+
const { container, dataSource } = await openPanel();
305+
await showResolved();
306+
expect(await within(panel(container)!).findByText('Resolved by Linus')).toBeInTheDocument();
307+
expect(dataSource.find.mock.calls.some(([o]: [string]) => o === 'sys_user')).toBe(false);
308+
});
309+
271310
it('✓ writes is_resolved alone on the top-level comment; the thread leaves and the count drops', async () => {
272311
const { container, dataSource } = await openPanel();
273312
await waitFor(() => expect(count(container)).toBe('1'));
@@ -296,9 +335,14 @@ describe('resolved threads in the record comment panel (objectstack#36075)', ()
296335
});
297336

298337
it('the reopen ✓ writes is_resolved false and the thread counts again', async () => {
338+
stubExplain(null, true);
299339
const { container, dataSource } = await openPanel();
300340
await showResolved();
301-
const grace = await waitFor(() => commentIn(container, GRACE_BODY)!);
341+
const grace = await waitFor(() => {
342+
const el = commentIn(container, GRACE_BODY)!;
343+
expect(el.querySelector('[data-comment-action="reopen"]')).not.toBeNull();
344+
return el;
345+
});
302346
await act(async () => {
303347
fireEvent.click(grace.querySelector('[data-comment-action="reopen"]')!);
304348
});
@@ -349,6 +393,72 @@ describe("Edit and Delete on another member's comment (objectstack#36075 item 6)
349393
expect(moreOn(container, ADA_BODY)).not.toBeNull();
350394
});
351395

396+
it('the resolve control rides its own gate: ✓ on another member\'s thread beside a moderation refusal', async () => {
397+
stubExplain(false, true);
398+
const { container } = await openPanel();
399+
await showResolved();
400+
await waitFor(() =>
401+
expect(commentIn(container, GRACE_BODY)!.querySelector('[data-comment-action="reopen"]')).not.toBeNull(),
402+
);
403+
expect(moreOn(container, GRACE_BODY)).toBeNull();
404+
});
405+
});
406+
407+
describe("the row floor on another member's comment (objectstack#36075)", () => {
408+
const moreOn = (root: HTMLElement, text: string) => commentIn(root, text)?.querySelector(':scope > [data-comment-actions] [data-comment-action="more"]') ?? null;
409+
const reopenOn = (root: HTMLElement, text: string) => commentIn(root, text)?.querySelector('[data-comment-action="reopen"]') ?? null;
410+
411+
it('asks ONE explain of a top-level comment the viewer did not write, once the reader reaches into the open panel', async () => {
412+
stubExplain(true);
413+
const mounted = await mount();
414+
await waitFor(() => expect(button(mounted.container)).not.toBeNull());
415+
expect(explainAsked().filter((q) => q.object === 'sys_comment')).toEqual([]);
416+
fireEvent.click(button(mounted.container)!);
417+
await within(panel(mounted.container)!).findByText(ADA_BODY);
418+
// Opening the panel asks nothing (objectstack#28470).
419+
await act(async () => {});
420+
expect(explainAsked().filter((q) => q.object === 'sys_comment')).toEqual([]);
421+
engage(mounted.container);
422+
// Twice in, still one question.
423+
engage(mounted.container);
424+
await waitFor(() =>
425+
expect(explainAsked().filter((q) => q.object === 'sys_comment')).toEqual([
426+
expect.objectContaining({ object: 'sys_comment', operation: 'update', recordId: 'c-grace' }),
427+
]),
428+
);
429+
});
430+
431+
it('refused: no ✓ and no Edit on another member\'s rows, Delete still where the viewer moderates, own rows unchanged', async () => {
432+
stubExplain(true, false);
433+
const { container } = await openPanel();
434+
await showResolved();
435+
await waitFor(() => expect(moreOn(container, GRACE_BODY)).not.toBeNull());
436+
expect(reopenOn(container, GRACE_BODY)).toBeNull();
437+
fireEvent.pointerDown(moreOn(container, GRACE_BODY)!, { button: 0, ctrlKey: false, pointerType: 'mouse' });
438+
expect(await within(document.body).findByRole('menuitem', { name: 'Delete' })).toBeInTheDocument();
439+
expect(within(document.body).queryByRole('menuitem', { name: 'Edit' })).toBeNull();
440+
expect(commentIn(container, ADA_BODY)!.querySelector('[data-comment-action="resolve"]')).not.toBeNull();
441+
});
442+
443+
it('admitted: ✓ and Edit on another member\'s rows', async () => {
444+
stubExplain(true, true);
445+
const { container } = await openPanel();
446+
await showResolved();
447+
await waitFor(() => expect(reopenOn(container, GRACE_BODY)).not.toBeNull());
448+
fireEvent.pointerDown(moreOn(container, GRACE_BODY)!, { button: 0, ctrlKey: false, pointerType: 'mouse' });
449+
expect(await within(document.body).findByRole('menuitem', { name: 'Edit' })).toBeInTheDocument();
450+
});
451+
452+
it('not on a guess: no answer offers ✓ on the viewer\'s own threads alone', async () => {
453+
stubExplain(null);
454+
const { container } = await openPanel();
455+
await showResolved();
456+
await waitFor(() => expect(commentIn(container, GRACE_BODY)).toBeDefined());
457+
await act(async () => {});
458+
expect(reopenOn(container, GRACE_BODY)).toBeNull();
459+
expect(commentIn(container, ADA_BODY)!.querySelector('[data-comment-action="resolve"]')).not.toBeNull();
460+
});
461+
352462
it('not offered on a guess: an explain answer with no record verdict offers the own comments alone', async () => {
353463
stubExplain(null);
354464
const { container } = await openPanel();

0 commit comments

Comments
 (0)