@bevel-software/platform-core-frontend 0.10.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/core/CoreAppShell.tsx +2 -0
- package/src/core/registry.ts +25 -0
- package/src/lib/email.ts +25 -0
- package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +1 -1
- package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +280 -4
- package/src/modules/access/api.ts +47 -13
- package/src/modules/access/components/ManageAccessDialog.tsx +119 -49
- package/src/modules/admin/__tests__/AdminRolesPage.capabilities.test.tsx +281 -0
- package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +4 -4
- package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +438 -0
- package/src/modules/admin/components/AdminRolesPage.tsx +203 -411
- package/src/modules/admin/components/DirectoryGroupsPage.tsx +610 -0
- package/src/modules/admin/hooks/useExclusiveRunner.ts +27 -0
- package/src/modules/admin/services/groups.api.ts +151 -0
- package/src/modules/admin/services/roles.api.ts +57 -31
- package/src/modules/library/__tests__/LibraryRoutes.test.tsx +42 -3
- package/src/modules/library/__tests__/PluginPage.test.tsx +29 -0
- package/src/modules/library/__tests__/ToolPage.test.tsx +22 -0
- package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +90 -0
- package/src/modules/library/components/LibraryPage.tsx +2 -2
- package/src/modules/library/components/PersonalPluginPage.tsx +2 -2
- package/src/modules/library/components/PluginPage.tsx +2 -2
- package/src/modules/library/components/tool-page/ToolPage.tsx +7 -1
- package/src/modules/library/routes/LibraryRoutes.tsx +6 -4
- package/src/modules/library/routes/WorkspaceItemRoute.tsx +33 -5
- package/src/modules/library/routes/library-paths.ts +30 -0
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +63 -17
- package/src/modules/onboarding/agent-clients.ts +21 -7
- package/src/modules/onboarding/components/WelcomePage.tsx +1 -1
- package/src/modules/settings/settings-nav-items.tsx +9 -1
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +135 -20
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +113 -14
- package/src/shared/mcp/__tests__/connect-snippets.test.ts +66 -0
- package/src/shared/mcp/connect-snippets.ts +76 -0
- package/src/shared/mcp/index.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bevel-software/platform-core-frontend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "Open-source core UI of the Bevel platform (raw TS/TSX source): workspace explorer/viewer, branches & change requests, Library, secrets, tools, access control.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"tailwind-merge": "^3.5.0",
|
|
42
42
|
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",
|
|
43
43
|
"yaml": "^2.9.0",
|
|
44
|
-
"@bevel-software/platform-shared": "0.
|
|
44
|
+
"@bevel-software/platform-shared": "0.11.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@testing-library/jest-dom": "^6.9.1",
|
|
@@ -45,6 +45,7 @@ import { AccountPage } from '../modules/auth/components/AccountPage';
|
|
|
45
45
|
import { ExternalAgentAccessPage } from '../modules/toolbar/components/ExternalAgentAccessPage';
|
|
46
46
|
import { AdminRolesPage } from '../modules/admin/components/AdminRolesPage';
|
|
47
47
|
import { UserAccountsPage } from '../modules/admin/components/UserAccountsPage';
|
|
48
|
+
import { DirectoryGroupsPage } from '../modules/admin/components/DirectoryGroupsPage';
|
|
48
49
|
import { ToolsExplorerPage } from '../modules/tools/ToolsExplorerPage';
|
|
49
50
|
import { LibraryRoutes } from '../modules/library/routes/LibraryRoutes';
|
|
50
51
|
import { RootLanding } from '../modules/onboarding/components/RootLanding';
|
|
@@ -412,6 +413,7 @@ export function ShellRoutes({ apps }: { apps: AppDef[] }) {
|
|
|
412
413
|
<Route path="/roles-and-members" element={<AdminRolesPage />} />
|
|
413
414
|
<Route path="/deployment" element={<DeploymentPage />} />
|
|
414
415
|
<Route path="/user-accounts" element={<UserAccountsPage />} />
|
|
416
|
+
<Route path="/directory-groups" element={<DirectoryGroupsPage />} />
|
|
415
417
|
<Route path="/tools" element={<ToolsExplorerPage />} />
|
|
416
418
|
</Route>
|
|
417
419
|
{/* `/` consults the onboarding: a brand-new account's FIRST visit lands
|
package/src/core/registry.ts
CHANGED
|
@@ -252,6 +252,22 @@ export interface ToolbarItemDef {
|
|
|
252
252
|
order?: number;
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
+
/** Props for the overlay-provided panel on the Groups settings page. */
|
|
256
|
+
export interface GroupsDirectoryPanelProps {
|
|
257
|
+
/** The active group source, as the roster reports it. */
|
|
258
|
+
mode: 'manual' | 'idp';
|
|
259
|
+
/** Re-fetch the roster — call after any action that may flip the mode. */
|
|
260
|
+
onDirectoryChanged: () => void;
|
|
261
|
+
/**
|
|
262
|
+
* Report whether a directory connection EXISTS — which the roster alone
|
|
263
|
+
* cannot see: between connecting and the first provisioning push the mode
|
|
264
|
+
* still reads 'manual' (the synced file hasn't landed), yet the IdP already
|
|
265
|
+
* owns groups and manual edits would go dormant on the first push. The page
|
|
266
|
+
* suppresses manual CRUD while this is true.
|
|
267
|
+
*/
|
|
268
|
+
onConnectedChange: (connected: boolean) => void;
|
|
269
|
+
}
|
|
270
|
+
|
|
255
271
|
export interface AppRegistry {
|
|
256
272
|
/** Apps appended to the toolbar's app switcher (see {@link AppDef}). */
|
|
257
273
|
apps: AppDef[];
|
|
@@ -285,6 +301,15 @@ export interface AppRegistry {
|
|
|
285
301
|
renderers: FileRendererDef[];
|
|
286
302
|
/** Extra rows in the explorer's Pinned section (see {@link ExplorerItemDef}). */
|
|
287
303
|
explorerItems: ExplorerItemDef[];
|
|
304
|
+
/**
|
|
305
|
+
* The Groups settings page's directory-connection panel. Core's Groups
|
|
306
|
+
* page manages MANUAL groups and renders the IdP-synced roster read-only;
|
|
307
|
+
* HOW a deployment connects an identity provider (e.g. SCIM provisioning)
|
|
308
|
+
* is an enterprise concern, so the page reserves this slot for an overlay
|
|
309
|
+
* panel. Rendered below the groups list in both modes; absent means the
|
|
310
|
+
* page simply never mentions a directory connection.
|
|
311
|
+
*/
|
|
312
|
+
groupsDirectoryPanel?: ComponentType<GroupsDirectoryPanelProps>;
|
|
288
313
|
/**
|
|
289
314
|
* How many unread items the gear menu's badge should show, if anything is
|
|
290
315
|
* counting. CORE COUNTS NOTHING: the feedback inbox behind that badge is an
|
package/src/lib/email.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ONE email-validation rule for every access/admin surface (Manage Access,
|
|
3
|
+
* Roles & Members, Groups). Mirrors the backend's `EMAIL_REGEX`
|
|
4
|
+
* (access-control.service.ts): no whitespace, no `<`/`>` (angle-bracket
|
|
5
|
+
* forms like `Name <a@b.c>` are a different grammar), and exactly one `@`.
|
|
6
|
+
*
|
|
7
|
+
* Three per-surface copies existed and had already drifted (`<`/`>` slipped
|
|
8
|
+
* through two of them) — a value the client accepts and the server refuses is
|
|
9
|
+
* a round trip wasted on an error the input could have caught.
|
|
10
|
+
*/
|
|
11
|
+
export const EMAIL_RE = /^[^<>\s@]+@[^<>\s@]+\.[^<>\s@]+$/;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The roles.yaml grammar prefix for a group REFERENCE (`group:<name>`) —
|
|
15
|
+
* never a member email. The backend refuses `group:`-prefixed member values
|
|
16
|
+
* (a `group:lee@x.io` would pass the email regex and land a dead ref);
|
|
17
|
+
* member inputs mirror that refusal with an inline hint instead of a round
|
|
18
|
+
* trip.
|
|
19
|
+
*/
|
|
20
|
+
export const GROUP_MEMBER_PREFIX = 'group:';
|
|
21
|
+
|
|
22
|
+
/** True when a typed member value is a `group:` reference, not an email. */
|
|
23
|
+
export function isGroupPrefixed(value: string): boolean {
|
|
24
|
+
return value.trim().toLowerCase().startsWith(GROUP_MEMBER_PREFIX);
|
|
25
|
+
}
|
|
@@ -124,7 +124,7 @@ let offsetHeightDescriptor: PropertyDescriptor | undefined;
|
|
|
124
124
|
beforeEach(() => {
|
|
125
125
|
vi.clearAllMocks();
|
|
126
126
|
api.fetchFileAccess.mockResolvedValue(VIEW);
|
|
127
|
-
api.suggestPrincipals.mockResolvedValue({
|
|
127
|
+
api.suggestPrincipals.mockResolvedValue({ roles: [], groups: [], people: [], peopleWithheld: false });
|
|
128
128
|
|
|
129
129
|
rects.clear();
|
|
130
130
|
watchers = [];
|
|
@@ -46,7 +46,7 @@ async function openAndUncheckEdit(user: ReturnType<typeof userEvent.setup>) {
|
|
|
46
46
|
describe('ManageAccessDialog: unchecking an inherited verb on a mixed row', () => {
|
|
47
47
|
beforeEach(() => {
|
|
48
48
|
vi.clearAllMocks();
|
|
49
|
-
api.suggestPrincipals.mockResolvedValue({
|
|
49
|
+
api.suggestPrincipals.mockResolvedValue({ roles: [], groups: [], people: [], peopleWithheld: false });
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
it('write PURELY inherited (download direct): uncheck "Can edit" → 409 → opens prompt on FIRST click, revokes only write', async () => {
|
|
@@ -166,7 +166,7 @@ describe('ManageAccessDialog: which workspace the edit targets', () => {
|
|
|
166
166
|
|
|
167
167
|
beforeEach(() => {
|
|
168
168
|
vi.clearAllMocks();
|
|
169
|
-
api.suggestPrincipals.mockResolvedValue({
|
|
169
|
+
api.suggestPrincipals.mockResolvedValue({ roles: [], groups: [], people: [], peopleWithheld: false });
|
|
170
170
|
api.fetchFileAccess.mockResolvedValue(VIEW);
|
|
171
171
|
api.grantAccess.mockResolvedValue(VIEW);
|
|
172
172
|
});
|
|
@@ -215,7 +215,7 @@ describe('ManageAccessDialog: which workspace the edit targets', () => {
|
|
|
215
215
|
describe('ManageAccessDialog: naming the rules', () => {
|
|
216
216
|
beforeEach(() => {
|
|
217
217
|
vi.clearAllMocks();
|
|
218
|
-
api.suggestPrincipals.mockResolvedValue({
|
|
218
|
+
api.suggestPrincipals.mockResolvedValue({ roles: [], groups: [], people: [], peopleWithheld: false });
|
|
219
219
|
});
|
|
220
220
|
|
|
221
221
|
/** The real AccessResponse shape — see the passing fixture above. */
|
|
@@ -240,7 +240,7 @@ describe('ManageAccessDialog: naming the rules', () => {
|
|
|
240
240
|
expect(screen.queryByRole('heading', { name: /People with access/i })).not.toBeInTheDocument();
|
|
241
241
|
});
|
|
242
242
|
|
|
243
|
-
it('gives each granting folder its own
|
|
243
|
+
it('gives each granting folder its own section, named after the folder', async () => {
|
|
244
244
|
api.fetchFileAccess.mockResolvedValue(
|
|
245
245
|
view({
|
|
246
246
|
readers: { restricted: true, roles: [], users: [A, { name: 'Bo', email: 'bo@x.com' }] },
|
|
@@ -293,3 +293,279 @@ describe('ManageAccessDialog: naming the rules', () => {
|
|
|
293
293
|
expect(screen.queryByRole('button', { name: /Manage Sales →/ })).not.toBeInTheDocument();
|
|
294
294
|
});
|
|
295
295
|
});
|
|
296
|
+
|
|
297
|
+
// ── group principals in the picker ──
|
|
298
|
+
describe('ManageAccessDialog: group principals', () => {
|
|
299
|
+
const VIEW = {
|
|
300
|
+
canRead: true,
|
|
301
|
+
canWrite: true,
|
|
302
|
+
canDownload: false,
|
|
303
|
+
canOwner: false,
|
|
304
|
+
eligible: { roles: [], users: [A] },
|
|
305
|
+
readers: { restricted: true, roles: [], users: [A] },
|
|
306
|
+
owners: { roles: [], users: [] },
|
|
307
|
+
downloaders: { roles: [], users: [] },
|
|
308
|
+
sources: { 'u:alice@x.com': { read: [{ kind: 'direct' }], write: [{ kind: 'direct' }] } },
|
|
309
|
+
} as AccessResponse;
|
|
310
|
+
|
|
311
|
+
beforeEach(() => {
|
|
312
|
+
vi.clearAllMocks();
|
|
313
|
+
api.fetchFileAccess.mockResolvedValue(VIEW);
|
|
314
|
+
api.grantAccess.mockResolvedValue(VIEW);
|
|
315
|
+
api.suggestPrincipals.mockResolvedValue({
|
|
316
|
+
roles: [],
|
|
317
|
+
groups: ['GTM Team'],
|
|
318
|
+
people: [],
|
|
319
|
+
peopleWithheld: false,
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it('suggests active groups, chips one, and grants it with the group kind', async () => {
|
|
324
|
+
const user = userEvent.setup();
|
|
325
|
+
render(<ManageAccessDialog entry={ENTRY} onClose={() => {}} />);
|
|
326
|
+
|
|
327
|
+
await user.type(
|
|
328
|
+
await screen.findByPlaceholderText(/add people, groups, or roles/i),
|
|
329
|
+
'gtm',
|
|
330
|
+
);
|
|
331
|
+
// The suggestion row carries the "group" tag and chips on click.
|
|
332
|
+
await user.click(await screen.findByRole('button', { name: /GTM Team/ }));
|
|
333
|
+
expect(screen.getByText('GTM Team')).toBeInTheDocument();
|
|
334
|
+
|
|
335
|
+
await user.click(screen.getByRole('button', { name: /^Share$/ }));
|
|
336
|
+
await waitFor(() => expect(api.grantAccess).toHaveBeenCalled());
|
|
337
|
+
expect(api.grantAccess).toHaveBeenCalledWith(
|
|
338
|
+
'ws-1',
|
|
339
|
+
expect.objectContaining({ principal: { kind: 'group', group: 'GTM Team' } }),
|
|
340
|
+
);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it('suggests roles from the `roles` field (never the retired `plugins` alias) and grants the role kind', async () => {
|
|
344
|
+
const user = userEvent.setup();
|
|
345
|
+
// A server still emitting the deprecated alias: the dialog must read
|
|
346
|
+
// `roles` and IGNORE `plugins` — the alias is not in the type, and the
|
|
347
|
+
// suggestion list must come from the new field alone.
|
|
348
|
+
api.suggestPrincipals.mockResolvedValue({
|
|
349
|
+
roles: ['Admin'],
|
|
350
|
+
groups: [],
|
|
351
|
+
people: [],
|
|
352
|
+
peopleWithheld: false,
|
|
353
|
+
plugins: ['Stale Alias Role'],
|
|
354
|
+
} as never);
|
|
355
|
+
render(<ManageAccessDialog entry={ENTRY} onClose={() => {}} />);
|
|
356
|
+
|
|
357
|
+
await user.type(
|
|
358
|
+
await screen.findByPlaceholderText(/add people, groups, or roles/i),
|
|
359
|
+
'adm',
|
|
360
|
+
);
|
|
361
|
+
expect(await screen.findByRole('button', { name: /Admin/ })).toBeInTheDocument();
|
|
362
|
+
expect(screen.queryByRole('button', { name: /Stale Alias Role/ })).not.toBeInTheDocument();
|
|
363
|
+
|
|
364
|
+
await user.click(screen.getByRole('button', { name: /Admin/ }));
|
|
365
|
+
await user.click(screen.getByRole('button', { name: /^Share$/ }));
|
|
366
|
+
await waitFor(() => expect(api.grantAccess).toHaveBeenCalled());
|
|
367
|
+
expect(api.grantAccess).toHaveBeenCalledWith(
|
|
368
|
+
'ws-1',
|
|
369
|
+
expect.objectContaining({ principal: { kind: 'role', role: 'Admin' } }),
|
|
370
|
+
);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
it('a suggest response missing `roles` and `groups` renders people and never throws', async () => {
|
|
374
|
+
const user = userEvent.setup();
|
|
375
|
+
// Version skew: an older/newer server may omit either field entirely. The
|
|
376
|
+
// dialog reads every field defensively — this used to crash.
|
|
377
|
+
api.suggestPrincipals.mockResolvedValue({
|
|
378
|
+
people: [{ name: 'Bo', email: 'bo@x.com' }],
|
|
379
|
+
peopleWithheld: false,
|
|
380
|
+
} as never);
|
|
381
|
+
render(<ManageAccessDialog entry={ENTRY} onClose={() => {}} />);
|
|
382
|
+
|
|
383
|
+
await user.type(
|
|
384
|
+
await screen.findByPlaceholderText(/add people, groups, or roles/i),
|
|
385
|
+
'bo',
|
|
386
|
+
);
|
|
387
|
+
expect(await screen.findByRole('button', { name: /Bo/ })).toBeInTheDocument();
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
it('a suggest response with ONLY roles/groups (people absent) still lists them', async () => {
|
|
391
|
+
const user = userEvent.setup();
|
|
392
|
+
api.suggestPrincipals.mockResolvedValue({
|
|
393
|
+
roles: ['Admin'],
|
|
394
|
+
groups: ['GTM Team'],
|
|
395
|
+
} as never);
|
|
396
|
+
render(<ManageAccessDialog entry={ENTRY} onClose={() => {}} />);
|
|
397
|
+
|
|
398
|
+
await user.type(
|
|
399
|
+
await screen.findByPlaceholderText(/add people, groups, or roles/i),
|
|
400
|
+
'a',
|
|
401
|
+
);
|
|
402
|
+
expect(await screen.findByRole('button', { name: /GTM Team/ })).toBeInTheDocument();
|
|
403
|
+
expect(screen.getByRole('button', { name: /Admin/ })).toBeInTheDocument();
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
// ── grantee rows: a group is badged "Group", a role "Role" ──
|
|
408
|
+
//
|
|
409
|
+
// The eligible lists' `principals` carry each collective's kind; the old
|
|
410
|
+
// name-only `roles` list forced every collective row into a "Role" badge —
|
|
411
|
+
// a group grantee rendered as a role, and its mutations round-tripped with
|
|
412
|
+
// the wrong principal kind (a grant on the row would 404 as an unknown role).
|
|
413
|
+
describe('ManageAccessDialog: grantee rows badge roles vs groups', () => {
|
|
414
|
+
/** GTM Team (a GROUP) holds write directly; Engineering (a ROLE) holds read. */
|
|
415
|
+
const VIEW = {
|
|
416
|
+
canRead: true,
|
|
417
|
+
canWrite: true,
|
|
418
|
+
canDownload: false,
|
|
419
|
+
canOwner: false,
|
|
420
|
+
eligible: {
|
|
421
|
+
principals: [{ name: 'GTM Team', kind: 'group' }],
|
|
422
|
+
roles: ['GTM Team'],
|
|
423
|
+
users: [],
|
|
424
|
+
},
|
|
425
|
+
readers: {
|
|
426
|
+
restricted: true,
|
|
427
|
+
principals: [{ name: 'Engineering', kind: 'role' }],
|
|
428
|
+
roles: ['Engineering'],
|
|
429
|
+
users: [],
|
|
430
|
+
},
|
|
431
|
+
owners: { principals: [], roles: [], users: [] },
|
|
432
|
+
downloaders: { principals: [], roles: [], users: [] },
|
|
433
|
+
sources: {
|
|
434
|
+
'r:gtm team': { write: [{ kind: 'direct' }] },
|
|
435
|
+
'r:engineering': { read: [{ kind: 'direct' }] },
|
|
436
|
+
},
|
|
437
|
+
} as AccessResponse;
|
|
438
|
+
|
|
439
|
+
beforeEach(() => {
|
|
440
|
+
vi.clearAllMocks();
|
|
441
|
+
api.suggestPrincipals.mockResolvedValue({ roles: [], groups: [], people: [], peopleWithheld: false });
|
|
442
|
+
api.fetchFileAccess.mockResolvedValue(VIEW);
|
|
443
|
+
api.grantAccess.mockResolvedValue(VIEW);
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
it('badges each collective row with its kind', async () => {
|
|
447
|
+
render(<ManageAccessDialog entry={ENTRY} onClose={() => {}} />);
|
|
448
|
+
expect(await screen.findByText('GTM Team')).toBeInTheDocument();
|
|
449
|
+
// One badge each, with the right words — a group must NOT read "Role".
|
|
450
|
+
expect(screen.getByText('Group')).toBeInTheDocument();
|
|
451
|
+
expect(screen.getByText('Role')).toBeInTheDocument();
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
it('round-trips a group row mutation with the group principal kind', async () => {
|
|
455
|
+
const user = userEvent.setup();
|
|
456
|
+
render(<ManageAccessDialog entry={ENTRY} onClose={() => {}} />);
|
|
457
|
+
|
|
458
|
+
// The GTM row's trigger reads "Can edit" (the add-row selector does too —
|
|
459
|
+
// the row's is the later one in the DOM). Check "Can download" on it.
|
|
460
|
+
const triggers = await screen.findAllByRole('button', { name: /^can edit$/i });
|
|
461
|
+
await user.click(triggers[triggers.length - 1]);
|
|
462
|
+
await user.click(await screen.findByRole('button', { name: /^can download$/i }));
|
|
463
|
+
|
|
464
|
+
await waitFor(() => expect(api.grantAccess).toHaveBeenCalledTimes(1));
|
|
465
|
+
expect(api.grantAccess).toHaveBeenCalledWith(
|
|
466
|
+
'ws-1',
|
|
467
|
+
expect.objectContaining({
|
|
468
|
+
verb: 'download',
|
|
469
|
+
principal: { kind: 'group', group: 'GTM Team' },
|
|
470
|
+
}),
|
|
471
|
+
);
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
it('a group and a role SHARING one name are two rows, each mutating its own kind', async () => {
|
|
475
|
+
// The backend treats bare `Product` (the group) and `role/Product` (the
|
|
476
|
+
// role) as different principals. One collapsed row silently pointed every
|
|
477
|
+
// edit at the group and hid the role's grant.
|
|
478
|
+
const user = userEvent.setup();
|
|
479
|
+
const SHARED = {
|
|
480
|
+
...VIEW,
|
|
481
|
+
eligible: {
|
|
482
|
+
principals: [
|
|
483
|
+
{ name: 'Product', kind: 'group' },
|
|
484
|
+
{ name: 'Product', kind: 'role' },
|
|
485
|
+
],
|
|
486
|
+
roles: ['Product'],
|
|
487
|
+
users: [],
|
|
488
|
+
},
|
|
489
|
+
readers: { restricted: true, principals: [], roles: [], users: [] },
|
|
490
|
+
sources: {
|
|
491
|
+
'g:product': { write: [{ kind: 'direct' }] },
|
|
492
|
+
'r:product': { write: [{ kind: 'direct' }] },
|
|
493
|
+
},
|
|
494
|
+
} as AccessResponse;
|
|
495
|
+
api.fetchFileAccess.mockResolvedValue(SHARED);
|
|
496
|
+
api.grantAccess.mockResolvedValue(SHARED);
|
|
497
|
+
render(<ManageAccessDialog entry={ENTRY} onClose={() => {}} />);
|
|
498
|
+
|
|
499
|
+
// Both rows render, one badged Group, one badged Role.
|
|
500
|
+
expect(await screen.findAllByText('Product')).toHaveLength(2);
|
|
501
|
+
expect(screen.getByText('Group')).toBeInTheDocument();
|
|
502
|
+
expect(screen.getByText('Role')).toBeInTheDocument();
|
|
503
|
+
|
|
504
|
+
// Toggling "Can download" on each row round-trips ITS kind. Rows render
|
|
505
|
+
// in eligible order (group first), after the add-row selector — so the
|
|
506
|
+
// trigger list is [add-row, group row, role row].
|
|
507
|
+
const triggers = await screen.findAllByRole('button', { name: /^can edit$/i });
|
|
508
|
+
expect(triggers).toHaveLength(3);
|
|
509
|
+
await user.click(triggers[1]); // the group row
|
|
510
|
+
await user.click(await screen.findByRole('button', { name: /^can download$/i }));
|
|
511
|
+
await waitFor(() => expect(api.grantAccess).toHaveBeenCalledTimes(1));
|
|
512
|
+
expect(api.grantAccess).toHaveBeenLastCalledWith(
|
|
513
|
+
'ws-1',
|
|
514
|
+
expect.objectContaining({ principal: { kind: 'group', group: 'Product' } }),
|
|
515
|
+
);
|
|
516
|
+
|
|
517
|
+
// Close the group row's still-open menu (its items also read "Can edit"),
|
|
518
|
+
// then open the role row's.
|
|
519
|
+
await user.click((await screen.findAllByRole('button', { name: /^can edit$/i }))[1]);
|
|
520
|
+
const after = await screen.findAllByRole('button', { name: /^can edit$/i });
|
|
521
|
+
expect(after).toHaveLength(3);
|
|
522
|
+
await user.click(after[2]); // the role row
|
|
523
|
+
await user.click(await screen.findByRole('button', { name: /^can download$/i }));
|
|
524
|
+
await waitFor(() => expect(api.grantAccess).toHaveBeenCalledTimes(2));
|
|
525
|
+
expect(api.grantAccess).toHaveBeenLastCalledWith(
|
|
526
|
+
'ws-1',
|
|
527
|
+
expect.objectContaining({ principal: { kind: 'role', role: 'Product' } }),
|
|
528
|
+
);
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
it('the picker keeps BOTH chips when a group and a role share the typed name', async () => {
|
|
532
|
+
const user = userEvent.setup();
|
|
533
|
+
api.suggestPrincipals.mockResolvedValue({
|
|
534
|
+
roles: ['Product'],
|
|
535
|
+
groups: ['Product'],
|
|
536
|
+
people: [],
|
|
537
|
+
peopleWithheld: false,
|
|
538
|
+
});
|
|
539
|
+
render(<ManageAccessDialog entry={ENTRY} onClose={() => {}} />);
|
|
540
|
+
|
|
541
|
+
const input = await screen.findByPlaceholderText(/add people, groups, or roles/i);
|
|
542
|
+
await user.type(input, 'prod');
|
|
543
|
+
// The group suggestion (tagged "group") chips first…
|
|
544
|
+
await user.click(await screen.findByRole('button', { name: /Product group/i }));
|
|
545
|
+
// …then the role suggestion must NOT be dropped as a duplicate.
|
|
546
|
+
await user.type(input, 'prod');
|
|
547
|
+
await user.click(await screen.findByRole('button', { name: /Product role/i }));
|
|
548
|
+
|
|
549
|
+
// Two chips — one per kind — each with its own remove affordance.
|
|
550
|
+
const chips = screen.getAllByRole('button', { name: /Remove Product/ });
|
|
551
|
+
expect(chips).toHaveLength(2);
|
|
552
|
+
|
|
553
|
+
await user.click(screen.getByRole('button', { name: /^Share$/ }));
|
|
554
|
+
await waitFor(() => expect(api.grantAccess).toHaveBeenCalledTimes(2));
|
|
555
|
+
const granted = api.grantAccess.mock.calls.map((c) => (c[1] as { principal: unknown }).principal);
|
|
556
|
+
expect(granted).toContainEqual({ kind: 'group', group: 'Product' });
|
|
557
|
+
expect(granted).toContainEqual({ kind: 'role', role: 'Product' });
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
it('falls back to name-only `roles` (badged "Role") when `principals` is absent — version skew', async () => {
|
|
561
|
+
api.fetchFileAccess.mockResolvedValue({
|
|
562
|
+
...VIEW,
|
|
563
|
+
eligible: { roles: ['GTM Team'], users: [] },
|
|
564
|
+
readers: { restricted: true, roles: [], users: [] },
|
|
565
|
+
} as AccessResponse);
|
|
566
|
+
render(<ManageAccessDialog entry={ENTRY} onClose={() => {}} />);
|
|
567
|
+
expect(await screen.findByText('GTM Team')).toBeInTheDocument();
|
|
568
|
+
expect(screen.getByText('Role')).toBeInTheDocument();
|
|
569
|
+
expect(screen.queryByText('Group')).not.toBeInTheDocument();
|
|
570
|
+
});
|
|
571
|
+
});
|
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import { authFetch } from '../../lib/api';
|
|
2
2
|
import { GitApiError, handleApiResponse } from '../git/services/git.api';
|
|
3
3
|
|
|
4
|
+
/** A collective grantee with WHAT it is — role (capability) or group (audience). */
|
|
5
|
+
export interface ResolvedPrincipal {
|
|
6
|
+
name: string;
|
|
7
|
+
kind: 'role' | 'group';
|
|
8
|
+
}
|
|
9
|
+
|
|
4
10
|
export interface AccessEligible {
|
|
11
|
+
/**
|
|
12
|
+
* Kinded twin of `roles` — the same names, each saying whether it is a ROLE
|
|
13
|
+
* or a GROUP, so grantee rows can badge honestly and round-trip mutations
|
|
14
|
+
* with the right principal kind. Optional for version skew: an older server
|
|
15
|
+
* omits it, and readers fall back to `roles` (all treated as roles).
|
|
16
|
+
*/
|
|
17
|
+
principals?: ResolvedPrincipal[];
|
|
5
18
|
roles: string[];
|
|
6
19
|
users: { name: string; email: string }[];
|
|
7
20
|
}
|
|
@@ -15,7 +28,7 @@ export interface AccessReaders extends AccessEligible {
|
|
|
15
28
|
* ONE place a principal is named for a verb (mirrors the backend `GrantSource`).
|
|
16
29
|
* Both kinds are file-backed and removable from the dialog: `direct` → remove
|
|
17
30
|
* here; `ancestor` → remove-from-parent or deny-here. A principal who only
|
|
18
|
-
* resolves via a
|
|
31
|
+
* resolves via a role / group / `everyone` / admin-rescue produces no source.
|
|
19
32
|
*/
|
|
20
33
|
export type GrantSource =
|
|
21
34
|
| { kind: 'direct' }
|
|
@@ -51,11 +64,14 @@ export interface AccessResponse {
|
|
|
51
64
|
downloaders: AccessEligible;
|
|
52
65
|
/**
|
|
53
66
|
* Per-principal, per-verb sources of access. Keyed `u:<email>` / `r:<role>`
|
|
54
|
-
* (lowercased) to match the dialog's row keys, so a row can
|
|
55
|
-
* access comes from (direct, inherited, or both) and which
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
67
|
+
* / `g:<group>` (lowercased) to match the dialog's row keys, so a row can
|
|
68
|
+
* show where its access comes from (direct, inherited, or both) and which
|
|
69
|
+
* verbs are removable here. Groups have their own `g:` namespace — a group
|
|
70
|
+
* and a role sharing a name are different principals with different
|
|
71
|
+
* sources (older servers keyed groups under `r:`; readers fall back). After
|
|
72
|
+
* a revoke, a principal whose direct entry was stripped but who remains
|
|
73
|
+
* inherited still appears here with only their `ancestor` source(s) — which
|
|
74
|
+
* is how the dialog chains into "Remove from parent?".
|
|
59
75
|
*/
|
|
60
76
|
sources: Record<string, GrantSources>;
|
|
61
77
|
}
|
|
@@ -85,23 +101,41 @@ export function asInheritedError(err: unknown): InheritedRevokeError | null {
|
|
|
85
101
|
return null;
|
|
86
102
|
}
|
|
87
103
|
|
|
88
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* A grantable principal — a person (by email), a role (an app-defined
|
|
106
|
+
* capability from the registry, or a legacy roles.yaml role), or a group (a
|
|
107
|
+
* people-set from the active group source — IdP-synced or manual). Groups are
|
|
108
|
+
* written as bare-name tokens (bare names resolve group-first); the backend
|
|
109
|
+
* writes role grants as explicit `role/<Name>` tokens itself — the dialog
|
|
110
|
+
* just sends `kind: 'role'`. The separate kinds exist so the backend
|
|
111
|
+
* validates each against the right namespace.
|
|
112
|
+
*/
|
|
89
113
|
export type Principal =
|
|
90
114
|
| { kind: 'user'; email: string; displayName: string }
|
|
91
|
-
| { kind: 'role'; role: string }
|
|
115
|
+
| { kind: 'role'; role: string }
|
|
116
|
+
| { kind: 'group'; group: string };
|
|
92
117
|
|
|
93
118
|
/** Verbs the share dialog can grant. */
|
|
94
119
|
export type GrantVerb = 'read' | 'write' | 'owner' | 'download';
|
|
95
120
|
|
|
121
|
+
/**
|
|
122
|
+
* The suggest payload. Every field is read DEFENSIVELY (`?.` / `?? []`) in
|
|
123
|
+
* the dialog: under version skew a server may omit one, and a missing field
|
|
124
|
+
* must degrade to an empty section, never a crash. (The retired `plugins`
|
|
125
|
+
* alias of `roles` is deliberately NOT in this type — nothing may read it.)
|
|
126
|
+
*/
|
|
96
127
|
export interface SuggestResponse {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
|
|
128
|
+
/** Role principals (registry roles + legacy roles.yaml roles + `Everyone`). */
|
|
129
|
+
roles?: string[];
|
|
130
|
+
/** Active-source groups. A name shared with a role is offered as BOTH. */
|
|
131
|
+
groups?: string[];
|
|
132
|
+
people?: { name: string; email: string }[];
|
|
133
|
+
/** True when the query was too short to return people (roles/groups still shown). */
|
|
134
|
+
peopleWithheld?: boolean;
|
|
101
135
|
}
|
|
102
136
|
|
|
103
137
|
/**
|
|
104
|
-
* Autocomplete the share dialog: matching
|
|
138
|
+
* Autocomplete the share dialog: matching roles + groups + people. People are
|
|
105
139
|
* withheld until the query is ≥ 2 chars (server-side harvesting guard).
|
|
106
140
|
*/
|
|
107
141
|
export async function suggestPrincipals(
|