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

Commit 5698ec7

Browse files
fix(app-shell): show a position's label in a permission set's Assigned users (objectui#13477) (#13493)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D2bmCsjnmZkrozUjaCZ8Xgr)_ - [x] Adds no product-specific widget, dialog, hook or string (see AGENTS.md › Product-neutral renderer) Fixes #13477 Clause-②: no Metadata-protocol: none ## What changed `AssignedUsersSection` (a permission set's Assigned users list) drew each "via position" chip from the holder's `sys_user_position.position`, the position's machine name, through `c.viaPosition(v.position)`. The same `load` already lists the registry's position definitions through `ensureType('position')` to find the positions that distribute the set, and that list carries each definition's `label` as `/meta/position` serves it in the caller's language (objectstack#25701). - A module-private `positionLabels(positions)` reads `name` to `label` from that one list (a blank or non-string label is skipped). - Each position entry of a row's `via` now carries `label` beside `position`. - The chip text is `c.viaPosition(label ?? name)`, and the chip's `title` is the machine name whenever the text is not the name, the same rule `CitedItemChip` in `AccessExplainPanel` applies. With no label the chip reads by its name and has no `title`, as before. - No new read: the label comes from the list the section already fetched. - `.changeset/13477-assigned-users-position-label.md`: `@object-ui/app-shell` patch. Files: `packages/app-shell/src/views/metadata-admin/AssignedUsersSection.tsx`, its existing test `AssignedUsersSection.test.tsx` (the fixture's `contributor` definition has the label `Contributor`, so the chip assertion now reads `via position Contributor`), the new pin `AssignedUsersSection.positionLabel-13477.test.tsx`, and the changeset. ## Tests The new pin mounts the real `AssignedUsersSection` inside the real `MetadataProvider`, over a real `ObjectStackAdapter` whose `fetch` is the only stub, so the label reaches the chip through the store's own `GET /api/v1/meta/position`: - `shows the label from /meta/position, with the machine name on title`: chip `via position Sales Manager`, `title="sales_manager"`, and no `via position sales_manager`. - `a definition with no label reads by its name, with no title`: chip `via position field_rep` with no `title`, beside the labelled one. Readings, taken locally on the branch head: - `pnpm exec vitest run packages/app-shell/src/views/metadata-admin/AssignedUsersSection`: Test Files 5 passed (5), Tests 29 passed (29). - Nearby: the same plus `PositionHoldersSection` and `AccessExplainPanel` prefixes: Test Files 14 passed (14), Tests 84 passed (84). - Reverse check (fix committed, then only `AssignedUsersSection.tsx` put back to the base commit): both new tests and the updated chip assertion in `AssignedUsersSection.test.tsx` fail (3 failed, 11 passed across the two files); with the fix restored they pass. - `pnpm --filter @object-ui/app-shell type-check` (both `tsc --noEmit` and `tsc -p tsconfig.test.json`): exit 0. - `pnpm exec eslint` on the three touched source/test files: 0 errors, 15 warnings. Each warning is a rule on a line this branch did not write (`no-explicit-any`, `react-hooks/refs`, `react-hooks/set-state-in-effect`, and `only-export-components` on the existing `positionsDistributing` export). The new helper stays unexported so it adds none. - `node scripts/check-changeset-presence.mjs`: pass, 1 changeset declared for the 1 released package. - `pnpm check:new-line-citations`: 0 new citations. ## Acceptance notes The sweep looked for any other site that draws a raw position or permission-set machine name from a payload other than the `/meta/position` or `/meta/permission` list. The brief allowed a fix in the same diff only where the fix is the same one-line label lookup from a list that component already loads. None of the sites below qualified, so this diff touches none of them. Already labelled, nothing to do: - `PositionHoldersSection` (a position's holders) lists people only. It draws no position or permission-set name. - Approver `type: 'position'` (the `decision_output_defs` entry in `apps/console/src/services/approvalsApi.ts`): the decide dialog's picker is built by `registryOptions` in `decisionOutputParams.ts` from `ensureType('position')`, using `label` and falling back to the name. Approver display goes through `useApproverDirectory`, whose registry leg labels `position:` references from the same store read. - `AccessExplainPanel` Principal card and "Contributed by" chips already label through `CitedItemChip`. Raw names that remain, each needing more than a one-line lookup (none of these components loads the list): - Sharing-rule `sharedWith`: the catalog's "Shared with" list column (the `render` on the `sharedWith` column in `anchors.ts`) and the summary row in `SharingRuleCloneDialog` both print `TYPE: VALUE`, e.g. `position: sales_manager`. Neither loads `/meta/position`, and the recipient type itself is a raw token. - `PositionGrantCells` (the position list's "Permission sets" column) draws `_grantedPermissionSets[].name` from the list's served `listInclude` column. The component loads no `/meta/permission` list. - `PositionPreview` lists the draft definition's `permissionSets` as code-formatted machine names. It loads no permission list. - Suggested bindings (`SuggestedBindingsPanel`, its Studio copy in `StudioDesignSurface`, and `MarketplacePackagePage` toasts) interpolate the suggestion payload's `permission_set_name` into their sentences. None of them loads `/meta/permission`. Locale of the metadata store's reads: `MetadataProvider.ensureType` reads through `adapter.getClient().meta.getItems(type)`. The console's adapter is built in `AdapterProvider` with `createAuthenticatedFetch()`, which sets `Accept-Language` from `document.documentElement.lang` on every API call that does not already carry one. `ConnectedShellInner` keys `MetadataProvider` on the UI language (`key={language}`) and clears the adapter cache on a switch, so `/meta/position` and `/meta/permission` are read again in the new language. Nothing on this branch re-checks that wiring; it was read from the source and the new pin does not assert the header. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01XWGTsmqrtrt1Zqh1ioWqsT --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent d0c9650 commit 5698ec7

4 files changed

Lines changed: 170 additions & 12 deletions

File tree

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+
Clause-②: no
6+
Metadata-protocol: none
7+
8+
A permission set's Assigned users list now names the position a person holds the set through by the position's label, in the viewer's language, instead of its machine name (objectui#13477).
9+
10+
The "via position" chip drew the `position` column of the holder's `sys_user_position` row, the machine name, although the section had already listed the registry's position definitions to find the positions that distribute the set, and that list carries each definition's label as the server localizes it. The chip now reads the label from that list and keeps the name on its tooltip, as the access explainer's position chips do. A position whose definition has no label still reads by its name.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2026 ObjectStack. Licensed under the MIT license.
4+
*
5+
* A holder's "via position" chip names the position by its label
6+
* (objectui#13477).
7+
*
8+
* The chip used to draw `sys_user_position.position` — the position's machine
9+
* name — while the section had already listed the registry's position
10+
* definitions, labels included, to find the positions that distribute the set.
11+
* `/meta/position` serves those labels in the caller's language
12+
* (objectstack#25701). This file holds that the chip reads the label from that
13+
* list with the name on its `title`, as `CitedItemChip` in `AccessExplainPanel`
14+
* does, and that a definition with no label still reads by its name.
15+
*
16+
* Everything between the server and the chip is real: a `MetadataProvider`
17+
* over an `ObjectStackAdapter` whose `fetch` is the only stub, so the label
18+
* reaches the section through the store's own `/meta/position` read.
19+
*/
20+
21+
import * as React from 'react';
22+
import { afterEach, describe, expect, it, vi } from 'vitest';
23+
import { cleanup, render, screen } from '@testing-library/react';
24+
import { AdapterCtx } from '@object-ui/react';
25+
import { ObjectStackAdapter } from '@object-ui/data-objectstack';
26+
import { MetadataProvider } from '../../providers/MetadataProvider';
27+
import { AssignedUsersSection } from './AssignedUsersSection';
28+
29+
vi.mock('@object-ui/fields', async (importOriginal) => ({
30+
...(await importOriginal<typeof import('@object-ui/fields')>()),
31+
RecordPickerDialog: () => null,
32+
}));
33+
34+
const SET = 'crm_sales_user';
35+
36+
/** The registry's position definitions as `/meta/position` serves them. */
37+
const POSITIONS = [
38+
{ name: 'sales_manager', label: 'Sales Manager', permissionSets: [SET] },
39+
// A definition with no label: its chip reads by its name.
40+
{ name: 'field_rep', permissionSets: [SET] },
41+
{ name: 'auditor', label: 'Auditor', permissionSets: ['crm_auditor'] },
42+
];
43+
44+
const ROWS: Record<string, unknown[]> = {
45+
sys_user_permission_set: [],
46+
sys_user_position: [
47+
{ id: 'up_1', user_id: 'u_manager', position: 'sales_manager' },
48+
{ id: 'up_2', user_id: 'u_rep', position: 'field_rep' },
49+
],
50+
sys_user: [
51+
{ id: 'u_manager', name: 'Manager Mia', email: 'mia@example.com' },
52+
{ id: 'u_rep', name: 'Rep Ray', email: 'ray@example.com' },
53+
],
54+
};
55+
56+
const json = (status: number, body: unknown) =>
57+
new Response(JSON.stringify(body), { status, headers: { 'Content-Type': 'application/json' } });
58+
59+
let seq = 0;
60+
61+
function makeAdapter() {
62+
const fetchImpl = vi.fn(async (input: RequestInfo | URL) => {
63+
const url = new URL(String(input));
64+
if (url.pathname.endsWith('/api/v1/discovery')) {
65+
return json(200, { success: true, data: { version: 'v0', routes: {}, capabilities: {} } });
66+
}
67+
if (url.pathname === '/api/v1/meta/position') {
68+
return json(200, { success: true, data: { type: 'position', items: structuredClone(POSITIONS) } });
69+
}
70+
const list = /^\/api\/v1\/meta\/([a-z_]+)$/.exec(url.pathname);
71+
if (list) return json(200, { success: true, data: { type: list[1], items: [] } });
72+
const data = /^\/api\/v1\/data\/([^/?]+)$/.exec(url.pathname);
73+
if (data) {
74+
const records = ROWS[data[1]] ?? [];
75+
return json(200, { object: data[1], records, total: records.length });
76+
}
77+
return json(404, { success: false, error: { message: `no route ${url.pathname}` } });
78+
});
79+
// A fresh origin per adapter: the adapter shares discovery per base URL.
80+
return new ObjectStackAdapter({ baseUrl: `http://position-label-${(seq += 1)}.test`, autoReconnect: false, fetch: fetchImpl });
81+
}
82+
83+
function renderSection() {
84+
const adapter = makeAdapter();
85+
render(
86+
<AdapterCtx.Provider value={adapter as never}>
87+
<MetadataProvider adapter={adapter}>
88+
<AssignedUsersSection permissionSetName={SET} />
89+
</MetadataProvider>
90+
</AdapterCtx.Provider>,
91+
);
92+
}
93+
94+
afterEach(() => {
95+
cleanup();
96+
});
97+
98+
describe("AssignedUsersSection — a position chip reads the position's label (objectui#13477)", () => {
99+
it('shows the label from /meta/position, with the machine name on title', async () => {
100+
renderSection();
101+
102+
const chip = await screen.findByText('via position Sales Manager');
103+
expect(chip).toHaveAttribute('title', 'sales_manager');
104+
expect(screen.queryByText('via position sales_manager')).toBeNull();
105+
});
106+
107+
it('a definition with no label reads by its name, with no title', async () => {
108+
renderSection();
109+
110+
const chip = await screen.findByText('via position field_rep');
111+
expect(chip).not.toHaveAttribute('title');
112+
// The labelled holder beside it still reads by its label.
113+
expect(screen.getByText('via position Sales Manager')).toBeTruthy();
114+
});
115+
});

‎packages/app-shell/src/views/metadata-admin/AssignedUsersSection.test.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ describe('AssignedUsersSection — effective holders (objectui#2382)', () => {
8585
expect(screen.getByText('2')).toBeTruthy();
8686
// Attribution badges.
8787
expect(screen.getAllByText('direct').length).toBeGreaterThan(0);
88-
expect(screen.getAllByText('via position contributor').length).toBeGreaterThan(0);
88+
// The chip reads the position's label from the registry (objectui#13477).
89+
expect(screen.getAllByText('via position Contributor').length).toBeGreaterThan(0);
8990
});
9091

9192
it('surfaces the everyone-anchor binding as a note instead of enumerating members', async () => {

‎packages/app-shell/src/views/metadata-admin/AssignedUsersSection.tsx‎

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,12 @@ interface AssignedRow {
112112
userId: string;
113113
name: string;
114114
email: string;
115-
/** How the user holds the set: a direct grant, or via one or more positions. */
116-
via: Array<{ kind: 'direct' } | { kind: 'position'; position: string }>;
115+
/**
116+
* How the user holds the set: a direct grant, or via one or more positions.
117+
* A position carries its machine name and, where its registry definition
118+
* has one, its label (objectui#13477).
119+
*/
120+
via: Array<{ kind: 'direct' } | { kind: 'position'; position: string; label?: string }>;
117121
}
118122

119123
/**
@@ -235,6 +239,22 @@ export function positionsDistributing(positions: readonly unknown[], setName: st
235239
return out;
236240
}
237241

242+
/**
243+
* The labels of the registry's `position` definitions, by name — the list
244+
* {@link positionsDistributing} reads, which `/meta/position` serves in the
245+
* caller's language (objectui#13477). A definition with no label has no entry,
246+
* so its chip shows the name, as `CitedItemChip` in `AccessExplainPanel` does.
247+
*/
248+
function positionLabels(positions: readonly unknown[]): Map<string, string> {
249+
const out = new Map<string, string>();
250+
for (const raw of positions) {
251+
const p = raw as { name?: unknown; label?: unknown } | null;
252+
if (typeof p?.name !== 'string' || typeof p.label !== 'string' || !p.label.trim()) continue;
253+
out.set(p.name, p.label);
254+
}
255+
return out;
256+
}
257+
238258
export function AssignedUsersSection({ permissionSetName, onHoldersRead }: AssignedUsersSectionProps) {
239259
const adapter = useAdapter() as any;
240260
// Read through a ref so a host's inline callback does not re-key `load`.
@@ -315,9 +335,11 @@ export function AssignedUsersSection({ permissionSetName, onHoldersRead }: Assig
315335
// are THE distribution channel — a direct-grants-only list told the
316336
// admin "0 users" for any normally-administered set.
317337
let positionNames: string[] = [];
338+
let labelByPosition = new Map<string, string>();
318339
let boundEveryone = false;
319340
try {
320341
const positions = await metadataStoreRef.current.ensureType('position');
342+
labelByPosition = positionLabels(positions);
321343
const names = positionsDistributing(positions, permissionSetName);
322344
// The audience anchors are implicit memberships — `everyone` is every
323345
// signed-in member; enumerating them as rows would be noise. Surface
@@ -345,7 +367,11 @@ export function AssignedUsersSection({ permissionSetName, onHoldersRead }: Assig
345367
for (const a of assignments) {
346368
if (!a?.user_id || !a?.position) continue;
347369
const uid = String(a.user_id);
348-
viaByUser.set(uid, [...(viaByUser.get(uid) ?? []), { kind: 'position' as const, position: String(a.position) }]);
370+
const position = String(a.position);
371+
viaByUser.set(uid, [
372+
...(viaByUser.get(uid) ?? []),
373+
{ kind: 'position' as const, position, label: labelByPosition.get(position) },
374+
]);
349375
}
350376

351377
const userIds = [...viaByUser.keys()];
@@ -535,14 +561,20 @@ export function AssignedUsersSection({ permissionSetName, onHoldersRead }: Assig
535561
<div className="min-w-0 flex-1">
536562
<div className="flex items-center gap-1.5 min-w-0">
537563
<span className="text-sm truncate">{r.name}</span>
538-
{r.via.map((v, i) => (
539-
<span
540-
key={i}
541-
className="shrink-0 rounded border bg-muted/40 px-1.5 py-0.5 text-[10px] leading-none text-muted-foreground"
542-
>
543-
{v.kind === 'direct' ? c.direct : c.viaPosition(v.position)}
544-
</span>
545-
))}
564+
{r.via.map((v, i) => {
565+
// A position reads by its label, with its name on `title`;
566+
// with no label the name is the text (objectui#13477).
567+
const shown = v.kind === 'position' ? v.label ?? v.position : '';
568+
return (
569+
<span
570+
key={i}
571+
className="shrink-0 rounded border bg-muted/40 px-1.5 py-0.5 text-[10px] leading-none text-muted-foreground"
572+
title={v.kind === 'position' && shown !== v.position ? v.position : undefined}
573+
>
574+
{v.kind === 'direct' ? c.direct : c.viaPosition(shown)}
575+
</span>
576+
);
577+
})}
546578
</div>
547579
{r.email && r.email !== r.name && (
548580
<div className="text-xs text-muted-foreground truncate">{r.email}</div>

0 commit comments

Comments
 (0)