@bevel-software/platform-core-frontend 0.26.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.
Files changed (206) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +87 -25
  3. package/src/core/ProductName.tsx +49 -0
  4. package/src/core/__tests__/ProductName.test.tsx +46 -0
  5. package/src/core/__tests__/ShellRoutes.test.tsx +22 -0
  6. package/src/core/__tests__/core-contributions.test.ts +16 -0
  7. package/src/core/core-contributions.ts +17 -0
  8. package/src/core/maker-url.ts +30 -0
  9. package/src/core/registry.ts +78 -1
  10. package/src/index.css +23 -5
  11. package/src/index.ts +5 -0
  12. package/src/lib/__tests__/latest-request.test.ts +48 -0
  13. package/src/lib/latest-request.ts +45 -0
  14. package/src/modules/access/__tests__/ManageAccessDialog.no-sso-invite.test.tsx +222 -0
  15. package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
  16. package/src/modules/access/api.ts +19 -3
  17. package/src/modules/access/components/ManageAccessDialog.tsx +61 -8
  18. package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +16 -1
  19. package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
  20. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +284 -39
  21. package/src/modules/admin/components/AdminRolesPage.tsx +13 -14
  22. package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
  23. package/src/modules/admin/components/UserAccountsPage.tsx +91 -107
  24. package/src/modules/admin/services/roles.api.ts +14 -1
  25. package/src/modules/auth/__tests__/LoginScreen.test.tsx +80 -5
  26. package/src/modules/auth/__tests__/sso-strict-probe.test.ts +66 -0
  27. package/src/modules/auth/components/LoginScreen.tsx +101 -73
  28. package/src/modules/auth/services/account.api.ts +59 -3
  29. package/src/modules/auth/services/sso.ts +30 -10
  30. package/src/modules/auth/state/use-sign-in-methods.ts +41 -0
  31. package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +176 -0
  32. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +68 -0
  33. package/src/modules/change-requests/__tests__/ChangeRequestLink.test.tsx +182 -0
  34. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +1 -1
  35. package/src/modules/change-requests/__tests__/readFileOnBranch.test.ts +79 -0
  36. package/src/modules/change-requests/components/ChangeBox.tsx +6 -1
  37. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +45 -15
  38. package/src/modules/change-requests/components/ChangeRequestLink.tsx +151 -0
  39. package/src/modules/change-requests/components/CrFileTree.tsx +2 -1
  40. package/src/modules/change-requests/components/FileChangeBoxes.tsx +4 -2
  41. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +6 -3
  42. package/src/modules/change-requests/services/change-requests.api.ts +15 -2
  43. package/src/modules/change-requests/utils/readFailure.ts +22 -0
  44. package/src/modules/embed/__tests__/EmbedLinkPage.test.tsx +74 -0
  45. package/src/modules/embed/__tests__/EmbedView.test.tsx +473 -0
  46. package/src/modules/embed/__tests__/embed-config.test.ts +128 -0
  47. package/src/modules/embed/__tests__/embed-host.test.ts +111 -0
  48. package/src/modules/embed/__tests__/mcp-app-view.test.ts +295 -0
  49. package/src/modules/embed/__tests__/mount.test.tsx +157 -0
  50. package/src/modules/embed/components/EmbedLinkPage.tsx +109 -0
  51. package/src/modules/embed/components/EmbedView.tsx +545 -0
  52. package/src/modules/embed/embed-config.ts +132 -0
  53. package/src/modules/embed/embed-host.ts +120 -0
  54. package/src/modules/embed/mount.tsx +80 -0
  55. package/src/modules/embed/services/embed-token.ts +22 -0
  56. package/src/modules/embed/services/embed.api.ts +158 -0
  57. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +202 -4
  58. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +59 -1
  59. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +39 -22
  60. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +7 -2
  61. package/src/modules/git/branch-delete-menu-item.tsx +24 -0
  62. package/src/modules/git/components/BranchSwitcher.tsx +29 -5
  63. package/src/modules/git/components/GitSyncFailedBanner.tsx +53 -15
  64. package/src/modules/git/components/HistoryVersionPreview.tsx +5 -3
  65. package/src/modules/git/components/PullNeededBanner.tsx +15 -49
  66. package/src/modules/git/hooks/useAutoPullUpdates.ts +9 -5
  67. package/src/modules/git/index.ts +15 -0
  68. package/src/modules/git/services/__tests__/error-messages.test.ts +67 -0
  69. package/src/modules/git/services/__tests__/pull-failure.test.ts +36 -0
  70. package/src/modules/git/services/error-messages.ts +58 -1
  71. package/src/modules/git/services/pull-failure.ts +68 -0
  72. package/src/modules/git/state/branch-delete-confirm.ts +46 -0
  73. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +1 -0
  74. package/src/modules/layout/__tests__/breakpoints.test.ts +7 -1
  75. package/src/modules/layout/breakpoints.ts +8 -0
  76. package/src/modules/library/__tests__/PluginExtras.test.tsx +9 -9
  77. package/src/modules/library/__tests__/PluginPage.test.tsx +8 -1
  78. package/src/modules/library/__tests__/SkillsTree.test.tsx +13 -4
  79. package/src/modules/library/components/LibraryPage.tsx +22 -0
  80. package/src/modules/library/components/PluginExtras.tsx +23 -6
  81. package/src/modules/library/components/PluginPage.tsx +6 -1
  82. package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
  83. package/src/modules/library/services/plugins.api.ts +4 -1
  84. package/src/modules/library/state/plugins-revision.ts +28 -0
  85. package/src/modules/onboarding/__tests__/InviteButton.test.tsx +214 -0
  86. package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
  87. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
  88. package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +164 -0
  89. package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1458 -0
  90. package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +811 -0
  91. package/src/modules/onboarding/__tests__/invite-emails.test.ts +247 -0
  92. package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
  93. package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
  94. package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
  95. package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
  96. package/src/modules/onboarding/components/GetStartedColumn.tsx +670 -0
  97. package/src/modules/onboarding/components/InviteButton.tsx +139 -0
  98. package/src/modules/onboarding/components/InviteDialog.tsx +741 -0
  99. package/src/modules/onboarding/components/RootLanding.tsx +8 -24
  100. package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
  101. package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
  102. package/src/modules/onboarding/first-page-prompt.ts +123 -0
  103. package/src/modules/onboarding/invite-emails.ts +313 -0
  104. package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
  105. package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
  106. package/src/modules/onboarding/state/agent-connection.ts +167 -0
  107. package/src/modules/onboarding/state/invite-dialog.context.ts +35 -0
  108. package/src/modules/onboarding/state/invite-dialog.tsx +39 -0
  109. package/src/modules/onboarding/state/onboarding.ts +133 -59
  110. package/src/modules/onboarding/state/starter-packs.ts +169 -0
  111. package/src/modules/settings/settings-nav-items.tsx +8 -3
  112. package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
  113. package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
  114. package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
  115. package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
  116. package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
  117. package/src/modules/setup/__tests__/setup.test.tsx +56 -15
  118. package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
  119. package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
  120. package/src/modules/setup/components/SetupGate.tsx +46 -1
  121. package/src/modules/setup/components/SetupScreen.tsx +81 -84
  122. package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
  123. package/src/modules/setup/services/setup.api.ts +3 -3
  124. package/src/modules/setup/utils/suggested-branch.ts +27 -0
  125. package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
  126. package/src/modules/toolbar/commands/actions.tsx +330 -0
  127. package/src/modules/toolbar/commands/command-menu.ts +44 -0
  128. package/src/modules/toolbar/commands/useCommandActions.ts +71 -0
  129. package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
  130. package/src/modules/toolbar/components/AppSwitcher.tsx +125 -22
  131. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
  132. package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
  133. package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
  134. package/src/modules/toolbar/components/Toolbar.tsx +10 -0
  135. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +230 -52
  136. package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
  137. package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +864 -0
  138. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
  139. package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
  140. package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
  141. package/src/modules/toolbar/search/rank.ts +111 -0
  142. package/src/modules/toolbar/search/sources.ts +169 -0
  143. package/src/modules/workflow/hooks/useFileLock.ts +10 -7
  144. package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
  145. package/src/modules/workflow/services/lock.api.ts +17 -2
  146. package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
  147. package/src/modules/workspace/components/EditorTabs.tsx +39 -15
  148. package/src/modules/workspace/components/FileExplorer.tsx +39 -6
  149. package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
  150. package/src/modules/workspace/components/FileRoute.tsx +12 -7
  151. package/src/modules/workspace/components/FileViewer.tsx +271 -74
  152. package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
  153. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
  154. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +92 -4
  155. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
  156. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
  157. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
  158. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
  159. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
  160. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
  161. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
  162. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
  163. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
  164. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
  165. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
  166. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
  167. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
  168. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
  169. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
  170. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
  171. package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
  172. package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
  173. package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
  174. package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
  175. package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
  176. package/src/modules/workspace/components/renderers/index.ts +26 -0
  177. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
  178. package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
  179. package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
  180. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
  181. package/src/modules/workspace/hooks/__tests__/useCreatePage.test.ts +137 -0
  182. package/src/modules/workspace/hooks/__tests__/useKnowledgeWriteTarget.test.ts +302 -0
  183. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
  184. package/src/modules/workspace/hooks/useCreatePage.ts +206 -0
  185. package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +238 -0
  186. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
  187. package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
  188. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
  189. package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
  190. package/src/modules/workspace/routing/kb-routes.ts +66 -12
  191. package/src/modules/workspace/state/editable-page.ts +42 -0
  192. package/src/modules/workspace/state/workspace.context.ts +13 -4
  193. package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
  194. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
  195. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +16 -0
  196. package/src/modules/workspace/utils/display-file-name.ts +102 -0
  197. package/src/modules/workspace/utils/fileTree.ts +49 -14
  198. package/src/modules/workspace/utils/treeConfirm.ts +15 -0
  199. package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
  200. package/src/shared/components/ConfirmProvider.tsx +156 -0
  201. package/src/shared/components/Dialog.tsx +7 -0
  202. package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
  203. package/src/shared/components/confirm-context.ts +94 -0
  204. package/src/shared/components/index.ts +3 -0
  205. package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
  206. package/src/modules/onboarding/welcome-state.ts +0 -36
