Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/30117-action-preview-param-widget.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@object-ui/app-shell': patch
---

fix(app-shell): Studio's action preview draws a param's authored `widget` the way the action dialog draws it (#30117)

Clause-②: no
Metadata-protocol: none

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.
10 changes: 10 additions & 0 deletions .changeset/30117-create-user-permission-set-picker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@objectstack/platform-objects': patch
---

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)

Clause-②: no
Metadata-protocol: none

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.
10 changes: 10 additions & 0 deletions .changeset/30117-create-user-refusal-sentence.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@objectstack/plugin-auth': patch
---

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)

Clause-②: no
Metadata-protocol: none

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.
16 changes: 16 additions & 0 deletions .changeset/30117-grant-refusal-business-wording.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@objectstack/plugin-security': patch
---

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)

Clause-②: no
Metadata-protocol: none

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:

- 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'.`
- a label more than one set carries: the sets are listed, and none is picked;
- anything else: `There is no permission set named 'xyz': choose one from the list.`

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`.
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,24 @@ describe('#28280 — Create User marks Email required exactly when the endpoint
expect(first?.visible?.source).toBe(featureGatePredicate('phoneNumber'));
});
});

describe('#30117 — Create User picks its permission set from the catalog, never types it', () => {
// Setup shows permission sets by label; the grant stores a set's name
// (ADR-0131 D4). A bare `text` param drew an empty box that took only the
// name, so typing the label an administrator can see was refused. The param
// names the grant column's own picker instead (`ActionParamSchema.widget`),
// which the action dialog draws as a searchable list of the sets by label,
// submitting the chosen name: its VALUE stays `text`. Pinned here, on the
// source, because plugin-auth's route pin reads this package's built dist.
const permissionSet = (params as Array<Param & { type?: string; widget?: string }>).find(
(p) => p.name === 'permissionSet',
);

it('the param names the permission-set picker and keeps a text value', () => {
expect(permissionSet).toMatchObject({ type: 'text', widget: 'permission-ref', required: false });
});

it('it stays inline, so the dialog opens without plugin-security metadata loaded', () => {
expect(permissionSet).not.toHaveProperty('field');
});
});
9 changes: 7 additions & 2 deletions packages/platform-objects/src/identity/sys-user.object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,20 @@ export const SysUser = ObjectSchema.create({
// field-backed: the grant object lives in plugin-security, whose
// metadata the console need not have loaded on this list, and an
// unresolvable field-backed param makes the dialog refuse the whole
// action. The grant column is a text field anyway (its picker is a
// widget hint params do not inherit), so nothing is lost.
// action. The value is a permission set's NAME, a `text` value like
// the grant column it lands in, and `widget: 'permission-ref'` draws
// the grant column's own picker (ADR-0131 D4): a searchable list of
// the security catalog's sets, each shown by its label, that submits
// the chosen set's name. So the administrator picks what Setup shows
// and never types a machine name.
// The route writes the grant under the administrator's OWN context in
// the same transaction as the account: the delegated-administration
// gate and the catalog name check judge it as they judge Setup's
// grant form, and a refusal creates no user.
{
name: 'permissionSet',
type: 'text',
widget: 'permission-ref',
label: 'Permission Set',
required: false,
helpText: 'Optional. Grants this permission set to the new user, so they can open their apps on first sign-in.',
Expand Down
15 changes: 12 additions & 3 deletions packages/plugins/plugin-auth/src/admin-user-endpoints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1336,9 +1336,13 @@ describe('create-user: an optional permission set, granted under the caller\'s o
it('a name the catalog does not hold: 400 VALIDATION_FAILED with its fields, and the account rolls back', async () => {
const g = makeGrantSeam();
const m = makeDeps({ createGrant: g.seam });
const fields = [{ field: 'permission_set', code: 'reference_not_found', message: 'no such set' }];
// The grant's name check speaks for itself (plugin-security's
// `grant-permission-set-name.ts`, pinned there); this route only says, first,
// that no user was created, and then hands the reason on unchanged.
const reason = "There is no permission set named 'nope': choose one from the list.";
const fields = [{ field: 'permission_set', code: 'reference_not_found', message: reason }];
m.engineCreate.mockImplementation((async (object: string) => {
if (object === 'sys_user_permission_set') throw validationFailure('no permission set is named nope', fields);
if (object === 'sys_user_permission_set') throw validationFailure(reason, fields);
return {};
}) as any);
const res = await runAdminCreateUser(
Expand All @@ -1348,8 +1352,10 @@ describe('create-user: an optional permission set, granted under the caller\'s o
);
expect(res.status).toBe(400);
expect(res.body.error?.code).toBe('VALIDATION_FAILED');
expect(res.body.error?.message).toBe(`The permission set was not assigned, so no user was created. ${reason}`);
expect(res.body.error?.fields).toEqual(fields);
expect(g.outcomes).toEqual(['rolled back']);
expect(res.body.data).toBeUndefined();
});

it('a host that wires no seam refuses 501 before any account exists', async () => {
Expand Down Expand Up @@ -1392,7 +1398,10 @@ describe('create-user: an optional permission set, granted under the caller\'s o
it('the Create User dialog offers it as an optional INLINE param, never field-backed on another package\'s object', () => {
const action = (SysUser.actions ?? []).find((a) => a.name === 'create_user');
const param = (action?.params ?? []).find((p) => p.name === 'permissionSet');
expect(param).toMatchObject({ type: 'text', required: false });
// Picked, never typed: `widget: 'permission-ref'` draws the grant column's
// own picker (ADR-0131 D4), a searchable list of the catalog's sets by
// label that submits the chosen set's NAME, a `text` value as before.
expect(param).toMatchObject({ type: 'text', widget: 'permission-ref', required: false });
// A field-backed param on plugin-security's object is refused by the
// console dialog whenever that object's metadata is not loaded.
expect(param).not.toHaveProperty('field');
Expand Down
7 changes: 6 additions & 1 deletion packages/plugins/plugin-auth/src/admin-user-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,11 @@ function multiOrgCreationJoinsCurrentOrganization(deps: AdminUserEndpointDeps):
* `VALIDATION_FAILED` with its `fields` for a name the catalog does not hold),
* read as the data doors read a thrown error, and a sentence saying the user
* was not created either.
*
* The reason follows as its own sentence, in the refusal's own words: the
* grant's name check says it once for every grant path, Setup's grant form
* included, and names the set to pick when the value typed is a set's label
* (`grant-permission-set-name.ts` in plugin-security). Nothing here restates it.
*/
function grantRefusal(error: unknown): EndpointResult {
const thrown = resolveThrownHttpError(error, 500);
Expand All @@ -1046,7 +1051,7 @@ function grantRefusal(error: unknown): EndpointResult {
success: false,
error: {
code: thrown.code,
message: `The permission set was not assigned, so no user was created: ${thrown.message}`,
message: `The permission set was not assigned, so no user was created. ${thrown.message}`,
...(validation ? { fields: validation.fields } : {}),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ const QA_ADMIN = {

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

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

// ---------------------------------------------------------------------------
// The refusal's sentence — one line an administrator can act on
// ---------------------------------------------------------------------------

describe('the refusal says, in one line, what to pick instead', () => {
// Every grant path shares this sentence: Setup's grant form writes through
// this door, and Create User hands it on after its own "no user was created"
// (plugin-auth `admin-user-endpoints.ts`). The literals are the pin: an
// assertion against `grantSetNotInCatalogMessage` alone would follow any
// wording back to the developer message.
async function refusedMessage(value: string): Promise<string> {
const h = await boot();
const err = await refusalOf(() => h.engine.insert(
'sys_user_permission_set', { user_id: 'u_msg', permission_set: value }, { context: ADMIN } as any,
));
expectNotInCatalogRefusal(err, value);
expect(await grantsOf(h, 'u_msg'), 'a refused grant stores nothing').toHaveLength(0);
const { message } = envelopeOf(err).fields[0];
expect((err as Error).message, 'the top-level message is the same sentence').toBe(message);
return message;
}

it('NEGATIVE — a name no set has: one line, no developer vocabulary', async () => {
const message = await refusedMessage('qa_nowhere');
expect(message).toBe("There is no permission set named 'qa_nowhere': choose one from the list.");
expect(message).not.toMatch(/sys_user_permission_set|machine name|record id|metadata door|security catalog/);
expect(message).not.toContain('\n');
});

it('NEGATIVE — a set\'s LABEL typed where its name belongs: the sentence names the set to pick', async () => {
expect(await refusedMessage('QA Alpha')).toBe(
"'QA Alpha' is the label of the permission set named 'qa_alpha': choose it from the list, or enter 'qa_alpha'.",
);
});

it('the label is matched ignoring case and surrounding spaces', async () => {
expect(await refusedMessage(' qa beta ')).toBe(
"' qa beta ' is the label of the permission set named 'qa_beta': choose it from the list, or enter 'qa_beta'.",
);
});

it('a label two sets share names both, and picks neither', async () => {
expect(await refusedMessage('QA Twin')).toBe(
"'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.",
);
});

it('an agent ceiling set is never suggested: no person\'s grant may name one', async () => {
expect(await refusedMessage('QA Agent Reader')).toBe(
"There is no permission set named 'QA Agent Reader': choose one from the list.",
);
});

it('NEGATIVE — names only what the caller could grant: a caller the delegated-administration gate refuses hears no set name', async () => {
// The suggestion is made by this hook, which runs only after the ADR-0090
// D12 gate admitted the write. Past the gate stand only tenant-level
// administrators, who may grant every set the picker lists (the agent
// ceilings excepted, never suggested above); 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"). Measured here with a caller who administers nothing.
const h = await boot();
const MEMBER = { userId: 'u_member', positions: [], permissions: ['member_default'] };
const err = await refusalOf(() => h.engine.insert(
'sys_user_permission_set', { user_id: 'u_reach', permission_set: 'QA Alpha' }, { context: MEMBER } as any,
));
expect(envelopeOf(err)).toMatchObject({ status: 403, code: 'PERMISSION_DENIED' });
expect((err as Error).message).not.toContain('qa_alpha');
expect(await grantsOf(h, 'u_reach')).toHaveLength(0);
});

it('a catalog that cannot be listed still refuses, with the plain sentence, and the operator is told', async () => {
const h = await boot();
const metadata = h.ctx.getService('metadata');
vi.spyOn(metadata, 'list').mockRejectedValue(new Error('metadata store down'));
const err = await refusalOf(() => h.engine.insert(
'sys_user_permission_set', { user_id: 'u_list', permission_set: 'QA Alpha' }, { context: ADMIN } as any,
));
expectNotInCatalogRefusal(err, 'QA Alpha');
expect(envelopeOf(err).fields[0].message).toBe("There is no permission set named 'QA Alpha': choose one from the list.");
expect(await grantsOf(h, 'u_list')).toHaveLength(0);
expect(h.ctx.logger.warn).toHaveBeenCalledWith(
expect.stringContaining('could not be listed'),
expect.objectContaining({ object: 'sys_user_permission_set' }),
);
});
});

// ---------------------------------------------------------------------------
// System writers
// ---------------------------------------------------------------------------
Expand Down
Loading
Loading