Skip to content

Commit b631573

Browse files
feat(console): revoke an authorized AI assistant from Connect an Agent, and an admin widget for a person's assistants (#31084)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6Jao5pkwaKihk9gPVY4NVju7YY)_ Part of #30894 (part 2: the assistants' Revoke, plus the ui half of the administrator view. The card stays open for the server half: one "AI Assistants" tab on the `sys_user` record page that names the widget added here, filed by the seat.) Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 改了什么:「连接 AI 助手」页里已授权的每个 AI 助手旁新增「撤销」按钮,确认后立即收回该助手的访问权限并刷新列表;删掉「暂不支持在此页面撤销」那行提示。另新增一个管理员组件 `mcp:authorized-assistants`,放在用户记录页上即可查看并撤销此人授权的助手(目前还没有页面引用它)。 - 为什么改:OAuth 授权页承诺「可以随时在账户设置中撤销访问权限」,第一部分只做了列表;服务端撤销接口 #31048 已合并,这一步把承诺补完整,并为管理员替员工撤销准备好界面。 - 风险与回滚:只调用已上线的两个撤销接口(本人 / 平台管理员),每次撤销前都要确认;管理员组件在页面引用前不会出现。回滚即还原本 PR,无数据迁移。 - 先看:ui/packages/app-shell/src/console/connect/AuthorizedAccessList.tsx(撤销流程与撤销后重读)、ManagedPersonAssistants.tsx(只从记录上下文取用户 id)、ui/packages/i18n/src/locales/en.ts(新增 5 个、删除 1 个 connectAgent.access.* 键)。 - 两分钟验证:pnpm dev 后以授权过助手的用户登录,打开 账户 → 连接 AI 助手,在某个助手上点「撤销」并确认,该行消失,该助手下一次 MCP 调用被拒绝(401)。 - 需要你做的:无,席位落地。 ## What changes - **Assistant Revoke** (`AuthorizedAccessList.tsx`). The assistants half is now its own `AuthorizedAssistantsSection`. Every assistant row carries a Revoke. It asks first, naming the assistant ("Revoke access for Claude Desktop?", the unnamed fallback for a nameless client), then calls `oauth.authorizedClients.withdraw(id)` with the row's consent id. The list is read again after every withdraw, answered or refused: a refusal is most often a grant already withdrawn elsewhere (the server answers 404 for it), so its message is shown and the stale row leaves. Revoke buttons wait while a withdraw is in flight. The `connectAgent.access.withdrawLater` line is removed. The API-key half is unchanged. - **Administrator view, ui half** (`ManagedPersonAssistants.tsx`, new). SDUI widget registered ONCE as `mcp:authorized-assistants` (`namespace: 'mcp'`, `skipFallback: true`, so no bare `authorized-assistants` and no `app-shell:` spelling). It reads `className` from the node and one thing from the page: the bound record from `useRecordContext()`, which must be a `sys_user` record with an id. It takes no props. It renders `AuthorizedAssistantsSection` with `forUserId` = that id, which lists through `oauth.authorizedClients.listForUser(userId)` and revokes through `withdrawForUser(userId, id)`, with the same rows and confirm. Off a `sys_user` record (Studio palette, any other object's page, no id) it renders nothing. Those doors are platform-admin only; anyone else gets the server's 403 shown as a failed read, never as an empty list. No page names the widget yet, so nothing changes on screen until the server card (#31085) adds the tab. - **Its `@object-ui/types` arm** (`zod/mcp-authorized-assistants.zod.ts` `McpAuthorizedAssistantsSchema`, TS twin `mcp-authorized-assistants.ts`), a member of `AnyComponentSchema` / `AnySchema`, so `objectui validate` claims the type instead of refusing it at `type` (the registered-types ratchet's namespaced pin stays 306). Read from the widget's read points: `properties` may only be `{}`; `body` / `children` are refused by name with the family clause. Pinned by `mcp-authorized-assistants-arm.test.ts`; the mirror-parity pair count moves 197 → 198 and the emit-headroom table gains the arm. - `ui/packages/app-shell/src/index.ts` imports the widget for its registration, and `package.json` `sideEffects` lists it (dist and src), as for `ConnectAgentWidget`. - `ui/packages/cli/src/utils/known-schema-types.ts` regenerated (`node scripts/regenerate-known-schema-types.mjs`): one line, `mcp:authorized-assistants`. The 10859 ratchet gains a row pinning that it registered with its arm. - **Language packs**, all eleven: added `connectAgent.access.withdrawTitle`, `withdrawBody`, `managedBody`, `managedEmpty`, `managedTruncated`; removed `withdrawLater`. Net +4 keys per pack; no existing key reworded. `zh-Hant` regenerated from `zh-Hans` with `gen:zh-hant`. - Changeset `.changeset/30894-assistant-revoke.md` (`@object-ui/app-shell`, `@object-ui/i18n`, `@object-ui/types`, `@object-ui/cli`: patch). ## Tests `AuthorizedAccessList.test.tsx`, 21 cases (12 before). New: every assistant row has a Revoke; Revoke asks first naming the assistant, Cancel withdraws nothing; a nameless assistant is named by the fallback; confirm calls `withdraw('consent_2')`, re-reads the list, the row leaves, keys are not re-read and `withdrawForUser` is not called; a refused withdraw (grant gone) names the refusal and still re-reads. §5, the admin widget: registered as `mcp:authorized-assistants`; on a `sys_user` record it lists through `listForUser('user_mia')` (never `list`) and revokes through `withdrawForUser('user_mia', 'consent_1')`, then re-reads; empty and truncated lines speak of "this person"; a refused read (not an admin) is named, not shown empty; off a `sys_user` record or without an id it renders and reads nothing. The old "no Revoke, withdrawLater shown" case is replaced by the Revoke cases. Ablation (one-off, on committed head 5087922): replacing the admin branch's `withdrawForUser(forUserId, client.id)` with `withdraw(client.id)` turned §5's revoke case red (1 failed, 20 passed); restored and verified `git diff HEAD` empty by `scripts/ablation-replace.mjs`. ## Acceptance notes - **Where the administrator view lands.** Setup shows one user only on the `sys_user` record page, which is server metadata (`packages/platform-objects/src/pages/sys-user.page.ts`, `kind: 'full'`, its own tab strip). The console has no ui-side way to add a tab there, so this PR ships the widget and the server card adds the tab: a `page:tabs` item whose body is `{ type: 'mcp:authorized-assistants', properties: {} }`. The widget needs nothing from the page but the bound record. Gating the tab to platform administrators is the server card's call; without it, a non-admin sees the 403 named. - **Shared files with #30898**: `ConnectAgentWidget.tsx` is not touched. In the packs, keys are only added and one removed; no existing string is reworded. - **Refusal text**: a refused withdraw shows the server's message ("No authorized assistant you may withdraw matches the supplied id.") under the list, and the list is re-read. - Follow-up #31076 (refresh-family delete not scoped to the organization) is server-side and does not change what the console calls. ## Verification <details><summary>Both withdraw doors, live on origin/main cb8f520 (showcase, fresh; admin + two members)</summary> - Own door `POST /auth/authorized-clients/withdraw`: the member's own grant 200 `{id}`, and the assistant's next MCP call 401 (200 before). Another member naming that id: 404 RESOURCE_NOT_FOUND, and the assistant's MCP call still 200. Unknown id 404; the same id a second time 404; missing `id` 400 VALIDATION_ERROR. The admin naming the member's id on the own door: 404. - Admin door `POST /auth/admin/authorized-clients/withdraw`: member caller 403 PERMISSION_DENIED; admin with the wrong `userId` 404; admin with the member's `userId` 200 `{id}`, the assistant's next MCP call 401, and `listForUser` then answers `[]`. - A user created through `admin/create-user` answers 403 PASSWORD_RESET_REQUIRED on these doors until they change their password (the server's existing rule, not new here). </details> <details><summary>Console, live (Vite dev against that backend), head 2583f17's code</summary> As a member with two grants (Claude Desktop, Cursor), on Account → Connect an Agent: both rows show a Revoke and the not-available-yet line is gone. Revoke on Claude Desktop opened "Revoke access for Claude Desktop? The assistant loses access at once. To use it again, it has to be authorized again."; confirming removed the row (Cursor stays). Claude Desktop's token then answered 401 on MCP while Cursor's still answered 200. The admin widget is not reachable live yet: no page names it (unit-tested, §5). </details> <details><summary>Local gates and tests</summary> - `pnpm --dir ui exec vitest run packages/app-shell/src/console/connect/`: 2 files, 37 tests passed. With `packages/i18n/`, the plugin-form `affordanceGrantMap-12082` write census and the product-neutral ratchet: 102 files, 1859 passed, 13 skipped. After merging `origin/main` (2583f17): connect + affordanceGrantMap + `check-side-effects-array`: 4 files, 138 passed. - `pnpm --filter @object-ui/app-shell type-check` and `@object-ui/i18n` type-check: exit 0. eslint on `console/connect/` and `index.ts`: 0 errors (3 existing warnings in `ConnectAgentWidget.tsx`, untouched). - `node scripts/pm/dispatch-gates.mjs --commands` derived 51 commands on the final change set; all 51 exit 0; `--ran` reconciliation: 51 derived, 51 run, 0 NOT-MEASURED. That includes `node scripts/check-sdui-manifest.mjs` exit 0 and `pnpm --dir ui exec vitest run scripts/` (170 files passed, 2 skipped) on fec0386, which first caught the missing `sideEffects` entry (fixed in fec0386). `check:type-check-debt` exit 0 on 5087922 (the package.json change after it touches no `typecheck` script). - `pnpm check:new-line-citations` (ui): 0 new citations. - NOT MEASURED locally: the `i18n-locale-en` eager-closure ceiling (needs the Console production build; CI's `Build & E2E UI` `check:eager-closure` is the verdict). The ceiling is not changed. </details> <details><summary>CI fix round, head 5044eb2</summary> - Cause of the red Test UI (6/16): `registered-types-validate-ratchet-10859.test.ts` counted 308 refused namespaced keys against the pin 306 — `mcp:authorized-assistants` and `app-shell:mcp:authorized-assistants` had no arm. Fixed by arming the type and registering it under one key; the pin is unchanged. - `pnpm --dir ui exec vitest run packages/cli/ packages/types/ packages/app-shell/src/console/connect/ packages/app-shell/src/__tests__/product-neutral-renderer.ratchet.test.ts scripts/`: 592 files passed, 2 skipped (15956 tests passed). - `@object-ui/types`, `@object-ui/app-shell`, `@object-ui/cli` type-check: exit 0. eslint on the new files: exit 0. ui `check:new-line-citations`: 0 new. - `dispatch-gates --commands`: 51 derived, all 51 exit 0, `--ran` 0 NOT-MEASURED (record: project files ui-seat-3/r2026-11-06/30894/gates-ran-p2-510c6e36.list); changeset gates re-run on 5044eb2 exit 0. </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (No spec change.) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; eslint on the touched files passes (the repo-wide `pnpm lint` is CI's). - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: n/a. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L9qiby1cruv4PSfF5pFmit --- _Generated by [Claude Code](https://claude.ai/code/session_01L9qiby1cruv4PSfF5pFmit)_ <!-- signed: domain:ui#3 · os-tesla · session_01L9qibxW6qraU2Z3mwupUGp --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ddd646d commit b631573

