Skip to content

Commit 5959bfa

Browse files
committed
feat(console): the user page's Permission Sets tab shows the person's effective sets and where each comes from
A new console widget, security:effective-access, reads security.describeEffectiveAccess(userId) for the bound sys_user record and lists every permission set in force with its origins (default binding, a position by name, a direct grant, or a derived standing). A 403 or 501 leaves one quiet line and no list. It sits above the stored grant list on the Permission Sets tab, where a direct grant keeps its remove action. The zod arm and its TypeScript twin land in @object-ui/types with the registration, the CLI known-types list is regenerated, and the strings are added in all eleven locale packs. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5kxrRdCiSKcPqREG4w
1 parent e735425 commit 5959bfa

28 files changed

Lines changed: 1041 additions & 1 deletion

‎packages/platform-objects/src/pages/canonical-expression-envelopes.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ const UNMAPPED_TYPE_EXEMPTIONS: Readonly<Record<string, string>> = {
172172
'mcp:authorized-assistants':
173173
'the user page\'s AI Assistants tab body (@object-ui/app-shell): the widget takes no props and reads '
174174
+ 'the bound sys_user record, so its authored `properties` is `{}` and holds no expression key',
175+
'security:effective-access':
176+
'the user page\'s Permission Sets tab, above the grant list (@object-ui/app-shell): the widget takes no props '
177+
+ 'and reads the bound sys_user record, so its authored `properties` is `{}` and holds no expression key',
175178
};
176179

177180
/** The authored node at an audit path such as `regions[0].components[2].properties.items[10].children[0]`. */
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The user page's "Permission Sets" tab shows the person's EFFECTIVE sets, not
5+
* only their stored grant rows.
6+
*
7+
* A person who holds access only through the default binding or a position has
8+
* no `sys_user_permission_set` row, so a tab holding only the grant list reads
9+
* as "no records" for them. The tab's first child is the console widget
10+
* `security:effective-access` (`@object-ui/app-shell`), which reads the bound
11+
* `sys_user` record and lists every set the server resolves for the person
12+
* with its origins. The grant list stays below it: a direct grant keeps its
13+
* remove action there.
14+
*
15+
* Read from the shipped page metadata, so the pin fails if the widget leaves
16+
* the tab, moves below the list, or starts authoring props.
17+
*/
18+
19+
import { describe, expect, it } from 'vitest';
20+
import { PageSchema } from '@objectstack/spec/ui';
21+
import { SysUserDetailPage } from './sys-user.page.js';
22+
23+
type Rec = Record<string, unknown>;
24+
25+
describe('sys_user_detail — the Permission Sets tab', () => {
26+
const tabs = (SysUserDetailPage.regions![0]!.components as Rec[]).find((c) => c.type === 'page:tabs') as Rec;
27+
const items = (tabs.properties as Rec).items as Rec[];
28+
const tab = items.find((it) => (it.label as Rec).en === 'Permission Sets')!;
29+
const children = tab.children as Rec[];
30+
31+
it('parses through PageSchema', () => {
32+
const parsed = PageSchema.safeParse(SysUserDetailPage);
33+
expect(parsed.success, JSON.stringify(parsed.error?.issues ?? [])).toBe(true);
34+
});
35+
36+
it('opens with the `security:effective-access` widget, with no props', () => {
37+
expect(children[0]).toEqual({ type: 'security:effective-access', properties: {} });
38+
});
39+
40+
it('keeps the stored grant list below it, where a direct grant is removed', () => {
41+
expect(children.map((c) => c.type)).toEqual(['security:effective-access', 'record:related_list']);
42+
expect((children[1]!.properties as Rec).objectName).toBe('sys_user_permission_set');
43+
});
44+
45+
it('mounts the widget nowhere else on the page', () => {
46+
const found: unknown[] = [];
47+
const walk = (n: unknown): void => {
48+
if (Array.isArray(n)) { n.forEach(walk); return; }
49+
if (!n || typeof n !== 'object') return;
50+
if ((n as Rec).type === 'security:effective-access') found.push(n);
51+
Object.values(n as Rec).forEach(walk);
52+
};
53+
walk(SysUserDetailPage);
54+
expect(found).toHaveLength(1);
55+
});
56+
57+
it('carries no tab-level gate: the server refuses a viewer who may not manage the person', () => {
58+
expect(tab.visibleWhen).toBeUndefined();
59+
});
60+
});