@@ -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
+ });
@@ -38,7 +38,7 @@ const ENTRY: FileTreeEntry = {
38
38
  const BRANCH = 'suggestions/me/knowledge';
39
39
  const BRANCH_WS = encodeURIComponent(BRANCH);
40
40
  const PROPOSAL = { number: 12, branch: BRANCH };
41
- const NOTICE = /editing access on change request #12\. It takes effect when the request merges/i;
41
+ const NOTICE = /editing access on change request #12\. It takes effect when the request is published/i;
42
42
  const A = { name: 'Alice', email: 'alice@x.com' };
43
43
 
44
44
  /** Alice, granted `write` directly on the file. */
@@ -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, or `owner` — membership in an `owner:` grant, which
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={NO_ACCOUNT_HELP}
353
- aria-description={NO_ACCOUNT_HELP}
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.sub && <div className="truncate text-detail text-ink-muted">{p.sub}</div>}
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
  )}
@@ -1870,7 +1923,7 @@ export function ManageAccessDialog({
1870
1923
 
1871
1924
  {proposal && (
1872
1925
  <Banner tone="neutral" role="status" className="mt-3">
1873
- {`You're editing access on change request #${proposal.number}. It takes effect when the request merges.`}
1926
+ {`You're editing access on change request #${proposal.number}. It takes effect when the request is published.`}
1874
1927
  </Banner>
1875
1928
  )}
1876
1929
 
@@ -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)}
@@ -32,7 +32,7 @@ vi.mock('../../access/api', async (importOriginal) => {
32
32
  import { suggestPrincipals } from '../../access/api';
33
33
 
34
34
  const OWNER = 'owner@bevel.software';
35
- const NOTE = 'Deployment admin, set in the server configuration; cannot be removed here';
35
+ const NOTE = 'Owner; cannot be removed here';
36
36
 
37
37
  /** Admin as the backend now reports it: a fixed member plus editable ones. */
38
38
  function adminRole(over: Partial<RoleRosterEntry> = {}): RoleRosterEntry {
@@ -41,6 +41,7 @@ function adminRole(over: Partial<RoleRosterEntry> = {}): RoleRosterEntry {
41
41
  displayName: 'Admin',
42
42
  members: ['razvan@bevel.software'],
43
43
  fixedMembers: [OWNER],
44
+ fixedMembersNote: NOTE,
44
45
  groups: [],
45
46
  capability: { description: 'Full administrative access.', groupAssignable: true },
46
47
  isAdmin: true,
@@ -54,6 +55,7 @@ const SALES: RoleRosterEntry = {
54
55
  displayName: 'Sales',
55
56
  members: ['felix@example.com'],
56
57
  fixedMembers: [],
58
+ fixedMembersNote: null,
57
59
  groups: [],
58
60
  capability: null,
59
61
  isAdmin: false,
@@ -177,6 +179,19 @@ describe('AdminRolesPage: the deployment admin is a fixed Admin member', () => {
177
179
  expect(card.getByRole('button', { name: 'Remove felix@example.com' })).toBeInTheDocument();
178
180
  });
179
181
 
182
+ it('prints the note the server sends, not a copy of its own', async () => {
183
+ // The wording lives on the server; a reworded note shows up here as sent.
184
+ const reworded = 'Server-held owner';
185
+ vi.mocked(fetchRoles).mockResolvedValue([adminRole({ fixedMembersNote: reworded }), SALES]);
186
+ renderPage();
187
+ const card = within(await findCard('Admin'));
188
+ expect(card.getByText(`${reworded}.`)).toBeInTheDocument();
189
+ expect(card.queryByText(`${NOTE}.`)).not.toBeInTheDocument();
190
+ await userEvent.type(card.getByRole('combobox', { name: 'Member email' }), OWNER);
191
+ await userEvent.keyboard('{Enter}');
192
+ expect(await card.findByText(`${reworded}. ${OWNER} is already an Admin.`)).toBeInTheDocument();
193
+ });
194
+
180
195
  it('degrades to today’s behaviour when the backend omits fixedMembers', async () => {
181
196
  const legacyShape = { ...adminRole() } as Partial<RoleRosterEntry>;
182
197
  delete legacyShape.fixedMembers;
@@ -0,0 +1,70 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi, type MockInstance } from 'vitest';
2
+ import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
3
+ import { AdminContext } from '../state/admin.context';
4
+ import { RolesCorruptedBanner } from '../components/RolesCorruptedBanner';
5
+ import { ConfirmProvider } from '../../../shared/components';
6
+
7
+ /**
8
+ * Bevel Recovery asks before it runs — in the app's own dialog, which the
9
+ * browser cannot silence — with today's text.
10
+ */
11
+
12
+ const QUESTION =
13
+ 'Bevel Recovery will back up the corrupted roles.yaml to old-roles.yaml and ' +
14
+ 'restore the default Bevel roster. Only continue if you are from Bevel. Proceed?';
15
+
16
+ let confirmSpy: MockInstance<Window['confirm']>;
17
+ let reload: ReturnType<typeof vi.fn>;
18
+ beforeEach(() => {
19
+ confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(false);
20
+ reload = vi.fn();
21
+ vi.spyOn(window, 'location', 'get').mockReturnValue({ ...window.location, reload } as Location);
22
+ });
23
+ afterEach(() => {
24
+ expect(confirmSpy).not.toHaveBeenCalled();
25
+ vi.restoreAllMocks();
26
+ });
27
+
28
+ function renderBanner() {
29
+ const runRolesRecovery = vi.fn(async () => {});
30
+ render(
31
+ <ConfirmProvider>
32
+ <AdminContext.Provider
33
+ value={{
34
+ isAdmin: true,
35
+ isAdminLoading: false,
36
+ unreadCount: 0,
37
+ lastSeen: null,
38
+ markSeen: () => {},
39
+ refresh: () => {},
40
+ rolesConfigCorrupted: true,
41
+ rolesConfigErrors: ['bad indent'],
42
+ runRolesRecovery,
43
+ } as never}
44
+ >
45
+ <RolesCorruptedBanner />
46
+ </AdminContext.Provider>
47
+ </ConfirmProvider>,
48
+ );
49
+ fireEvent.click(screen.getByRole('button', { name: /Bevel Recovery/ }));
50
+ return runRolesRecovery;
51
+ }
52
+
53
+ describe('roles recovery', () => {
54
+ it("asks with today's text; Cancel runs nothing", async () => {
55
+ const run = renderBanner();
56
+ const dialog = await screen.findByRole('dialog');
57
+ expect(dialog.textContent).toContain(QUESTION);
58
+ expect(within(dialog).queryByText("Don't ask again")).toBeNull();
59
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Cancel' }));
60
+ await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
61
+ expect(run).not.toHaveBeenCalled();
62
+ });
63
+
64
+ it('Proceed runs the recovery, with the browser\'s dialogs suppressed', async () => {
65
+ const run = renderBanner();
66
+ fireEvent.click(within(await screen.findByRole('dialog')).getByRole('button', { name: 'Proceed' }));
67
+ await waitFor(() => expect(run).toHaveBeenCalledTimes(1));
68
+ await waitFor(() => expect(reload).toHaveBeenCalled());
69
+ });
70
+ });