27 files changed

Lines changed: 749 additions & 98 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
'@object-ui/types': patch
5+
'@object-ui/cli': patch
6+
---
7+
8+
feat(console): revoke an authorized AI assistant from Connect an Agent, and an administrator widget for a person's assistants
9+
10+
Clause-②: yes (widening)
11+
Metadata-protocol: none
12+
13+
- **`@object-ui/app-shell`**: each row in Connect an Agent's "Authorized AI assistants" list now has a Revoke. It asks first, naming the assistant, then withdraws the grant through `oauth.authorizedClients.withdraw(id)`: the assistant's token is refused on its next call and it has to be authorized again to reconnect. The list is read again after every withdraw, so a grant already withdrawn elsewhere leaves it too, and the refusal is named. The line saying withdrawing was not available yet is gone. New SDUI widget `mcp:authorized-assistants` for a `sys_user` record page: it reads the person from the bound record (no props), lists their authorized assistants through `oauth.authorizedClients.listForUser(userId)` with the same rows and confirm-first Revoke, which calls `withdrawForUser(userId, id)`. Those doors are for platform administrators; anyone else sees the server's refusal as a failed read. Off a `sys_user` record it renders nothing, and it is drawn only where a page names it.
14+
- **`@object-ui/i18n`**: `connectAgent.access.withdrawTitle`, `withdrawBody`, `managedBody`, `managedEmpty` and `managedTruncated` added in all eleven packs; `connectAgent.access.withdrawLater` removed (net +4 keys per pack).
15+
- **`@object-ui/types`**: `McpAuthorizedAssistantsSchema` (zod arm) and its TypeScript twin, so a page placing `{ type: 'mcp:authorized-assistants' }` validates. The widget reads only `className`: `properties` may only be `{}`, and `body` / `children` are refused by name.
16+
- **`@object-ui/cli`**: `objectui check` knows the `mcp:authorized-assistants` type (the generated known-types list).

