@bevel-software/platform-core-frontend 0.27.0 → 0.28.0
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/ProductName.tsx +4 -4
- package/src/core/__tests__/ProductName.test.tsx +46 -0
- package/src/core/maker-url.ts +30 -0
- package/src/core/registry.ts +27 -0
- package/src/lib/__tests__/latest-request.test.ts +48 -0
- package/src/lib/latest-request.ts +45 -0
- package/src/modules/access/__tests__/ManageAccessDialog.no-sso-invite.test.tsx +222 -0
- package/src/modules/access/api.ts +19 -3
- package/src/modules/access/components/ManageAccessDialog.tsx +60 -7
- package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +16 -1
- package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +284 -39
- package/src/modules/admin/components/AdminRolesPage.tsx +13 -14
- package/src/modules/admin/components/UserAccountsPage.tsx +91 -107
- package/src/modules/admin/services/roles.api.ts +14 -1
- package/src/modules/auth/__tests__/LoginScreen.test.tsx +80 -5
- package/src/modules/auth/__tests__/sso-strict-probe.test.ts +66 -0
- package/src/modules/auth/components/LoginScreen.tsx +100 -75
- package/src/modules/auth/services/account.api.ts +31 -2
- package/src/modules/auth/services/sso.ts +29 -8
- package/src/modules/auth/state/use-sign-in-methods.ts +41 -0
- package/src/modules/onboarding/__tests__/InviteButton.test.tsx +214 -0
- package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +56 -1
- package/src/modules/onboarding/__tests__/get-started-column.test.tsx +538 -81
- package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +543 -124
- package/src/modules/onboarding/__tests__/invite-emails.test.ts +247 -0
- package/src/modules/onboarding/components/GetStartedColumn.tsx +30 -11
- package/src/modules/onboarding/components/InviteButton.tsx +119 -15
- package/src/modules/onboarding/components/InviteDialog.tsx +392 -75
- package/src/modules/onboarding/first-page-prompt.ts +34 -0
- package/src/modules/onboarding/invite-emails.ts +171 -33
- package/src/modules/onboarding/state/invite-dialog.context.ts +7 -4
- package/src/modules/onboarding/state/invite-dialog.tsx +12 -4
- package/src/modules/toolbar/commands/actions.tsx +10 -4
- package/src/modules/toolbar/commands/useCommandActions.ts +5 -3
- package/src/modules/toolbar/components/AppSwitcher.tsx +19 -0
- package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +46 -1
- package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +34 -2
- package/src/modules/workspace/hooks/__tests__/useCreatePage.test.ts +137 -0
- package/src/modules/workspace/hooks/__tests__/useKnowledgeWriteTarget.test.ts +302 -0
- package/src/modules/workspace/hooks/useCreatePage.ts +118 -28
- package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +238 -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.28.0",
|
|
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",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"tailwind-merge": "^3.5.0",
|
|
46
46
|
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",
|
|
47
47
|
"yaml": "^2.9.0",
|
|
48
|
-
"@bevel-software/platform-shared": "0.
|
|
48
|
+
"@bevel-software/platform-shared": "0.28.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@testing-library/jest-dom": "^6.9.1",
|
package/src/core/ProductName.tsx
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* this is the one thing in the frontend that says which product this is.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { useMakerUrl } from './maker-url';
|
|
9
|
+
|
|
8
10
|
/** The product's own name, before its maker's: the first half of {@link PRODUCT_NAME}. */
|
|
9
11
|
const PRODUCT = 'Hexis';
|
|
10
12
|
|
|
@@ -18,9 +20,6 @@ const MAKER = 'Bevel';
|
|
|
18
20
|
*/
|
|
19
21
|
export const PRODUCT_NAME = `${PRODUCT} by ${MAKER}`;
|
|
20
22
|
|
|
21
|
-
/** Where the maker's name leads. */
|
|
22
|
-
export const MAKER_URL = 'https://bevel.software';
|
|
23
|
-
|
|
24
23
|
/**
|
|
25
24
|
* The product's name wherever it is shown: "Hexis by Bevel", with the maker's
|
|
26
25
|
* name a link to its site.
|
|
@@ -34,11 +33,12 @@ export const MAKER_URL = 'https://bevel.software';
|
|
|
34
33
|
* {@link PRODUCT_NAME}.
|
|
35
34
|
*/
|
|
36
35
|
export function ProductName({ link = true, className }: { link?: boolean; className?: string }) {
|
|
36
|
+
const makerUrl = useMakerUrl();
|
|
37
37
|
return (
|
|
38
38
|
<span className={className}>
|
|
39
39
|
{PRODUCT} by{' '}
|
|
40
40
|
{link ? (
|
|
41
|
-
<a href={
|
|
41
|
+
<a href={makerUrl} target="_blank" rel="noopener noreferrer" className="text-accent hover:underline">
|
|
42
42
|
{MAKER}
|
|
43
43
|
</a>
|
|
44
44
|
) : (
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
2
|
+
import { cleanup, render, screen } from '@testing-library/react';
|
|
3
|
+
import { ProductName } from '../ProductName';
|
|
4
|
+
import { MAKER_URL } from '../maker-url';
|
|
5
|
+
import { AppRegistryContext, makeRegistry } from '../registry';
|
|
6
|
+
|
|
7
|
+
afterEach(cleanup);
|
|
8
|
+
|
|
9
|
+
describe('ProductName', () => {
|
|
10
|
+
it("links the maker's name to the maker's site by default", () => {
|
|
11
|
+
render(<ProductName />);
|
|
12
|
+
expect(screen.getByRole('link', { name: 'Bevel' })).toHaveAttribute('href', MAKER_URL);
|
|
13
|
+
expect(MAKER_URL).toBe('https://bevel.software');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('links it where the registry says, for a distribution with its own front door', () => {
|
|
17
|
+
render(
|
|
18
|
+
<AppRegistryContext.Provider value={makeRegistry({ makerLink: 'https://hexis.software' })}>
|
|
19
|
+
<ProductName />
|
|
20
|
+
</AppRegistryContext.Provider>,
|
|
21
|
+
);
|
|
22
|
+
const link = screen.getByRole('link', { name: 'Bevel' });
|
|
23
|
+
expect(link).toHaveAttribute('href', 'https://hexis.software');
|
|
24
|
+
expect(link).toHaveAttribute('target', '_blank');
|
|
25
|
+
expect(link.closest('span')).toHaveTextContent('Hexis by Bevel');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("links the maker's site when the registry's place is empty, as when it is absent", () => {
|
|
29
|
+
render(
|
|
30
|
+
<AppRegistryContext.Provider value={makeRegistry({ makerLink: '' })}>
|
|
31
|
+
<ProductName />
|
|
32
|
+
</AppRegistryContext.Provider>,
|
|
33
|
+
);
|
|
34
|
+
expect(screen.getByRole('link', { name: 'Bevel' })).toHaveAttribute('href', MAKER_URL);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('is plain text where a link cannot go, wherever the registry would send it', () => {
|
|
38
|
+
render(
|
|
39
|
+
<AppRegistryContext.Provider value={makeRegistry({ makerLink: 'https://hexis.software' })}>
|
|
40
|
+
<ProductName link={false} />
|
|
41
|
+
</AppRegistryContext.Provider>,
|
|
42
|
+
);
|
|
43
|
+
expect(screen.queryByRole('link')).toBeNull();
|
|
44
|
+
expect(screen.getByText('Hexis by Bevel')).toBeInTheDocument();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the maker's name in "Hexis by Bevel" leads. Its own module because
|
|
3
|
+
* two components link the name, `ProductName` and the toolbar's app menu,
|
|
4
|
+
* and a component's file exports components only (fast refresh).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { useAppRegistry } from './registry';
|
|
8
|
+
|
|
9
|
+
/** Where the maker's name leads when the registry names no other place (`makerLink` absent or empty). */
|
|
10
|
+
export const MAKER_URL = 'https://bevel.software';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Where the maker's name leads in this deployment: the registry's
|
|
14
|
+
* `makerLink`, absent or empty {@link MAKER_URL}. One place for the rule, so
|
|
15
|
+
* the toolbar's menu, which links the name where its trigger cannot, leads
|
|
16
|
+
* where `ProductName` does.
|
|
17
|
+
*/
|
|
18
|
+
export function useMakerUrl(): string {
|
|
19
|
+
const { makerLink } = useAppRegistry();
|
|
20
|
+
return makerLink || MAKER_URL;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* What the app menu's entry for that place says: the registry's
|
|
25
|
+
* `makerLinkLabel`, absent or empty `fallback` (the product's name).
|
|
26
|
+
*/
|
|
27
|
+
export function useMakerLinkLabel(fallback: string): string {
|
|
28
|
+
const { makerLinkLabel } = useAppRegistry();
|
|
29
|
+
return makerLinkLabel?.trim() || fallback;
|
|
30
|
+
}
|
package/src/core/registry.ts
CHANGED
|
@@ -517,6 +517,33 @@ export interface AppRegistry {
|
|
|
517
517
|
* the other is the likeliest way to produce it.
|
|
518
518
|
*/
|
|
519
519
|
welcomeExit?: { path: string; label: string };
|
|
520
|
+
/**
|
|
521
|
+
* Where the maker's name in "Hexis by Bevel" leads (see `ProductName`):
|
|
522
|
+
* the login page, the first-run screen and the toolbar, where a wide
|
|
523
|
+
* toolbar links the name beside the apps and a compact one, whose name
|
|
524
|
+
* sits inside the menu's trigger, links it at the foot of the app menu.
|
|
525
|
+
* Absent or empty, it is the maker's own site. A distribution with a front
|
|
526
|
+
* door of its own points it there: the hosted cloud sends it to its
|
|
527
|
+
* Impressum, so the provider's details are one click from any workspace
|
|
528
|
+
* page on a wide toolbar and two on a compact one.
|
|
529
|
+
*/
|
|
530
|
+
makerLink?: string;
|
|
531
|
+
/**
|
|
532
|
+
* What the app menu's own entry for `makerLink` says, where the name is
|
|
533
|
+
* not on screen as a link: the compact toolbar, and a wide one with more
|
|
534
|
+
* than three apps. Absent or empty, it says "Hexis by Bevel". The hosted
|
|
535
|
+
* cloud says "Impressum", so a page in the app names its Impressum as one
|
|
536
|
+
* a visitor recognises, not only behind the maker's name.
|
|
537
|
+
*/
|
|
538
|
+
makerLinkLabel?: string;
|
|
539
|
+
/**
|
|
540
|
+
* Links under the sign-in card, on the login page only: the app behind it
|
|
541
|
+
* shows none. For a deployment whose provider must name itself to anyone
|
|
542
|
+
* who reaches it, such as the hosted cloud, which lists its Impressum and
|
|
543
|
+
* privacy policy here because German law wants them easy to recognise on
|
|
544
|
+
* every page of a commercial service. Absent or empty, there are none.
|
|
545
|
+
*/
|
|
546
|
+
loginLinks?: { label: string; href: string }[];
|
|
520
547
|
/**
|
|
521
548
|
* A panel inside the invite dialog, between the role choice and the footer.
|
|
522
549
|
*
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { LatestRequest } from '../latest-request';
|
|
3
|
+
|
|
4
|
+
/** A request that answers when told to. */
|
|
5
|
+
function deferred<T>() {
|
|
6
|
+
let resolve!: (value: T) => void;
|
|
7
|
+
const promise = new Promise<T>((r) => (resolve = r));
|
|
8
|
+
return { promise, resolve };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
describe('LatestRequest', () => {
|
|
12
|
+
it('applies and returns the answer of a request nothing overtook', async () => {
|
|
13
|
+
const applied: string[] = [];
|
|
14
|
+
const latest = new LatestRequest<string>();
|
|
15
|
+
expect(await latest.run(async () => 'a', (v) => applied.push(v))).toBe('a');
|
|
16
|
+
expect(applied).toEqual(['a']);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('never applies an overtaken answer, and hands its caller the newest one, whatever order they answer in', async () => {
|
|
20
|
+
const applied: string[] = [];
|
|
21
|
+
const latest = new LatestRequest<string>();
|
|
22
|
+
const first = deferred<string>();
|
|
23
|
+
const second = deferred<string>();
|
|
24
|
+
const a = latest.run(() => first.promise, (v) => applied.push(v));
|
|
25
|
+
const b = latest.run(() => second.promise, (v) => applied.push(v));
|
|
26
|
+
// The older answers first: it is not applied, and its caller waits on.
|
|
27
|
+
first.resolve('old');
|
|
28
|
+
second.resolve('new');
|
|
29
|
+
expect(await a).toBe('new');
|
|
30
|
+
expect(await b).toBe('new');
|
|
31
|
+
expect(applied).toEqual(['new']);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('waits through a request started while it was already waiting on a newer one', async () => {
|
|
35
|
+
const applied: string[] = [];
|
|
36
|
+
const latest = new LatestRequest<string>();
|
|
37
|
+
const [one, two, three] = [deferred<string>(), deferred<string>(), deferred<string>()];
|
|
38
|
+
const a = latest.run(() => one.promise, (v) => applied.push(v));
|
|
39
|
+
latest.run(() => two.promise, (v) => applied.push(v));
|
|
40
|
+
one.resolve('1');
|
|
41
|
+
await Promise.resolve();
|
|
42
|
+
latest.run(() => three.promise, (v) => applied.push(v));
|
|
43
|
+
two.resolve('2');
|
|
44
|
+
three.resolve('3');
|
|
45
|
+
expect(await a).toBe('3');
|
|
46
|
+
expect(applied).toEqual(['3']);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* "Only the latest request's answer counts", in one place. A screen that
|
|
5
|
+
* asks the server again whenever something changes (a list re-read after a
|
|
6
|
+
* send, a check re-asked after a page change) can have several requests out
|
|
7
|
+
* at once, and they can answer in any order.
|
|
8
|
+
*
|
|
9
|
+
* `run(start, apply)` starts a request and:
|
|
10
|
+
* - applies its answer only if no newer request was started meanwhile, so a
|
|
11
|
+
* slow reply to an older question never overwrites a newer one;
|
|
12
|
+
* - resolves with the answer of the LATEST request, waiting through any that
|
|
13
|
+
* start while it waits, so a caller that asked before a change is handed
|
|
14
|
+
* the answer for what is on screen now, never the one it started.
|
|
15
|
+
*
|
|
16
|
+
* `start` must not reject: fold a failure into the value it resolves with.
|
|
17
|
+
*/
|
|
18
|
+
export class LatestRequest<T> {
|
|
19
|
+
private seq = 0;
|
|
20
|
+
private latest: Promise<T> | null = null;
|
|
21
|
+
|
|
22
|
+
async run(start: () => Promise<T>, apply: (value: T) => void): Promise<T> {
|
|
23
|
+
const n = ++this.seq;
|
|
24
|
+
const mine = start();
|
|
25
|
+
this.latest = mine;
|
|
26
|
+
let value = await mine;
|
|
27
|
+
if (n === this.seq) {
|
|
28
|
+
apply(value);
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
// Superseded: the newest request applies its own answer; hand back
|
|
32
|
+
// whichever is newest once each one we waited on has answered.
|
|
33
|
+
let waited: Promise<T> = mine;
|
|
34
|
+
while (this.latest && this.latest !== waited) {
|
|
35
|
+
waited = this.latest;
|
|
36
|
+
value = await waited;
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** One {@link LatestRequest} for the life of a component. */
|
|
43
|
+
export function useLatestRequest<T>(): LatestRequest<T> {
|
|
44
|
+
return useState(() => new LatestRequest<T>())[0];
|
|
45
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { render, screen, waitFor, within } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import type { FileTreeEntry } from '@bevel-software/platform-shared';
|
|
5
|
+
import type { AccessResponse } from '../api';
|
|
6
|
+
import type { LoginProviders } from '../../auth/services/sso';
|
|
7
|
+
import { AdminContext, type AdminContextValue } from '../../admin/state/admin.context';
|
|
8
|
+
import {
|
|
9
|
+
InviteDialogContext,
|
|
10
|
+
type InviteDialogController,
|
|
11
|
+
} from '../../onboarding/state/invite-dialog.context';
|
|
12
|
+
|
|
13
|
+
const api = vi.hoisted(() => ({
|
|
14
|
+
fetchFileAccess: vi.fn(),
|
|
15
|
+
grantAccess: vi.fn(),
|
|
16
|
+
revokeAccess: vi.fn(),
|
|
17
|
+
suggestPrincipals: vi.fn(),
|
|
18
|
+
}));
|
|
19
|
+
vi.mock('../api', async (importOriginal) => {
|
|
20
|
+
const actual = await importOriginal<typeof import('../api')>();
|
|
21
|
+
return { ...actual, ...api };
|
|
22
|
+
});
|
|
23
|
+
const { providersMock } = vi.hoisted(() => ({ providersMock: vi.fn<() => Promise<LoginProviders>>() }));
|
|
24
|
+
vi.mock('../../auth/services/sso', async (importOriginal) => ({
|
|
25
|
+
...(await importOriginal<typeof import('../../auth/services/sso')>()),
|
|
26
|
+
fetchLoginProvidersStrict: providersMock,
|
|
27
|
+
}));
|
|
28
|
+
vi.mock('../../workspace/state/workspace.context', () => ({
|
|
29
|
+
useWorkspace: () => ({ workspaceId: 'ws-1', kbDirName: 'knowledge-base' }),
|
|
30
|
+
}));
|
|
31
|
+
vi.mock('../../auth/state/auth.context', () => ({
|
|
32
|
+
useAuth: () => ({ user: { email: 'me@x.com', name: 'Me' } }),
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
import { ManageAccessDialog } from '../components/ManageAccessDialog';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Manage access on a deployment with no single sign-on: an address with no
|
|
39
|
+
* account cannot sign in until someone invites it, so the row says so — to
|
|
40
|
+
* an admin, with an Invite action that opens the Invite dialog with that
|
|
41
|
+
* address; to anyone else, that an admin has to. The grant saves exactly as
|
|
42
|
+
* before. With single sign-on, or when the sign-in methods could not be
|
|
43
|
+
* read, the note is today's.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
const KB = 'knowledge-base';
|
|
47
|
+
const ENTRY: FileTreeEntry = {
|
|
48
|
+
name: 'Deal.md',
|
|
49
|
+
relativePath: `${KB}/Sales/Deal.md`,
|
|
50
|
+
type: 'file',
|
|
51
|
+
} as unknown as FileTreeEntry;
|
|
52
|
+
|
|
53
|
+
const KNOWN = { name: 'Alice', email: 'alice@x.com' };
|
|
54
|
+
const UNKNOWN = { name: 'new.hire', email: 'new.hire@x.com' };
|
|
55
|
+
const TODAY_NOTE = /hasn't signed in yet/i;
|
|
56
|
+
const TODAY_HELP =
|
|
57
|
+
'No account for this email yet. The grant is saved and takes effect the moment they first sign in — if you did not expect this, check the spelling.';
|
|
58
|
+
const ADMIN_HELP = "No account yet. They can't sign in until you invite them.";
|
|
59
|
+
const MEMBER_HELP = "No account yet. They can't sign in until an admin invites them.";
|
|
60
|
+
|
|
61
|
+
const viewWith = (users: { name: string; email: string; hasAccount?: boolean }[]): AccessResponse =>
|
|
62
|
+
({
|
|
63
|
+
canRead: true,
|
|
64
|
+
canWrite: true,
|
|
65
|
+
canDownload: false,
|
|
66
|
+
canOwner: false,
|
|
67
|
+
eligible: { roles: [], users: [] },
|
|
68
|
+
readers: { restricted: true, roles: [], users },
|
|
69
|
+
owners: { roles: [], users: [] },
|
|
70
|
+
downloaders: { roles: [], users: [] },
|
|
71
|
+
sources: Object.fromEntries(
|
|
72
|
+
users.map((u) => [`u:${u.email.toLowerCase()}`, { read: [{ kind: 'direct' }] }]),
|
|
73
|
+
),
|
|
74
|
+
}) as AccessResponse;
|
|
75
|
+
|
|
76
|
+
function adminValue(isAdmin: boolean): AdminContextValue {
|
|
77
|
+
return {
|
|
78
|
+
isAdmin,
|
|
79
|
+
isAdminLoading: false,
|
|
80
|
+
unreadCount: 0,
|
|
81
|
+
lastSeen: null,
|
|
82
|
+
markSeen: () => {},
|
|
83
|
+
refresh: () => {},
|
|
84
|
+
rolesConfigCorrupted: false,
|
|
85
|
+
rolesConfigErrors: [],
|
|
86
|
+
runRolesRecovery: async () => {},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function mount(isAdmin: boolean) {
|
|
91
|
+
const invite: InviteDialogController = { open: vi.fn(), invitedRevision: 0 };
|
|
92
|
+
render(
|
|
93
|
+
<AdminContext.Provider value={adminValue(isAdmin)}>
|
|
94
|
+
<InviteDialogContext.Provider value={invite}>
|
|
95
|
+
<ManageAccessDialog entry={ENTRY} onClose={() => {}} />
|
|
96
|
+
</InviteDialogContext.Provider>
|
|
97
|
+
</AdminContext.Provider>,
|
|
98
|
+
);
|
|
99
|
+
return invite;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function rowFor(name: string): Promise<HTMLElement> {
|
|
103
|
+
const label = await screen.findByText(name);
|
|
104
|
+
const row = label.closest('div.flex.flex-wrap');
|
|
105
|
+
if (!row) throw new Error(`no row around ${name}`);
|
|
106
|
+
return row as HTMLElement;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function chipFor(label: string): HTMLElement {
|
|
110
|
+
return screen.getByRole('button', { name: `Remove ${label}` }).parentElement!;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Type an unknown address into the picker, chip it, check the chip's help
|
|
115
|
+
* (`title`) while it is still on screen — Share removes it — and Share.
|
|
116
|
+
*/
|
|
117
|
+
async function grantToUnknown(title: string) {
|
|
118
|
+
const user = userEvent.setup();
|
|
119
|
+
const input = await screen.findByPlaceholderText('Add people, groups, roles or plugins…');
|
|
120
|
+
await user.type(input, UNKNOWN.email);
|
|
121
|
+
await waitFor(() => expect(api.suggestPrincipals).toHaveBeenCalled());
|
|
122
|
+
await user.keyboard('{Enter}');
|
|
123
|
+
expect(within(chipFor(UNKNOWN.name)).getByText(TODAY_NOTE)).toHaveAttribute('title', title);
|
|
124
|
+
await user.click(screen.getByRole('button', { name: /^share$/i }));
|
|
125
|
+
await waitFor(() => expect(api.grantAccess).toHaveBeenCalled());
|
|
126
|
+
expect(api.grantAccess).toHaveBeenCalledWith(
|
|
127
|
+
'ws-1',
|
|
128
|
+
expect.objectContaining({
|
|
129
|
+
principal: { kind: 'user', email: UNKNOWN.email, displayName: UNKNOWN.name },
|
|
130
|
+
}),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
beforeEach(() => {
|
|
135
|
+
vi.clearAllMocks();
|
|
136
|
+
api.fetchFileAccess.mockResolvedValue(
|
|
137
|
+
viewWith([
|
|
138
|
+
{ ...KNOWN, hasAccount: true },
|
|
139
|
+
{ ...UNKNOWN, hasAccount: false },
|
|
140
|
+
]),
|
|
141
|
+
);
|
|
142
|
+
api.grantAccess.mockResolvedValue(viewWith([]));
|
|
143
|
+
api.suggestPrincipals.mockResolvedValue({
|
|
144
|
+
roles: [],
|
|
145
|
+
groups: [],
|
|
146
|
+
people: [],
|
|
147
|
+
peopleWithheld: false,
|
|
148
|
+
accountsKnown: true,
|
|
149
|
+
});
|
|
150
|
+
providersMock.mockResolvedValue({ password: true, sso: [] });
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe('ManageAccessDialog, no single sign-on', () => {
|
|
154
|
+
it('an admin reads that they can’t sign in until invited, and Invite opens the dialog with the address', async () => {
|
|
155
|
+
const invite = mount(true);
|
|
156
|
+
const row = await rowFor(UNKNOWN.name);
|
|
157
|
+
expect(await within(row).findByText(ADMIN_HELP)).toBeInTheDocument();
|
|
158
|
+
expect(within(row).queryByText(TODAY_NOTE)).toBeNull();
|
|
159
|
+
await userEvent.click(within(row).getByRole('button', { name: `Invite ${UNKNOWN.email}` }));
|
|
160
|
+
expect(invite.open).toHaveBeenCalledWith({ emails: [UNKNOWN.email] });
|
|
161
|
+
// Someone with an account gets neither.
|
|
162
|
+
const known = await rowFor(KNOWN.name);
|
|
163
|
+
expect(within(known).queryByRole('button', { name: /^Invite/ })).toBeNull();
|
|
164
|
+
expect(within(known).queryByText(ADMIN_HELP)).toBeNull();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('anyone else reads that an admin has to invite them, and gets no action', async () => {
|
|
168
|
+
const invite = mount(false);
|
|
169
|
+
const row = await rowFor(UNKNOWN.name);
|
|
170
|
+
expect(await within(row).findByText(MEMBER_HELP)).toBeInTheDocument();
|
|
171
|
+
expect(within(row).queryByRole('button', { name: /^Invite/ })).toBeNull();
|
|
172
|
+
expect(invite.open).not.toHaveBeenCalled();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('the grant saves as today, and the new chip carries the same help — for an admin', async () => {
|
|
176
|
+
mount(true);
|
|
177
|
+
await screen.findByText(ADMIN_HELP);
|
|
178
|
+
await grantToUnknown(ADMIN_HELP);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('the grant saves as today, and the new chip carries the same help — for anyone else', async () => {
|
|
182
|
+
mount(false);
|
|
183
|
+
await screen.findByText(MEMBER_HELP);
|
|
184
|
+
await grantToUnknown(MEMBER_HELP);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
describe('ManageAccessDialog keeps today’s note', () => {
|
|
189
|
+
it('on a deployment with password sign-in off and no single sign-on, where an invite would not let anyone in', async () => {
|
|
190
|
+
providersMock.mockResolvedValue({ password: false, sso: [] });
|
|
191
|
+
mount(true);
|
|
192
|
+
await waitFor(() => expect(providersMock).toHaveBeenCalled());
|
|
193
|
+
const row = await rowFor(UNKNOWN.name);
|
|
194
|
+
await waitFor(() => expect(within(row).getByText(TODAY_NOTE)).toHaveAttribute('title', TODAY_HELP));
|
|
195
|
+
expect(within(row).queryByText(ADMIN_HELP)).toBeNull();
|
|
196
|
+
expect(within(row).queryByRole('button', { name: /^Invite/ })).toBeNull();
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('on a deployment with single sign-on', async () => {
|
|
200
|
+
providersMock.mockResolvedValue({
|
|
201
|
+
password: true,
|
|
202
|
+
sso: [{ key: 'oidc', label: 'Duende Demo', startPath: '/api/auth/oidc/start' }],
|
|
203
|
+
});
|
|
204
|
+
mount(true);
|
|
205
|
+
await waitFor(() => expect(providersMock).toHaveBeenCalled());
|
|
206
|
+
const row = await rowFor(UNKNOWN.name);
|
|
207
|
+
await waitFor(() => expect(within(row).getByText(TODAY_NOTE)).toHaveAttribute('title', TODAY_HELP));
|
|
208
|
+
expect(within(row).queryByText(ADMIN_HELP)).toBeNull();
|
|
209
|
+
expect(within(row).queryByRole('button', { name: /^Invite/ })).toBeNull();
|
|
210
|
+
await grantToUnknown(TODAY_HELP);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('when the sign-in methods could not be read', async () => {
|
|
214
|
+
providersMock.mockRejectedValue(new Error('offline'));
|
|
215
|
+
mount(true);
|
|
216
|
+
await waitFor(() => expect(providersMock).toHaveBeenCalled());
|
|
217
|
+
const row = await rowFor(UNKNOWN.name);
|
|
218
|
+
expect(within(row).getByText(TODAY_NOTE)).toHaveAttribute('title', TODAY_HELP);
|
|
219
|
+
expect(within(row).queryByText(ADMIN_HELP)).toBeNull();
|
|
220
|
+
expect(within(row).queryByRole('button', { name: /^Invite/ })).toBeNull();
|
|
221
|
+
});
|
|
222
|
+
});
|
|
@@ -355,15 +355,16 @@ export async function fetchFileAccess(
|
|
|
355
355
|
|
|
356
356
|
/**
|
|
357
357
|
* Batch lookup — one round trip resolves one verb for multiple paths: write
|
|
358
|
-
* permission by default,
|
|
359
|
-
* a writer (an Admin included) does not have by writing
|
|
358
|
+
* permission by default, `owner` — membership in an `owner:` grant, which
|
|
359
|
+
* a writer (an Admin included) does not have by writing — or `read`, the
|
|
360
|
+
* verdict `fetchFileAccess` gives as `canRead`.
|
|
360
361
|
* Caller-supplied path strings are the keys of the returned record. Throws if
|
|
361
362
|
* any path is rejected by the backend.
|
|
362
363
|
*/
|
|
363
364
|
export async function fetchFileAccessBatch(
|
|
364
365
|
workspaceId: string,
|
|
365
366
|
relativePaths: string[],
|
|
366
|
-
verb: 'write' | 'owner' = 'write',
|
|
367
|
+
verb: 'write' | 'owner' | 'read' = 'write',
|
|
367
368
|
): Promise<{ results: Record<string, boolean> }> {
|
|
368
369
|
return handleApiResponse(
|
|
369
370
|
await authFetch(`/api/workspace/${workspaceId}/access/batch`, {
|
|
@@ -470,3 +471,18 @@ export async function fetchAccessOverrides(
|
|
|
470
471
|
);
|
|
471
472
|
}
|
|
472
473
|
|
|
474
|
+
|
|
475
|
+
/** One admin, as `GET /api/access/admins` names them to anyone signed in. */
|
|
476
|
+
export interface AdminContact {
|
|
477
|
+
name: string;
|
|
478
|
+
email: string;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Who the admins are — names and emails, nothing else about roles. Open to
|
|
483
|
+
* everyone signed in, so someone who is not an admin knows whom to ask.
|
|
484
|
+
*/
|
|
485
|
+
export async function fetchAdmins(): Promise<AdminContact[]> {
|
|
486
|
+
const body = await handleApiResponse<{ admins: AdminContact[] }>(await authFetch('/api/access/admins'));
|
|
487
|
+
return body.admins;
|
|
488
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Fragment,
|
|
3
3
|
useCallback,
|
|
4
|
+
useContext,
|
|
4
5
|
useEffect,
|
|
5
6
|
useLayoutEffect,
|
|
6
7
|
useMemo,
|
|
@@ -34,6 +35,9 @@ import {
|
|
|
34
35
|
} from '../../../shared/components';
|
|
35
36
|
import { useWorkspace } from '../../workspace/state/workspace.context';
|
|
36
37
|
import { useAuth } from '../../auth/state/auth.context';
|
|
38
|
+
import { useSignInMethods } from '../../auth/state/use-sign-in-methods';
|
|
39
|
+
import { AdminContext } from '../../admin/state/admin.context';
|
|
40
|
+
import { useInviteDialog } from '../../onboarding/state/invite-dialog.context';
|
|
37
41
|
import {
|
|
38
42
|
fetchFileAccess,
|
|
39
43
|
grantAccess,
|
|
@@ -344,13 +348,24 @@ const NO_ACCOUNT_NOTE = "hasn't signed in yet";
|
|
|
344
348
|
const NO_ACCOUNT_HELP =
|
|
345
349
|
'No account for this email yet. The grant is saved and takes effect the moment they first sign in — if you did not expect this, check the spelling.';
|
|
346
350
|
|
|
351
|
+
/**
|
|
352
|
+
* On a deployment with no single sign-on, no sign-in creates the account:
|
|
353
|
+
* until someone invites them (and gives them a password), they cannot get in
|
|
354
|
+
* at all, and "takes effect the moment they first sign in" would be a promise
|
|
355
|
+
* nobody keeps. So there the help says so — to an admin, who can invite them
|
|
356
|
+
* from the row, and to anyone else, who has to ask one. The grant itself
|
|
357
|
+
* saves exactly as before.
|
|
358
|
+
*/
|
|
359
|
+
const NO_ACCOUNT_HELP_ADMIN = "No account yet. They can't sign in until you invite them.";
|
|
360
|
+
const NO_ACCOUNT_HELP_MEMBER = "No account yet. They can't sign in until an admin invites them.";
|
|
361
|
+
|
|
347
362
|
/** The note itself — muted and small, the same weight as a row's second line. */
|
|
348
|
-
function NoAccountNote() {
|
|
363
|
+
function NoAccountNote({ help = NO_ACCOUNT_HELP }: { help?: string }) {
|
|
349
364
|
return (
|
|
350
365
|
<span
|
|
351
366
|
className="shrink-0 whitespace-nowrap text-detail italic text-ink-faint"
|
|
352
|
-
title={
|
|
353
|
-
aria-description={
|
|
367
|
+
title={help}
|
|
368
|
+
aria-description={help}
|
|
354
369
|
>
|
|
355
370
|
{NO_ACCOUNT_NOTE}
|
|
356
371
|
</span>
|
|
@@ -878,6 +893,18 @@ export function ManageAccessDialog({
|
|
|
878
893
|
: null
|
|
879
894
|
: (workspaceIdProp ?? ctxWorkspaceId);
|
|
880
895
|
const { user } = useAuth();
|
|
896
|
+
// How people sign in here decides what "no account yet" means (see
|
|
897
|
+
// `NO_ACCOUNT_HELP_ADMIN`). Single sign-on, or an answer we could not get:
|
|
898
|
+
// today's words. Optional context: the dialog is mounted bare in tests.
|
|
899
|
+
const signIn = useSignInMethods();
|
|
900
|
+
// Password sign-in and no single sign-on: an invite (which gives a
|
|
901
|
+
// password) is what lets this person in. With password sign-in off as
|
|
902
|
+
// well nobody could sign in and an invite would not change that, so that
|
|
903
|
+
// deployment keeps today's words rather than promising one.
|
|
904
|
+
const noSso = signIn.status === 'ready' && signIn.methods.sso.length === 0 && signIn.methods.password;
|
|
905
|
+
const isAdmin = useContext(AdminContext)?.isAdmin ?? false;
|
|
906
|
+
const invite = useInviteDialog();
|
|
907
|
+
const noAccountHelp = noSso ? (isAdmin ? NO_ACCOUNT_HELP_ADMIN : NO_ACCOUNT_HELP_MEMBER) : NO_ACCOUNT_HELP;
|
|
881
908
|
const [data, setData] = useState<AccessResponse | null>(null);
|
|
882
909
|
const [loading, setLoading] = useState(!proposalBranchMissing);
|
|
883
910
|
const [error, setError] = useState<string | null>(
|
|
@@ -1660,6 +1687,20 @@ export function ManageAccessDialog({
|
|
|
1660
1687
|
</span>
|
|
1661
1688
|
);
|
|
1662
1689
|
|
|
1690
|
+
// An admin, on a deployment with no single sign-on, can turn a grant to an
|
|
1691
|
+
// address with no account into a way in: Invite opens the Invite dialog on
|
|
1692
|
+
// top of this one with the address filled in. Nothing about the grant changes.
|
|
1693
|
+
const inviteAction = (p: PrincipalRow) => {
|
|
1694
|
+
if (!noSso || !isAdmin || !invite || p.kind !== 'user' || p.hasAccount !== false) return null;
|
|
1695
|
+
if (p.principal.kind !== 'user') return null;
|
|
1696
|
+
const email = p.principal.email;
|
|
1697
|
+
return (
|
|
1698
|
+
<Button variant="outline" size="sm" aria-label={`Invite ${email}`} onClick={() => invite.open({ emails: [email] })}>
|
|
1699
|
+
Invite
|
|
1700
|
+
</Button>
|
|
1701
|
+
);
|
|
1702
|
+
};
|
|
1703
|
+
|
|
1663
1704
|
// One grantee row. Direct rows get the inline verb editor and a Remove that
|
|
1664
1705
|
// revokes in place; inherited rows are read-only with a Remove that opens the
|
|
1665
1706
|
// cascade flow; external rows are read-only with no action.
|
|
@@ -1690,7 +1731,7 @@ export function ManageAccessDialog({
|
|
|
1690
1731
|
{/* Granted, but nobody has signed in as this address yet. Beside
|
|
1691
1732
|
the name, where the chip put it before the grant was saved —
|
|
1692
1733
|
and gone by itself once they do sign in. */}
|
|
1693
|
-
{p.kind === 'user' && p.hasAccount === false && <NoAccountNote />}
|
|
1734
|
+
{p.kind === 'user' && p.hasAccount === false && !noSso && <NoAccountNote />}
|
|
1694
1735
|
{p.kind !== 'user' && (
|
|
1695
1736
|
// The same chip vocabulary as the suggest menu's trailing tags:
|
|
1696
1737
|
// a role is a capability, a group is an audience — badge which.
|
|
@@ -1705,7 +1746,17 @@ export function ManageAccessDialog({
|
|
|
1705
1746
|
</Badge>
|
|
1706
1747
|
)}
|
|
1707
1748
|
</div>
|
|
1708
|
-
{p.
|
|
1749
|
+
{noSso && p.kind === 'user' && p.hasAccount === false ? (
|
|
1750
|
+
// Without single sign-on the reason takes the second line, readable
|
|
1751
|
+
// without hovering: it is why this person is not in yet. The address
|
|
1752
|
+
// a display name hides stays visible, so Invite's target is plain.
|
|
1753
|
+
<>
|
|
1754
|
+
<div className="text-detail italic text-ink-faint">{noAccountHelp}</div>
|
|
1755
|
+
{p.sub && <div className="truncate text-detail text-ink-muted">{p.sub}</div>}
|
|
1756
|
+
</>
|
|
1757
|
+
) : (
|
|
1758
|
+
p.sub && <div className="truncate text-detail text-ink-muted">{p.sub}</div>
|
|
1759
|
+
)}
|
|
1709
1760
|
</div>
|
|
1710
1761
|
{canManage ? (
|
|
1711
1762
|
// ONE set of controls for every row the caller can manage — direct,
|
|
@@ -1714,6 +1765,7 @@ export function ManageAccessDialog({
|
|
|
1714
1765
|
// thing the sheet could describe but not do; the menu below does it, by
|
|
1715
1766
|
// writing the restriction in the background.
|
|
1716
1767
|
<div className="ml-auto flex max-w-full shrink-0 items-center gap-2">
|
|
1768
|
+
{inviteAction(p)}
|
|
1717
1769
|
{p.manage === 'inherited' && (
|
|
1718
1770
|
// Leaf folder name only (full path on hover) — where the entries
|
|
1719
1771
|
// naming this principal live, when none of them is here.
|
|
@@ -1829,7 +1881,8 @@ export function ManageAccessDialog({
|
|
|
1829
1881
|
{removeSlot(p.manage === 'external' ? null : p)}
|
|
1830
1882
|
</div>
|
|
1831
1883
|
) : (
|
|
1832
|
-
<span className="ml-auto shrink-0 text-detail text-ink-muted">
|
|
1884
|
+
<span className="ml-auto flex shrink-0 items-center gap-2 text-detail text-ink-muted">
|
|
1885
|
+
{inviteAction(p)}
|
|
1833
1886
|
{summarizeVerbs(p.verbs)}
|
|
1834
1887
|
</span>
|
|
1835
1888
|
)}
|
|
@@ -1921,7 +1974,7 @@ export function ManageAccessDialog({
|
|
|
1921
1974
|
<span className="min-w-0 truncate" title={label}>
|
|
1922
1975
|
{label}
|
|
1923
1976
|
</span>
|
|
1924
|
-
{noAccount && <NoAccountNote />}
|
|
1977
|
+
{noAccount && <NoAccountNote help={noAccountHelp} />}
|
|
1925
1978
|
<button
|
|
1926
1979
|
type="button"
|
|
1927
1980
|
onClick={() => removeChip(c)}
|