‎packages/platform-objects/src/pages/sys-user.page.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ export const SysUserDetailPage: Page = {
287287
label: { en: 'Permission Sets', 'zh-CN': '权限集', 'ja-JP': '権限セット', 'es-ES': 'Conjuntos de permisos', 'zh-Hant': '權限集', ar: 'مجموعات الأذونات', fr: 'Ensembles d’autorisations' },
288288
icon: 'lock',
289289
children: [
290+
// Effective sets with their origins (default / position / direct / derived), read from the server; the stored grant rows stay below.
291+
{ type: 'security:effective-access', properties: {} },
290292
{
291293
type: 'record:related_list',
292294
properties: {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"./dist/console/connect/ManagedPersonAssistants.js",
1313
"./dist/console/diagnostics/CloudAiModelStatus.js",
1414
"./dist/console/home/CloudWorkspaceTimezoneNotice.js",
15+
"./dist/console/security/UserEffectiveAccess.js",
1516
"./dist/services/builtinComponents.js",
1617
"./dist/views/global-notifications-renderer.js",
1718
"./dist/views/global-search-renderer.js",
@@ -31,6 +32,7 @@
3132
"./src/console/connect/ManagedPersonAssistants.tsx",
3233
"./src/console/diagnostics/CloudAiModelStatus.tsx",
3334
"./src/console/home/CloudWorkspaceTimezoneNotice.tsx",
35+
"./src/console/security/UserEffectiveAccess.tsx",
3436
"./src/services/builtinComponents.tsx",
3537
"./src/views/global-notifications-renderer.tsx",
3638
"./src/views/global-search-renderer.tsx",
Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* `security:effective-access` — a person's effective permission sets on their
5+
* `sys_user` record page, each with every origin the server's answer carries.
6+
*
7+
* Driven through the real input pipeline: the node a page authors
8+
* (`{ type: 'security:effective-access', properties: {} }`) is rendered by
9+
* `SchemaRenderer` inside the record context the page binds, and the widget
10+
* is fed `security.describeEffectiveAccess(userId)`'s answer through the
11+
* adapter's client.
12+
*
13+
* - §1 a person with access only through the default binding and a position
14+
* shows those sets, each with its origin, and the set label;
15+
* - §2 CONTROL: a person with one direct grant shows exactly that set;
16+
* - §3 a set reached two ways is one row with both origins; derived origins
17+
* say which standing;
18+
* - §4 a 403 and a 501 show no list, each a quiet line; another failure
19+
* names itself; an empty answer says so;
20+
* - §5 off a `sys_user` record it renders nothing and reads nothing; a grant
21+
* written on the page reads the answer again.
22+
*
23+
* `t` echoes the key with any interpolation values appended, so assertions
24+
* read which string was asked for and with what.
25+
*/
26+
27+
import '@testing-library/jest-dom/vitest';
28+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
29+
import { cleanup, render, screen, waitFor, within } from '@testing-library/react';
30+
31+
vi.mock('@object-ui/i18n', async (importOriginal) => ({
32+
...(await importOriginal<Record<string, unknown>>()),
33+
useObjectTranslation: () => ({
34+
t: (key: string, opts?: Record<string, unknown>) => {
35+
const vals = opts ? Object.values(opts).filter((v) => typeof v === 'string' || typeof v === 'number') : [];
36+
return vals.length ? `«${key}|${vals.join('|')}»` : `«${key}»`;
37+
},
38+
language: 'en',
39+
}),
40+
}));
41+
42+
let adapter: unknown = null;
43+
vi.mock('@object-ui/react', async (importOriginal) => ({
44+
...(await importOriginal<Record<string, unknown>>()),
45+
useAdapter: () => adapter,
46+
}));
47+
48+
import '@object-ui/components';
49+
import { ComponentRegistry } from '@object-ui/core';
50+
import {
51+
MetadataCtx,
52+
notifyDataChanged,
53+
RecordContextProvider,
54+
SchemaRenderer,
55+
type MetadataContextValue,
56+
} from '@object-ui/react';
57+
import { describeOrigin, type EffectiveAccessAnswer } from './UserEffectiveAccess';
58+
59+
const NODE = { type: 'security:effective-access', properties: {} };
60+
61+
/** The permission-set catalog the labels come from (`/meta/permission`). */
62+
const CATALOG = [
63+
{ name: 'member_default', label: 'Member default' },
64+
{ name: 'sales_rep', label: 'Sales rep' },
65+
{ name: 'admin_full_access', label: 'Full administrator' },
66+
];
67+
68+
const describeMock = vi.fn<(userId: string) => Promise<EffectiveAccessAnswer>>();
69+
const ensureTypeMock = vi.fn(async (_type: string): Promise<unknown[]> => CATALOG);
70+
71+
function refusal(status: number, message: string): Error {
72+
return Object.assign(new Error(message), { httpStatus: status });
73+
}
74+
75+
const metadata = {
76+
ensureType: (type: string) => ensureTypeMock(type),
77+
} as unknown as MetadataContextValue;
78+
79+
function renderOn(objectName: string, recordId: string | null) {
80+
return render(
81+
<MetadataCtx.Provider value={metadata}>
82+
<RecordContextProvider objectName={objectName} recordId={recordId}>
83+
<SchemaRenderer schema={NODE} />
84+
</RecordContextProvider>
85+
</MetadataCtx.Provider>,
86+
);
87+
}
88+
89+
/** The rendered rows, as set name → origin badge texts. */
90+
async function rowsShown(): Promise<Record<string, string[]>> {
91+
const list = await screen.findByTestId('effective-access-list');
92+
const out: Record<string, string[]> = {};
93+
for (const row of within(list).getAllByRole('listitem').filter((li) => li.dataset.testid?.startsWith('effective-access-row-'))) {
94+
const name = row.dataset.testid!.slice('effective-access-row-'.length);
95+
const origins = within(row).getByRole('list');
96+
out[name] = within(origins).getAllByRole('listitem').map((li) => li.textContent ?? '');
97+
}
98+
return out;
99+
}
100+
101+
beforeEach(() => {
102+
describeMock.mockReset();
103+
ensureTypeMock.mockClear();
104+
adapter = { getClient: () => ({ security: { describeEffectiveAccess: describeMock } }) };
105+
});
106+
107+
afterEach(() => {
108+
cleanup();
109+
});
110+
111+
describe('§0 registration', () => {
112+
it('is registered as security:effective-access, with no bare fallback', () => {
113+
expect(ComponentRegistry.get('security:effective-access')).toBeDefined();
114+
expect(ComponentRegistry.get('effective-access')).toBeUndefined();
115+
});
116+
});
117+
118+
describe('§1 access only through the default binding and a position', () => {
119+
it('shows those sets with their origins, not an empty list', async () => {
120+
describeMock.mockResolvedValueOnce({
121+
userId: 'user_mia',
122+
organizationId: 'org_here',
123+
positions: ['org_member', 'sales', 'everyone'],
124+
permissionSets: [
125+
{ name: 'sales_rep', origins: [{ kind: 'position', position: 'sales' }] },
126+
{ name: 'member_default', origins: [{ kind: 'default' }] },
127+
],
128+
});
129+
renderOn('sys_user', 'user_mia');
130+
131+
expect(await rowsShown()).toEqual({
132+
sales_rep: ['«effectiveAccess.origin.position|sales»'],
133+
member_default: ['«effectiveAccess.origin.default»'],
134+
});
135+
expect(describeMock).toHaveBeenCalledWith('user_mia');
136+
expect(screen.queryByTestId('effective-access-empty')).toBeNull();
137+
});
138+
139+
it('shows each set by its catalog label, with the name beside it', async () => {
140+
describeMock.mockResolvedValueOnce({
141+
userId: 'user_mia',
142+
organizationId: 'org_here',
143+
positions: ['everyone'],
144+
permissionSets: [{ name: 'member_default', origins: [{ kind: 'default' }] }],
145+
});
146+
renderOn('sys_user', 'user_mia');
147+
const row = await screen.findByTestId('effective-access-row-member_default');
148+
await waitFor(() => expect(within(row).getByText('Member default')).toBeInTheDocument());
149+
expect(within(row).getByText('member_default')).toBeInTheDocument();
150+
expect(ensureTypeMock).toHaveBeenCalledWith('permission');
151+
});
152+
153+
it('shows a set the catalog does not list by its name, never drops it', async () => {
154+
ensureTypeMock.mockResolvedValueOnce([]);
155+
describeMock.mockResolvedValueOnce({
156+
userId: 'user_mia',
157+
organizationId: 'org_here',
158+
positions: [],
159+
permissionSets: [{ name: 'uncatalogued_set', origins: [{ kind: 'default' }] }],
160+
});
161+
renderOn('sys_user', 'user_mia');
162+
const row = await screen.findByTestId('effective-access-row-uncatalogued_set');
163+
expect(within(row).getAllByText('uncatalogued_set')).toHaveLength(1);
164+
});
165+
});
166+
167+
describe('§2 CONTROL — one direct grant', () => {
168+
it('shows exactly that set, as a direct grant', async () => {
169+
describeMock.mockResolvedValueOnce({
170+
userId: 'user_ana',
171+
organizationId: 'org_here',
172+
positions: [],
173+
permissionSets: [{ name: 'sales_rep', origins: [{ kind: 'direct' }] }],
174+
});
175+
renderOn('sys_user', 'user_ana');
176+
expect(await rowsShown()).toEqual({ sales_rep: ['«effectiveAccess.origin.direct»'] });
177+
});
178+
});
179+
180+
describe('§3 a set reached two ways', () => {
181+
it('is one row carrying both origins, in the answer\'s order', async () => {
182+
describeMock.mockResolvedValueOnce({
183+
userId: 'user_mia',
184+
organizationId: 'org_here',
185+
positions: ['sales'],
186+
permissionSets: [
187+
{ name: 'sales_rep', origins: [{ kind: 'direct' }, { kind: 'position', position: 'sales' }] },
188+
{
189+
name: 'admin_full_access',
190+
origins: [{ kind: 'direct' }, { kind: 'derived', source: 'platform_admin_config' }],
191+
},
192+
{ name: 'ai_seat', origins: [{ kind: 'derived', source: 'ai_access' }] },
193+
],
194+
});
195+
renderOn('sys_user', 'user_mia');
196+
expect(await rowsShown()).toEqual({
197+
sales_rep: ['«effectiveAccess.origin.direct»', '«effectiveAccess.origin.position|sales»'],
198+
admin_full_access: ['«effectiveAccess.origin.direct»', '«effectiveAccess.origin.derivedPlatformAdmin»'],
199+
ai_seat: ['«effectiveAccess.origin.derivedAiAccess»'],
200+
});
201+
expect(screen.getAllByTestId(/^effective-access-row-/)).toHaveLength(3);
202+
});
203+
204+
it('describes every origin kind the contract declares', () => {
205+
const t = (key: string, opts?: Record<string, unknown>) => (opts ? `${key}|${Object.values(opts).join('|')}` : key);
206+
expect(describeOrigin({ kind: 'direct' }, t)).toBe('effectiveAccess.origin.direct');
207+
expect(describeOrigin({ kind: 'position', position: 'org_external' }, t)).toBe('effectiveAccess.origin.position|org_external');
208+
expect(describeOrigin({ kind: 'default' }, t)).toBe('effectiveAccess.origin.default');
209+
expect(describeOrigin({ kind: 'derived', source: 'platform_admin_config' }, t)).toBe('effectiveAccess.origin.derivedPlatformAdmin');
210+
expect(describeOrigin({ kind: 'derived', source: 'ai_access' }, t)).toBe('effectiveAccess.origin.derivedAiAccess');
211+
});
212+
});
213+
214+
describe('§4 refusals never draw a list', () => {
215+
it('a 403 (a person the caller may not manage) leaves one quiet line and no list', async () => {
216+
describeMock.mockRejectedValueOnce(refusal(403, 'Forbidden'));
217+
renderOn('sys_user', 'user_other');
218+
expect(await screen.findByTestId('effective-access-refused')).toHaveTextContent('«effectiveAccess.refused»');
219+
expect(screen.queryByTestId('effective-access-list')).toBeNull();
220+
expect(screen.queryByTestId('effective-access-empty')).toBeNull();
221+
});
222+
223+
it('a 501 (a server without the read) leaves one quiet line and no list', async () => {
224+
describeMock.mockRejectedValueOnce(refusal(501, 'Not implemented'));
225+
renderOn('sys_user', 'user_mia');
226+
expect(await screen.findByTestId('effective-access-unserved')).toHaveTextContent('«effectiveAccess.unserved»');
227+
expect(screen.queryByTestId('effective-access-list')).toBeNull();
228+
expect(screen.queryByTestId('effective-access-empty')).toBeNull();
229+
});
230+
231+
it('any other failure names itself, and draws no list', async () => {
232+
describeMock.mockRejectedValueOnce(refusal(500, 'authorization store could not be read'));
233+
renderOn('sys_user', 'user_mia');
234+
expect(await screen.findByTestId('effective-access-failed')).toHaveTextContent(
235+
'«effectiveAccess.loadFailed|authorization store could not be read»',
236+
);
237+
expect(screen.queryByTestId('effective-access-list')).toBeNull();
238+
});
239+
240+
it('an answer with no set says so', async () => {
241+
describeMock.mockResolvedValueOnce({ userId: 'user_mia', organizationId: null, positions: [], permissionSets: [] });
242+
renderOn('sys_user', 'user_mia');
243+
expect(await screen.findByTestId('effective-access-empty')).toHaveTextContent('«effectiveAccess.empty»');
244+
});
245+
});
246+
247+
describe('§5 where it draws, and when it reads again', () => {
248+
it('renders nothing and reads nothing off a sys_user record', () => {
249+
const other = renderOn('crm_account', 'acc_1');
250+
expect(other.container).toBeEmptyDOMElement();
251+
other.unmount();
252+
const noId = renderOn('sys_user', null);
253+
expect(noId.container).toBeEmptyDOMElement();
254+
expect(describeMock).not.toHaveBeenCalled();
255+
});
256+
257+
it('reads the answer again when a grant on the page changes', async () => {
258+
describeMock.mockResolvedValue({
259+
userId: 'user_mia',
260+
organizationId: 'org_here',
261+
positions: [],
262+
permissionSets: [{ name: 'sales_rep', origins: [{ kind: 'direct' }] }],
263+
});
264+
renderOn('sys_user', 'user_mia');
265+
await screen.findByTestId('effective-access-list');
266+
expect(describeMock).toHaveBeenCalledTimes(1);
267+
notifyDataChanged({ objectName: 'sys_user_permission_set' });
268+
await waitFor(() => expect(describeMock).toHaveBeenCalledTimes(2));
269+
});
270+
});

0 commit comments

Comments
 (0)