‎ui/packages/app-shell/package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"./dist/console/blocks/productBlocks.js",
1010
"./dist/console/cloud-connection/CloudConnectionPanel.js",
1111
"./dist/console/connect/ConnectAgentWidget.js",
12+
"./dist/console/connect/ManagedPersonAssistants.js",
1213
"./dist/console/diagnostics/CloudAiModelStatus.js",
1314
"./dist/console/home/CloudWorkspaceTimezoneNotice.js",
1415
"./dist/services/builtinComponents.js",
@@ -27,6 +28,7 @@
2728
"./src/console/blocks/productBlocks.tsx",
2829
"./src/console/cloud-connection/CloudConnectionPanel.tsx",
2930
"./src/console/connect/ConnectAgentWidget.tsx",
31+
"./src/console/connect/ManagedPersonAssistants.tsx",
3032
"./src/console/diagnostics/CloudAiModelStatus.tsx",
3133
"./src/console/home/CloudWorkspaceTimezoneNotice.tsx",
3234
"./src/services/builtinComponents.tsx",

‎ui/packages/app-shell/src/console/connect/AuthorizedAccessList.test.tsx‎

Lines changed: 150 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,22 @@
88
* client id when the client declares none), the granted scopes in the
99
* consent page's own words, when authorized, and "in the hour from" the
1010
* recorded last use or "not recorded"; the organization only when it is
11-
* not the active one; and no Revoke control on an assistant row;
11+
* not the active one;
12+
* - §1b Revoke on an assistant row asks first, naming the assistant; Cancel
13+
* withdraws nothing; confirming calls `withdraw(id)` and reads the list
14+
* again, and a refused withdraw (the grant already gone) names the refusal
15+
* and reads the list again too;
1216
* - §2 keys are the person's OWN `sys_api_key` rows: the read filters on the
1317
* signed-in user (a platform administrator's unfiltered read answers every
1418
* person's keys) and never selects the secret; revoked and expired keys
1519
* carry their state and no Revoke;
1620
* - §3 Revoke on an active key asks first, naming the key; Cancel writes
1721
* nothing; confirming writes `revoked: true` and the list re-reads in place;
18-
* - §4 empty, failed and signed-out states.
22+
* - §4 empty, failed and signed-out states;
23+
* - §5 the administrator's widget `mcp:authorized-assistants` on a `sys_user`
24+
* record page: it reads the person from the bound record, lists through
25+
* `listForUser` and revokes through `withdrawForUser`, and renders nothing
26+
* off a `sys_user` record.
1927
*
2028
* `t` echoes the key with any interpolation values appended, so assertions
2129
* read which string was asked for and with what.
@@ -55,8 +63,10 @@ vi.mock('@object-ui/auth', async (importOriginal) => ({
5563
}),
5664
}));
5765

