Skip to content

Commit 8fed00f

Browse files
fix(platform-objects): Create User picks its permission set from a list, and a refused grant says in one line what to pick (#30701)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DQWVv1Nxj3V5PkJPEMmeSk4)_ domain:server#3 · os-elon-musk · session_016WV4cwFtiPisvhAkegNCLQ Fixes #30117 Clause-②: no (no new export, error code, accept set or schema key: a platform-objects param uses the existing `ActionParamSchema.widget`; the refusal keeps `400 VALIDATION_FAILED` / `reference_not_found`, only its sentence changes) Metadata-protocol: none ## 维护者速读 - 改了什么:「新建用户」的「权限集」从只认机器名的空文本框,改成按标签列出权限集的可搜索下拉(`widget: 'permission-ref'`,就是授权表本身用的选择器);Studio 的动作预览也画成下拉,和真实对话框一致。 - 拒绝提示:原来是一大段开发者说明;现在是一句业务话。输入的是某个权限集的标签时,直接说出它的名称,例如 "'Repair Technician' is the label of the permission set named 'asset_repair_technician': choose it from the list, or enter 'asset_repair_technician'.";同一句话覆盖所有授权路径(Setup 的授权表单与新建用户)。 - 不变的:依旧只接受名称,不接受标签;拒绝依旧是原子的,不会留下用户;状态码与错误码不变。 - 边界:只提示调用者能授予的集合;代理上限权限集(MCP agent)从不提示;非租户级管理员先被委托管理闸门拒绝,听不到任何集合名。 - 先看:`grant-permission-set-name.ts` 的 `grantSetNotInCatalogMessage` / `setsLabelled`,`sys-user.object.ts` 的 `permissionSet` 参数,`ActionPreview.tsx` 的 `runtimeWidgetFor`。 - 需要你做的:无,席位在 CI 绿后按落地授权落地。 ## What changes - **`packages/platform-objects/src/identity/sys-user.object.ts`.** `create_user`'s inline `permissionSet` param adds `widget: 'permission-ref'` and keeps `type: 'text'`: the action dialog (since #30260) draws the grant column's own picker, a searchable list of the permission sets each shown by its label, submitting the chosen set's name. The stale comment "its picker is a widget hint params do not inherit" is retired. The param stays inline, so the dialog never needs plugin-security metadata to open. - **`ui/packages/app-shell/src/views/metadata-admin/previews/ActionPreview.tsx`.** `runtimeWidgetFor` now asks `paramToField` itself (with the authored `widget`) which widget the dialog draws, instead of `resolveParamWidgetType(type)`, so the preview's answer is `authoredWidgetKey(param) ?? resolveParamWidgetType(type)`, the dialog's expression, by construction (note 6662463937 line 2). A `permission-ref` answer is mocked as a disabled picker ("Select LABEL"); an unregistered widget name degrades to the `type` control, as in the dialog. `paramToField.ts` is not edited. - **`packages/plugins/plugin-security/src/grant-permission-set-name.ts`.** The shared refusal sentence (`grantSetNotInCatalogMessage`) is one line: - the refused value is one set's label (trimmed, any case): `'Repair Technician' is the label of the permission set named 'asset_repair_technician': choose it from the list, or enter 'asset_repair_technician'.` - a label several sets carry: they are listed, none is picked; - otherwise: `There is no permission set named 'xyz': choose one from the list.` The catalog is listed only on a refusal (`setsLabelled`); agent ceiling sets (`MCP_AGENT_PERMISSION_SETS`) are never suggested, the same exclusion the picker makes; a listing that throws leaves the plain sentence and is reported at `warn`. A label is still never accepted as a name. - **`packages/plugins/plugin-auth/src/admin-user-endpoints.ts`.** `grantRefusal` keeps "The permission set was not assigned, so no user was created" and hands the reason on as its own sentence (`. ` instead of `: `), so the composed answer reads as two sentences. Status, code, `fields` and the rollback are unchanged. - **Changesets**, one per package moved, all `patch`, both declaration lines: `@objectstack/platform-objects`, `@objectstack/plugin-security`, `@objectstack/plugin-auth`, `@object-ui/app-shell`. ## Why ### Before (measured at `origin/main` `b77c160a`) | | `main` | this PR | |:---|:---|:---| | `create_user.params.permissionSet` | `{ type: 'text' }`, no widget | `{ type: 'text', widget: 'permission-ref' }` | | dialog control | text box (`ActionParamDialog.test.tsx` CONTROL cell, #30260) | permission-set picker (same file, picker cell) | | Studio preview control | text box (`runtimeWidgetFor` → `resolveParamWidgetType('text')`) | disabled picker, `data-testid="action-preview-permission-ref"` | | refusal for `'Repair Technician'` (Create User) | `The permission set was not assigned, so no user was created: Permission Set: no permission set is named 'Repair Technician'. sys_user_permission_set.permission_set takes the machine name of a permission set in the security catalog (a package's set, a built-in, or one saved through the metadata door), never a record id: write the name of an existing permission set, or declare the set first.` | `The permission set was not assigned, so no user was created. 'Repair Technician' is the label of the permission set named 'asset_repair_technician': choose it from the list, or enter 'asset_repair_technician'.` | | user created on refusal | no | no | ### Who the picker lists `permission-ref` lists `GET /api/v1/meta/permission` minus the agent ceiling sets; it is not filtered per caller. Create User is visible only to a platform administrator (`current_user.isPlatformAdmin`), a tenant-level administrator whom the ADR-0090 D12 gate admits for every set except the agent ceilings, which the picker leaves out. So for this action's audience the listed sets are the grantable sets. The picker does not narrow per delegate on other surfaces; that is the picker's existing behaviour and not changed here. ### The suggestion stays inside the caller's grant reach The name check runs only after the D12 gate admitted the write. An organization administrator or a delegate naming a value the catalog does not hold is refused by the gate itself (`delegated-admin-gate.test.ts`, "not in the security catalog"), and a caller who administers nothing is refused 403 too, so neither hears a set name. Past the gate stand only tenant-level administrators. Pinned below. ## Verification Tests added or changed (all green locally): - `plugin-security` `grant-permission-set-name.test.ts`, new describe "the refusal says, in one line, what to pick instead" (7 cells, real `ObjectQL` + SQL driver + `SecurityPlugin`): plain sentence with no developer vocabulary; label → name; case/space-insensitive match; shared label lists both; agent ceiling never suggested; caller refused by the D12 gate hears no set name (403, nothing stored); unlistable catalog still refuses with the plain sentence and warns. Every cell asserts nothing is stored. File: 23 passed. - `plugin-auth` `admin-user-endpoints.test.ts`: the refusal's composed message, `fields` and rollback; the param pin adds `widget: 'permission-ref'`. 99 passed. - `platform-objects` `sys-user-create-user-email-required.test.ts`, new top-level describe pinning the param on the SOURCE (plugin-auth's pin reads the built dist, see ablation B2). 6 passed. - `ui` `ActionDesigner.paramVocabulary.test.tsx`, new top-level describe (4 cells): the dialog's adapter answers `permission-ref`; the preview draws the picker; CONTROL without widget is a text box; an unregistered widget degrades to the text box. 23 passed. - `qa/dogfood` `create-user-permission-set.dogfood.test.ts` (real showcase boot, real route): G2 pins the composed message; new G4 sends the label `Showcase Contributor` and gets 400 naming `showcase_contributor`, zero users. 4 passed. Ablations (old behaviour put back, red seen, restored): - A1 old developer sentence: 6 of the new plugin-security cells red (`Received: "Permission Set: no permission set is named 'qa_nowhere'. sys_user_permission_set.permission_set takes the machine name …"`). - A2 no label lookup: the 3 label cells and the unlistable-catalog warn cell red (`Received: "There is no permission set named 'QA Alpha': choose one from the list."`). - A3 agent ceiling not excluded: the agent cell red (`Received: "'QA Agent Reader' is the label of the permission set named 'mcp_agent_data_read': …"`). - A4 reach cell run with a tenant-admin caller: red (the suggestion appears), so the cell measures the gate's ordering. - B1 old `: ` joiner: plugin-auth refusal cell red. - B2 widget removed from the param: plugin-auth stays green (it reads `@objectstack/platform-objects` dist), which is why the source pin C1 exists; C1 red (`- "widget": "permission-ref"`). - D1 preview ignores `widget`: the preview picker cell red (`Unable to find an element by: [data-testid="action-preview-permission-ref"]`). Gates (head `b5c69de7`): `node scripts/pm/dispatch-gates.mjs --ran` reconciles 71 derived families: 70 run, all exit 0; 1 NOT MEASURED, `node scripts/check-plugin-teardown-shape.mjs --self-test` exit 3 (its positive control is pinned to commit `621a4876`, unreachable in this shallow clone; checker-health only). Also exit 0: `pnpm lint`; `typecheck` and `test` for `@objectstack/platform-objects`, `@objectstack/plugin-security`, `@objectstack/plugin-auth`. Record: `gates-ran-b5c69de7.txt` in the seat's project folder. Skills-docs: none owed by this diff. `git grep -n "create_user\|permissionSet" -- skills` has no hit; `content/docs/**` has no copy of the refusal sentence. `content/docs/permissions/authentication.mdx` ("Create a User Directly") documents `create-user` without the optional `permissionSet` at all, a gap that predates this PR; follow-up candidate. ## Deviations - File surface: `packages/qa/dogfood/test/create-user-permission-set.dogfood.test.ts` (test-only, outside the order's list), accepted by the seat for the end-to-end label case. - The refusal names a set's name when the refused value is a set's label (a catalog list read on the refusal path only), beyond rewording; the seat asked that the suggestion stay inside the caller's grant reach, pinned above. - `ActionPreview` mocks `permission-ref` as a picker, one key past the eight `PARAM_TYPE_OPTS` the preview's mock vocabulary covered, because a text box there would still contradict the dialog. - Full `pnpm test` across the monorepo was not run; the four moved packages' suites, the ui previews/designer suites and the dogfood file were. ## Acceptance notes - The result dialog's `Permission Set` row still shows the granted set's name, not its label (`resultDialog.fields` path `permissionSet`); not in the card's ask. - A translated label (for example a zh-CN label) is not matched by the suggestion: the catalog's `label` is the source string. - `ui/packages/app-shell/src/views/metadata-admin/AssignedUsersSection.test.tsx` mocks a server message with the old wording as its fixture; it pins that the form shows the server's words, whatever they are, so it is left as is. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (not touched) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [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. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. --- _Generated by [Claude Code](https://claude.ai/code/session_016WV4cwFtiPisvhAkegNCLQ)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 05a30e6 commit 8fed00f

13 files changed

Lines changed: 354 additions & 27 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(app-shell): Studio's action preview draws a param's authored `widget` the way the action dialog draws it (#30117)
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
An action param may name a widget (`widget: 'permission-ref'` on a `text` param is the permission-set picker). The action dialog drew that widget, while Studio's action preview read only the param's `type` and drew a text box. The preview now asks the dialog's own adapter which widget it draws, so a `permission-ref` param previews as a picker, and an unregistered widget name previews as the `type` control, the same fallback the dialog takes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/platform-objects': patch
3+
---
4+
5+
fix(platform-objects): Create User's permission set is picked from a list of the permission sets, by label, instead of typed as a machine name (#30117)
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The optional Permission Set on Setup's Create User dialog was an empty text box that accepted only a set's machine name, while everything else in Setup shows sets by their labels. Typing the label the administrator could see was refused. The `create_user` action's `permissionSet` param now declares `widget: 'permission-ref'`, so the dialog draws the permission-set picker the grant column itself uses: a searchable list of the permission sets, each shown by its label, that submits the chosen set's name. The value is still a set's name, and the endpoint and the grant are unchanged.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/plugin-auth': patch
3+
---
4+
5+
fix(plugin-auth): Create User's refusal of its permission set reads as two sentences: no user was created, then the grant's own reason (#30117)
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
When the permission set named on `POST /api/v1/auth/admin/create-user` is refused, the answer still says first that no user was created, and now follows with the grant's reason as its own sentence, for example: `The permission set was not assigned, so no user was created. There is no permission set named 'xyz': choose one from the list.` Status, code, `fields` and the rollback (no user is created) are unchanged.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/plugin-security': patch
3+
---
4+
5+
fix(plugin-security): a grant naming no permission set is refused in one line an administrator can act on, and a set's label typed in place of its name is answered with that set's name (#30117)
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A `sys_user_permission_set` write naming no permission set (Setup's grant form, Create User's optional permission set, any non-system grant) used to answer with a paragraph about the column's contract, the security catalog and record ids. It now answers with one line:
11+
12+
- a value that is a set's label (trimmed, any case): `'Repair Technician' is the label of the permission set named 'asset_repair_technician': choose it from the list, or enter 'asset_repair_technician'.`
13+
- a label more than one set carries: the sets are listed, and none is picked;
14+
- anything else: `There is no permission set named 'xyz': choose one from the list.`
15+
16+
The refusal itself is unchanged: `400 VALIDATION_FAILED`, one `reference_not_found` entry at `permission_set`, nothing stored. A label is still never accepted as a name. The catalog is listed only on a refusal, agent ceiling sets are never suggested, and a listing that fails leaves the plain sentence and is reported at `warn`.

‎packages/platform-objects/src/identity/sys-user-create-user-email-required.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,24 @@ describe('#28280 — Create User marks Email required exactly when the endpoint
8080
expect(first?.visible?.source).toBe(featureGatePredicate('phoneNumber'));
8181
});
8282
});
83+
84+
describe('#30117 — Create User picks its permission set from the catalog, never types it', () => {
85+
// Setup shows permission sets by label; the grant stores a set's name
86+
// (ADR-0131 D4). A bare `text` param drew an empty box that took only the
87+
// name, so typing the label an administrator can see was refused. The param
88+
// names the grant column's own picker instead (`ActionParamSchema.widget`),
89+
// which the action dialog draws as a searchable list of the sets by label,
90+
// submitting the chosen name: its VALUE stays `text`. Pinned here, on the
91+
// source, because plugin-auth's route pin reads this package's built dist.
92+
const permissionSet = (params as Array<Param & { type?: string; widget?: string }>).find(
93+
(p) => p.name === 'permissionSet',
94+
);
95+
96+
it('the param names the permission-set picker and keeps a text value', () => {
97+
expect(permissionSet).toMatchObject({ type: 'text', widget: 'permission-ref', required: false });
98+
});
99+
100+
it('it stays inline, so the dialog opens without plugin-security metadata loaded', () => {
101+
expect(permissionSet).not.toHaveProperty('field');
102+
});
103+
});

‎packages/platform-objects/src/identity/sys-user.object.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,20 @@ export const SysUser = ObjectSchema.create({
355355
// field-backed: the grant object lives in plugin-security, whose
356356
// metadata the console need not have loaded on this list, and an
357357
// unresolvable field-backed param makes the dialog refuse the whole
358-
// action. The grant column is a text field anyway (its picker is a
359-
// widget hint params do not inherit), so nothing is lost.
358+
// action. The value is a permission set's NAME, a `text` value like
359+
// the grant column it lands in, and `widget: 'permission-ref'` draws
360+
// the grant column's own picker (ADR-0131 D4): a searchable list of
361+
// the security catalog's sets, each shown by its label, that submits
362+
// the chosen set's name. So the administrator picks what Setup shows
363+
// and never types a machine name.
360364
// The route writes the grant under the administrator's OWN context in
361365
// the same transaction as the account: the delegated-administration
362366
// gate and the catalog name check judge it as they judge Setup's
363367
// grant form, and a refusal creates no user.
364368
{
365369
name: 'permissionSet',
366370
type: 'text',
371+
widget: 'permission-ref',
367372
label: 'Permission Set',
368373
required: false,
369374
helpText: 'Optional. Grants this permission set to the new user, so they can open their apps on first sign-in.',

‎packages/plugins/plugin-auth/src/admin-user-endpoints.test.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,9 +1336,13 @@ describe('create-user: an optional permission set, granted under the caller\'s o
13361336
it('a name the catalog does not hold: 400 VALIDATION_FAILED with its fields, and the account rolls back', async () => {
13371337
const g = makeGrantSeam();
13381338
const m = makeDeps({ createGrant: g.seam });
1339-
const fields = [{ field: 'permission_set', code: 'reference_not_found', message: 'no such set' }];
1339+
// The grant's name check speaks for itself (plugin-security's
1340+
// `grant-permission-set-name.ts`, pinned there); this route only says, first,
1341+
// that no user was created, and then hands the reason on unchanged.
1342+
const reason = "There is no permission set named 'nope': choose one from the list.";
1343+
const fields = [{ field: 'permission_set', code: 'reference_not_found', message: reason }];
13401344
m.engineCreate.mockImplementation((async (object: string) => {
1341-
if (object === 'sys_user_permission_set') throw validationFailure('no permission set is named nope', fields);
1345+
if (object === 'sys_user_permission_set') throw validationFailure(reason, fields);
13421346
return {};
13431347
}) as any);
13441348
const res = await runAdminCreateUser(
@@ -1348,8 +1352,10 @@ describe('create-user: an optional permission set, granted under the caller\'s o
13481352
);
13491353
expect(res.status).toBe(400);
13501354
expect(res.body.error?.code).toBe('VALIDATION_FAILED');
1355+
expect(res.body.error?.message).toBe(`The permission set was not assigned, so no user was created. ${reason}`);
13511356
expect(res.body.error?.fields).toEqual(fields);
13521357
expect(g.outcomes).toEqual(['rolled back']);
1358+
expect(res.body.data).toBeUndefined();
13531359
});
13541360

13551361
it('a host that wires no seam refuses 501 before any account exists', async () => {
@@ -1392,7 +1398,10 @@ describe('create-user: an optional permission set, granted under the caller\'s o
13921398
it('the Create User dialog offers it as an optional INLINE param, never field-backed on another package\'s object', () => {
13931399
const action = (SysUser.actions ?? []).find((a) => a.name === 'create_user');
13941400
const param = (action?.params ?? []).find((p) => p.name === 'permissionSet');
1395-
expect(param).toMatchObject({ type: 'text', required: false });
1401+
// Picked, never typed: `widget: 'permission-ref'` draws the grant column's
1402+
// own picker (ADR-0131 D4), a searchable list of the catalog's sets by
1403+
// label that submits the chosen set's NAME, a `text` value as before.
1404+
expect(param).toMatchObject({ type: 'text', widget: 'permission-ref', required: false });
13961405
// A field-backed param on plugin-security's object is refused by the
13971406
// console dialog whenever that object's metadata is not loaded.
13981407
expect(param).not.toHaveProperty('field');

‎packages/plugins/plugin-auth/src/admin-user-endpoints.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,11 @@ function multiOrgCreationJoinsCurrentOrganization(deps: AdminUserEndpointDeps):
10361036
* `VALIDATION_FAILED` with its `fields` for a name the catalog does not hold),
10371037
* read as the data doors read a thrown error, and a sentence saying the user
10381038
* was not created either.
1039+
*
1040+
* The reason follows as its own sentence, in the refusal's own words: the
1041+
* grant's name check says it once for every grant path, Setup's grant form
1042+
* included, and names the set to pick when the value typed is a set's label
1043+
* (`grant-permission-set-name.ts` in plugin-security). Nothing here restates it.
10391044
*/
10401045
function grantRefusal(error: unknown): EndpointResult {
10411046
const thrown = resolveThrownHttpError(error, 500);
@@ -1046,7 +1051,7 @@ function grantRefusal(error: unknown): EndpointResult {
10461051
success: false,
10471052
error: {
10481053
code: thrown.code,
1049-
message: `The permission set was not assigned, so no user was created: ${thrown.message}`,
1054+
message: `The permission set was not assigned, so no user was created. ${thrown.message}`,
10501055
...(validation ? { fields: validation.fields } : {}),
10511056
},
10521057
},

‎packages/plugins/plugin-security/src/grant-permission-set-name.test.ts‎

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ const QA_ADMIN = {
6565

6666
const QA_ALPHA = { name: 'qa_alpha', label: 'QA Alpha', objects: {} } as unknown as PermissionSet;
6767
const QA_BETA = { name: 'qa_beta', label: 'QA Beta', objects: {} } as unknown as PermissionSet;
68-
const CATALOG = [MEMBER_DEFAULT, QA_ADMIN, QA_ALPHA, QA_BETA];
68+
/** Two sets sharing one label: a label is display text, never unique. */
69+
const QA_TWIN_A = { name: 'qa_twin_a', label: 'QA Twin', objects: {} } as unknown as PermissionSet;
70+
const QA_TWIN_B = { name: 'qa_twin_b', label: 'QA Twin', objects: {} } as unknown as PermissionSet;
71+
/** An agent ceiling set (ADR-0090 D10): no person's grant may name it, so it is never suggested. */
72+
const AGENT_CEILING = { name: 'mcp_agent_data_read', label: 'QA Agent Reader', objects: {} } as unknown as PermissionSet;
73+
const CATALOG = [MEMBER_DEFAULT, QA_ADMIN, QA_ALPHA, QA_BETA, QA_TWIN_A, QA_TWIN_B, AGENT_CEILING];
6974

7075
const SYS = { isSystem: true } as const;
7176
const ADMIN = { userId: 'u_admin', positions: [], permissions: ['qa_admin'] };
@@ -259,6 +264,94 @@ describe('the data door (a non-system writer)', () => {
259264
});
260265
});
261266

267+
// ---------------------------------------------------------------------------
268+
// The refusal's sentence — one line an administrator can act on
269+
// ---------------------------------------------------------------------------
270+
271+
describe('the refusal says, in one line, what to pick instead', () => {
272+
// Every grant path shares this sentence: Setup's grant form writes through
273+
// this door, and Create User hands it on after its own "no user was created"
274+
// (plugin-auth `admin-user-endpoints.ts`). The literals are the pin: an
275+
// assertion against `grantSetNotInCatalogMessage` alone would follow any
276+
// wording back to the developer message.
277+
async function refusedMessage(value: string): Promise<string> {
278+
const h = await boot();
279+
const err = await refusalOf(() => h.engine.insert(
280+
'sys_user_permission_set', { user_id: 'u_msg', permission_set: value }, { context: ADMIN } as any,
281+
));
282+
expectNotInCatalogRefusal(err, value);
283+
expect(await grantsOf(h, 'u_msg'), 'a refused grant stores nothing').toHaveLength(0);
284+
const { message } = envelopeOf(err).fields[0];
285+
expect((err as Error).message, 'the top-level message is the same sentence').toBe(message);
286+
return message;
287+
}
288+
289+
it('NEGATIVE — a name no set has: one line, no developer vocabulary', async () => {
290+
const message = await refusedMessage('qa_nowhere');
291+
expect(message).toBe("There is no permission set named 'qa_nowhere': choose one from the list.");
292+
expect(message).not.toMatch(/sys_user_permission_set|machine name|record id|metadata door|security catalog/);
293+
expect(message).not.toContain('\n');
294+
});
295+
296+
it('NEGATIVE — a set\'s LABEL typed where its name belongs: the sentence names the set to pick', async () => {
297+
expect(await refusedMessage('QA Alpha')).toBe(
298+
"'QA Alpha' is the label of the permission set named 'qa_alpha': choose it from the list, or enter 'qa_alpha'.",
299+
);
300+
});
301+
302+
it('the label is matched ignoring case and surrounding spaces', async () => {
303+
expect(await refusedMessage(' qa beta ')).toBe(
304+
"' qa beta ' is the label of the permission set named 'qa_beta': choose it from the list, or enter 'qa_beta'.",
305+
);
306+
});
307+
308+
it('a label two sets share names both, and picks neither', async () => {
309+
expect(await refusedMessage('QA Twin')).toBe(
310+
"'QA Twin' is the label of more than one permission set ('qa_twin_a', 'qa_twin_b'): choose the one you mean from the list.",
311+
);
312+
});
313+
314+
it('an agent ceiling set is never suggested: no person\'s grant may name one', async () => {
315+
expect(await refusedMessage('QA Agent Reader')).toBe(
316+
"There is no permission set named 'QA Agent Reader': choose one from the list.",
317+
);
318+
});
319+
320+
it('NEGATIVE — names only what the caller could grant: a caller the delegated-administration gate refuses hears no set name', async () => {
321+
// The suggestion is made by this hook, which runs only after the ADR-0090
322+
// D12 gate admitted the write. Past the gate stand only tenant-level
323+
// administrators, who may grant every set the picker lists (the agent
324+
// ceilings excepted, never suggested above); an organization administrator
325+
// or a delegate naming a value the catalog does not hold is refused by the
326+
// gate itself (`delegated-admin-gate.test.ts`, "not in the security
327+
// catalog"). Measured here with a caller who administers nothing.
328+
const h = await boot();
329+
const MEMBER = { userId: 'u_member', positions: [], permissions: ['member_default'] };
330+
const err = await refusalOf(() => h.engine.insert(
331+
'sys_user_permission_set', { user_id: 'u_reach', permission_set: 'QA Alpha' }, { context: MEMBER } as any,
332+
));
333+
expect(envelopeOf(err)).toMatchObject({ status: 403, code: 'PERMISSION_DENIED' });
334+
expect((err as Error).message).not.toContain('qa_alpha');
335+
expect(await grantsOf(h, 'u_reach')).toHaveLength(0);
336+
});
337+
338+
it('a catalog that cannot be listed still refuses, with the plain sentence, and the operator is told', async () => {
339+
const h = await boot();
340+
const metadata = h.ctx.getService('metadata');
341+
vi.spyOn(metadata, 'list').mockRejectedValue(new Error('metadata store down'));
342+
const err = await refusalOf(() => h.engine.insert(
343+
'sys_user_permission_set', { user_id: 'u_list', permission_set: 'QA Alpha' }, { context: ADMIN } as any,
344+
));
345+
expectNotInCatalogRefusal(err, 'QA Alpha');
346+
expect(envelopeOf(err).fields[0].message).toBe("There is no permission set named 'QA Alpha': choose one from the list.");
347+
expect(await grantsOf(h, 'u_list')).toHaveLength(0);
348+
expect(h.ctx.logger.warn).toHaveBeenCalledWith(
349+
expect.stringContaining('could not be listed'),
350+
expect.objectContaining({ object: 'sys_user_permission_set' }),
351+
);
352+
});
353+
});
354+
262355
// ---------------------------------------------------------------------------
263356
// System writers
264357
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)