58-
import { notifyDataChanged } from '@object-ui/react';
66+
import { ComponentRegistry } from '@object-ui/core';
67+
import { notifyDataChanged, RecordContextProvider } from '@object-ui/react';
5968
import { AuthorizedAccessList } from './AuthorizedAccessList';
69+
import { ManagedPersonAssistants } from './ManagedPersonAssistants';
6070

6171
type Row = Record<string, unknown>;
6272

@@ -93,6 +103,10 @@ const CLIENTS = [
93103
const FAR_FUTURE = '2999-01-01T00:00:00.000Z';
94104
let keyRows: Row[];
95105
let listMock: ReturnType<typeof vi.fn>;
106+
let withdrawMock: ReturnType<typeof vi.fn>;
107+
let listForUserMock: ReturnType<typeof vi.fn>;
108+
let withdrawForUserMock: ReturnType<typeof vi.fn>;
109+
let granted: typeof CLIENTS;
96110
let findMock: ReturnType<typeof vi.fn>;
97111
let updateMock: ReturnType<typeof vi.fn>;
98112

@@ -104,7 +118,18 @@ beforeEach(() => {
104118
{ id: 'k_revoked', name: 'old key', prefix: 'osk_ghi', created_at: '2026-10-01T10:00:00.000Z', last_used_at: null, expires_at: FAR_FUTURE, revoked: true },
105119
{ id: 'k_expired', name: 'stale key', prefix: 'osk_jkl', created_at: '2026-01-01T10:00:00.000Z', last_used_at: null, expires_at: '2026-02-01T00:00:00.000Z', revoked: false },
106120
];
107-
listMock = vi.fn(async () => ({ clients: CLIENTS, truncated: false }));
121+
granted = [...CLIENTS];
122+
listMock = vi.fn(async () => ({ clients: [...granted], truncated: false }));
123+
withdrawMock = vi.fn(async (id: string) => {
124+
if (!granted.some((c) => c.id === id)) throw new Error('No authorized assistant you may withdraw matches the supplied id.');
125+
granted = granted.filter((c) => c.id !== id);
126+
return { id };
127+
});
128+
listForUserMock = vi.fn(async () => ({ clients: [...granted], truncated: false }));
129+
withdrawForUserMock = vi.fn(async (_userId: string, id: string) => {
130+
granted = granted.filter((c) => c.id !== id);
131+
return { id };
132+
});
108133
findMock = vi.fn(async () => ({ data: keyRows.map((r) => ({ ...r })) }));
109134
updateMock = vi.fn(async (resource: string, id: string, patch: Row) => {
110135
keyRows = keyRows.map((r) => (r.id === id ? { ...r, ...patch } : r));
@@ -113,7 +138,16 @@ beforeEach(() => {
113138
return keyRows.find((r) => r.id === id);
114139
});
115140
adapter = {
116-
getClient: () => ({ oauth: { authorizedClients: { list: listMock } } }),
141+
getClient: () => ({
142+
oauth: {
143+
authorizedClients: {
144+
list: listMock,
145+
withdraw: withdrawMock,
146+
listForUser: listForUserMock,
147+
withdrawForUser: withdrawForUserMock,
148+
},
149+
},
150+
}),
117151
find: findMock,
118152
update: updateMock,
119153
};
@@ -173,12 +207,11 @@ describe('§1 authorized assistants', () => {
173207
expect(within(nameless).getByText('«connectAgent.access.unnamed»')).toBeInTheDocument();
174208
});
175209

176-
it('offers no Revoke on any assistant row, and says withdrawing is not available here yet', async () => {
210+
it('offers a Revoke on every assistant row', async () => {
177211
await renderSettled();
178212
for (const row of screen.getAllByTestId('authorized-assistant')) {
179-
expect(within(row).queryByRole('button')).toBeNull();
213+
expect(within(row).getByRole('button', { name: '«connectAgent.access.revoke»' })).toBeInTheDocument();
180214
}
181-
expect(screen.getByText('«connectAgent.access.withdrawLater»')).toBeInTheDocument();
182215
expect(screen.queryByText(/connectAgent\.access\.truncated/)).toBeNull();
183216
});
184217

@@ -189,6 +222,54 @@ describe('§1 authorized assistants', () => {
189222
});
190223
});
191224

225+
describe('§1b revoking an assistant', () => {
226+
it('asks first, naming the assistant; Cancel withdraws nothing', async () => {
227+
await renderSettled();
228+
fireEvent.click(within(assistantRow('Claude Desktop')).getByRole('button', { name: '«connectAgent.access.revoke»' }));
229+
const dialog = await screen.findByRole('alertdialog');
230+
expect(within(dialog).getByText('«connectAgent.access.withdrawTitle|Claude Desktop»')).toBeInTheDocument();
231+
expect(within(dialog).getByText('«connectAgent.access.withdrawBody»')).toBeInTheDocument();
232+
fireEvent.click(within(dialog).getByRole('button', { name: '«common.cancel»' }));
233+
await waitFor(() => expect(screen.queryByRole('alertdialog')).toBeNull());
234+
expect(withdrawMock).not.toHaveBeenCalled();
235+
});
236+
237+
it('names a nameless assistant by the fallback in the confirm', async () => {
238+
await renderSettled();
239+
fireEvent.click(within(assistantRow('client_nameless')).getByRole('button', { name: '«connectAgent.access.revoke»' }));
240+
const dialog = await screen.findByRole('alertdialog');
241+
expect(within(dialog).getByText('«connectAgent.access.withdrawTitle|«connectAgent.access.unnamed»»')).toBeInTheDocument();
242+
});
243+
244+
it('confirming withdraws the grant by its id and reads the list again', async () => {
245+
await renderSettled();
246+
fireEvent.click(within(assistantRow('Claude Desktop')).getByRole('button', { name: '«connectAgent.access.revoke»' }));
247+
const dialog = await screen.findByRole('alertdialog');
248+
fireEvent.click(within(dialog).getByRole('button', { name: '«connectAgent.access.revoke»' }));
249+
250+
await waitFor(() => expect(withdrawMock).toHaveBeenCalledWith('consent_2'));
251+
await waitFor(() => expect(listMock).toHaveBeenCalledTimes(2));
252+
await waitFor(() => expect(screen.getAllByTestId('authorized-assistant')).toHaveLength(2));
253+
expect(screen.queryByText('Claude Desktop')).toBeNull();
254+
// An assistant withdraw is not a key write: the keys are not re-read.
255+
expect(findMock).toHaveBeenCalledTimes(1);
256+
expect(withdrawForUserMock).not.toHaveBeenCalled();
257+
});
258+
259+
it('a refused withdraw names the refusal and still reads the list again', async () => {
260+
await renderSettled();
261+
// Withdrawn elsewhere after this page read the list: the server answers 404.
262+
granted = granted.filter((c) => c.id !== 'consent_1');
263+
fireEvent.click(within(assistantRow('Cursor')).getByRole('button', { name: '«connectAgent.access.revoke»' }));
264+
const dialog = await screen.findByRole('alertdialog');
265+
fireEvent.click(within(dialog).getByRole('button', { name: '«connectAgent.access.revoke»' }));
266+
267+
expect(await screen.findByText(/No authorized assistant you may withdraw/)).toBeInTheDocument();
268+
await waitFor(() => expect(listMock).toHaveBeenCalledTimes(2));
269+
await waitFor(() => expect(screen.queryByText('Cursor')).toBeNull());
270+
});
271+
});
272+
192273
describe('§2 API keys', () => {
193274
it("reads only the signed-in person's own keys, and never the secret", async () => {
194275
await renderSettled();
@@ -275,3 +356,64 @@ describe('§4 empty, failed and signed-out states', () => {
275356
expect(findMock).not.toHaveBeenCalled();
276357
});
277358
});
359+
360+
describe('§5 the administrator widget on a person\'s record page', () => {
361+
const renderOn = (objectName: string, recordId: string | null) =>
362+
render(
363+
<RecordContextProvider objectName={objectName} recordId={recordId}>
364+
<ManagedPersonAssistants />
365+
</RecordContextProvider>,
366+
);
367+
368+
it('is registered as mcp:authorized-assistants', () => {
369+
expect(ComponentRegistry.get('mcp:authorized-assistants')).toBeDefined();
370+
});
371+
372+
it("lists the person's grants through listForUser and revokes through withdrawForUser", async () => {
373+
renderOn('sys_user', 'user_mia');
374+
await screen.findAllByTestId('authorized-assistant');
375+
expect(listForUserMock).toHaveBeenCalledWith('user_mia');
376+
expect(listMock).not.toHaveBeenCalled();
377+
expect(screen.getByText('«connectAgent.access.managedBody»')).toBeInTheDocument();
378+
379+
fireEvent.click(within(assistantRow('Cursor')).getByRole('button', { name: '«connectAgent.access.revoke»' }));
380+
const dialog = await screen.findByRole('alertdialog');
381+
expect(within(dialog).getByText('«connectAgent.access.withdrawTitle|Cursor»')).toBeInTheDocument();
382+
fireEvent.click(within(dialog).getByRole('button', { name: '«connectAgent.access.revoke»' }));
383+
384+
await waitFor(() => expect(withdrawForUserMock).toHaveBeenCalledWith('user_mia', 'consent_1'));
385+
await waitFor(() => expect(listForUserMock).toHaveBeenCalledTimes(2));
386+
await waitFor(() => expect(screen.queryByText('Cursor')).toBeNull());
387+
expect(withdrawMock).not.toHaveBeenCalled();
388+
});
389+
390+
it('speaks of this person when the list is empty or truncated', async () => {
391+
listForUserMock.mockResolvedValueOnce({ clients: [], truncated: false });
392+
const first = renderOn('sys_user', 'user_mia');
393+
expect(await screen.findByText('«connectAgent.access.managedEmpty»')).toBeInTheDocument();
394+
expect(screen.queryByText('«connectAgent.access.assistantsEmpty»')).toBeNull();
395+
first.unmount();
396+
listForUserMock.mockResolvedValueOnce({ clients: CLIENTS, truncated: true });
397+
renderOn('sys_user', 'user_mia');
398+
expect(await screen.findByText('«connectAgent.access.managedTruncated»')).toBeInTheDocument();
399+
});
400+
401+
it('names a refused read (not a platform administrator) instead of an empty list', async () => {
402+
listForUserMock.mockRejectedValueOnce(new Error('Admin role required'));
403+
renderOn('sys_user', 'user_mia');
404+
expect(await screen.findByText('«connectAgent.access.loadFailed|Admin role required»')).toBeInTheDocument();
405+
expect(screen.queryByText('«connectAgent.access.managedEmpty»')).toBeNull();
406+
});
407+
408+
it("renders nothing and reads nothing off a sys_user record", () => {
409+
const other = renderOn('crm_account', 'acc_1');
410+
expect(other.container).toBeEmptyDOMElement();
411+
other.unmount();
412+
const unbound = render(<ManagedPersonAssistants />);
413+
expect(unbound.container).toBeEmptyDOMElement();
414+
unbound.unmount();
415+
const noId = renderOn('sys_user', null);
416+
expect(noId.container).toBeEmptyDOMElement();
417+
expect(listForUserMock).not.toHaveBeenCalled();
418+
});
419+
});

0 commit comments

Comments
 (0)