@bevel-software/platform-core-frontend 0.22.0 → 0.23.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/CoreAppShell.tsx +2 -0
- package/src/core/registry.ts +83 -0
- package/src/lib/api.ts +49 -0
- package/src/modules/access/api.ts +6 -4
- package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +89 -1
- package/src/modules/admin/components/UserAccountsPage.tsx +93 -5
- package/src/modules/auth/components/LoginScreen.tsx +3 -0
- package/src/modules/auth/services/account.api.ts +26 -3
- package/src/modules/change-requests/components/BranchFilePreview.tsx +7 -1
- package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +89 -10
- package/src/modules/git/__tests__/HistoryVersionPreview.test.tsx +479 -0
- package/src/modules/git/components/FileHistoryPanel.tsx +52 -65
- package/src/modules/git/components/HistoryVersionPreview.tsx +410 -0
- package/src/modules/layout/__tests__/ReadOnlyBanner.test.tsx +157 -0
- package/src/modules/layout/components/ReadOnlyBanner.tsx +96 -0
- package/src/modules/setup/__tests__/setup.repository-change.test.tsx +296 -0
- package/src/modules/setup/__tests__/setup.repository.test.tsx +114 -24
- package/src/modules/setup/__tests__/setup.test.tsx +5 -3
- package/src/modules/setup/components/SetupScreen.tsx +187 -46
- package/src/modules/setup/services/setup.api.ts +78 -3
- package/src/modules/workspace/components/FileExplorer.tsx +140 -12
- package/src/modules/workspace/components/FileViewer.tsx +11 -1
- package/src/modules/workspace/components/TreeActionConfirm.tsx +5 -7
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +603 -29
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +23 -6
- package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +41 -8
- package/src/modules/workspace/components/renderers/EmailRenderer.tsx +20 -5
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +39 -16
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +27 -7
- package/src/modules/workspace/components/renderers/PptxRenderer.tsx +20 -5
- package/src/modules/workspace/components/renderers/RetryReadButton.tsx +37 -0
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +20 -5
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +186 -7
- package/src/modules/workspace/components/renderers/__tests__/readPane.test.tsx +59 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +80 -20
- package/src/modules/workspace/components/renderers/index.ts +6 -1
- package/src/modules/workspace/components/renderers/readPane.ts +22 -0
- package/src/modules/workspace/components/renderers/rendererWorkspace.ts +50 -9
- package/src/modules/workspace/components/renderers/useReadRetry.ts +27 -0
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +79 -0
- package/src/modules/workspace/routing/kb-routes.ts +25 -10
- package/src/modules/workspace/services/workspace.api.ts +22 -1
- package/src/shared/markdown/__tests__/hrefs.test.ts +111 -0
- package/src/shared/markdown/hrefs.ts +80 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bevel-software/platform-core-frontend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.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.23.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@testing-library/jest-dom": "^6.9.1",
|
|
@@ -23,6 +23,7 @@ import { EventBusFocusBinder } from '../modules/workflow/state/EventBusFocusBind
|
|
|
23
23
|
import { ChangeRequestStaleBinder } from '../modules/workflow/state/ChangeRequestStaleBinder';
|
|
24
24
|
import { Toolbar } from '../modules/toolbar/components/Toolbar';
|
|
25
25
|
import { DemoBanner } from '../modules/layout/components/DemoBanner';
|
|
26
|
+
import { ReadOnlyBanner } from '../modules/layout/components/ReadOnlyBanner';
|
|
26
27
|
import { FileExplorer } from '../modules/workspace/components/FileExplorer';
|
|
27
28
|
import { FileViewer } from '../modules/workspace/components/FileViewer';
|
|
28
29
|
import { OpenChangeRequestsProvider } from '../modules/workspace/state/open-change-requests';
|
|
@@ -175,6 +176,7 @@ function AuthenticatedAppInner() {
|
|
|
175
176
|
// and its onboarding-import banner after these.
|
|
176
177
|
const CORE_BANNERS: BannerDef[] = [
|
|
177
178
|
{ id: 'demo', order: 20, node: <DemoBanner /> },
|
|
179
|
+
{ id: 'read-only', order: 25, node: <ReadOnlyBanner /> },
|
|
178
180
|
{ id: 'roles-corrupted', order: 30, node: <RolesCorruptedBanner /> },
|
|
179
181
|
];
|
|
180
182
|
|
package/src/core/registry.ts
CHANGED
|
@@ -145,6 +145,83 @@ export interface ExplorerItemDef {
|
|
|
145
145
|
Component: ComponentType<{ tree: FileTreeEntry | null }>;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
/**
|
|
149
|
+
* The folder a right-click menu was opened on, as the entry is told about it.
|
|
150
|
+
*
|
|
151
|
+
* Everything here is what the explorer ALREADY knows when it draws the menu;
|
|
152
|
+
* nothing new is asked of the server on an entry's behalf, and nothing here is
|
|
153
|
+
* a gate. `canWrite` and `branchProtected` are for deciding whether to OFFER a
|
|
154
|
+
* verb — the routes an entry's action goes through decide whether to allow it,
|
|
155
|
+
* exactly as they do for "New folder".
|
|
156
|
+
*/
|
|
157
|
+
export interface FolderMenuContext {
|
|
158
|
+
/** Workspace-relative path of the folder, e.g. `knowledge-base/Data`. */
|
|
159
|
+
path: string;
|
|
160
|
+
/**
|
|
161
|
+
* The branch the explorer's rows came from — the branch the workspace IS,
|
|
162
|
+
* never the one a route may be navigating to. Empty only before the
|
|
163
|
+
* workspace has bootstrapped, which is before there is a row to right-click.
|
|
164
|
+
*/
|
|
165
|
+
branch: string;
|
|
166
|
+
/**
|
|
167
|
+
* Whether the viewer may write into this folder — the same answer the
|
|
168
|
+
* explorer's own write hints read, and `false` while it is still unknown.
|
|
169
|
+
*/
|
|
170
|
+
canWrite: boolean;
|
|
171
|
+
/** Whether {@link branch} is one of the deployment's protected branches. */
|
|
172
|
+
branchProtected: boolean;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* What a folder menu entry's action may do: the operations Hexis's own entries
|
|
177
|
+
* use, and only those. An entry creates nothing itself — it asks through here,
|
|
178
|
+
* so whatever it creates travels the same routes "New file" and "New folder"
|
|
179
|
+
* travel, and the access rules, the platform-file rules and the
|
|
180
|
+
* protected-branch rules apply to it unchanged.
|
|
181
|
+
*
|
|
182
|
+
* `createFolder` and `createFile` REJECT when the route refuses; an entry that
|
|
183
|
+
* lets the rejection through has its message shown the way a refused "New
|
|
184
|
+
* folder" shows one, so handling it is optional rather than the entry's
|
|
185
|
+
* problem. Paths are workspace-relative, as {@link FolderMenuContext.path} is.
|
|
186
|
+
*/
|
|
187
|
+
export interface FolderMenuTools {
|
|
188
|
+
createFolder: (path: string) => Promise<void>;
|
|
189
|
+
createFile: (path: string, content?: string) => Promise<void>;
|
|
190
|
+
/** Re-read the file tree, so what was created shows up in it. */
|
|
191
|
+
refreshTree: () => Promise<void>;
|
|
192
|
+
/** Open a path in the surface this tree belongs to. */
|
|
193
|
+
openPath: (path: string) => void;
|
|
194
|
+
/** Show a failure the way the explorer shows its own. */
|
|
195
|
+
showError: (message: string) => void;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* An entry a DEPLOYMENT adds to a folder's right-click menu in the explorer.
|
|
200
|
+
*
|
|
201
|
+
* Core registers none. The explorer and its menus are core's, but a verb like
|
|
202
|
+
* "New ontology" belongs to the distribution that has ontologies, so core
|
|
203
|
+
* offers the place rather than the entry.
|
|
204
|
+
*
|
|
205
|
+
* Registered entries are drawn after core's own, behind a separator, in the
|
|
206
|
+
* order registered — a deployment's verbs read as additions rather than as
|
|
207
|
+
* part of the tree's own vocabulary. With none registered there is no
|
|
208
|
+
* separator and the menu is exactly as it was.
|
|
209
|
+
*
|
|
210
|
+
* `appliesTo` is called every time a folder's menu opens, so keep it cheap and
|
|
211
|
+
* synchronous; one that throws leaves its entry out of that menu and is
|
|
212
|
+
* logged, and the rest of the menu is unaffected.
|
|
213
|
+
*/
|
|
214
|
+
export interface FolderMenuItemDef {
|
|
215
|
+
/** Stable, and unique among registered entries — it keys the rendered row. */
|
|
216
|
+
id: string;
|
|
217
|
+
label: string;
|
|
218
|
+
icon?: ReactNode;
|
|
219
|
+
/** Whether this entry belongs in THIS folder's menu. */
|
|
220
|
+
appliesTo: (folder: FolderMenuContext) => boolean;
|
|
221
|
+
/** What the entry does. A rejection's message is shown as an error. */
|
|
222
|
+
run: (folder: FolderMenuContext, tools: FolderMenuTools) => void | Promise<void>;
|
|
223
|
+
}
|
|
224
|
+
|
|
148
225
|
/**
|
|
149
226
|
* A way to sign in that the distribution runs for every deployment it hosts,
|
|
150
227
|
* shown in the "Single sign-on" section as a tab of its own, ahead of the
|
|
@@ -337,6 +414,11 @@ export interface AppRegistry {
|
|
|
337
414
|
renderers: FileRendererDef[];
|
|
338
415
|
/** Extra rows in the explorer's Pinned section (see {@link ExplorerItemDef}). */
|
|
339
416
|
explorerItems: ExplorerItemDef[];
|
|
417
|
+
/**
|
|
418
|
+
* Extra entries in a FOLDER's right-click menu in the explorer, drawn after
|
|
419
|
+
* core's own behind a separator (see {@link FolderMenuItemDef}).
|
|
420
|
+
*/
|
|
421
|
+
folderMenuItems: FolderMenuItemDef[];
|
|
340
422
|
/**
|
|
341
423
|
* The Groups settings page's directory-connection panel. Core's Groups
|
|
342
424
|
* page manages MANUAL groups and renders the IdP-synced roster read-only;
|
|
@@ -423,6 +505,7 @@ export const EMPTY_REGISTRY: AppRegistry = {
|
|
|
423
505
|
fileViewerPanels: [],
|
|
424
506
|
renderers: [],
|
|
425
507
|
explorerItems: [],
|
|
508
|
+
folderMenuItems: [],
|
|
426
509
|
apps: [],
|
|
427
510
|
toolbarItems: [],
|
|
428
511
|
};
|
package/src/lib/api.ts
CHANGED
|
@@ -13,6 +13,53 @@ export const API_UNREACHABLE_EVENT = 'bevel:api-unreachable';
|
|
|
13
13
|
|
|
14
14
|
const PROXY_DOWN_STATUSES = new Set([502, 503, 504]);
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Window event dispatched when the server refused a change because the
|
|
18
|
+
* deployment is read-only (a 403 whose body carries `workspace_read_only`).
|
|
19
|
+
* The read-only banner listens for it and asks the server what to say, so
|
|
20
|
+
* the app learns of the state from the first refusal instead of asking on a
|
|
21
|
+
* timer.
|
|
22
|
+
*/
|
|
23
|
+
export const WRITE_REFUSED_EVENT = 'bevel:write-refused';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Window event dispatched when a change went through. While the read-only
|
|
27
|
+
* banner is up it asks again on this: switching accounts off is how an admin
|
|
28
|
+
* ends the state, and those requests succeed.
|
|
29
|
+
*/
|
|
30
|
+
export const WRITE_ACCEPTED_EVENT = 'bevel:write-accepted';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The server's `READ_ONLY_CODE`, as `modules/write-access/write-access.ts`
|
|
34
|
+
* in core-backend exports it. The two must stay the same string: this is
|
|
35
|
+
* what the banner recognises a refusal by.
|
|
36
|
+
*/
|
|
37
|
+
const READ_ONLY_CODE = 'workspace_read_only';
|
|
38
|
+
const READING_METHODS = new Set(['GET', 'HEAD', 'OPTIONS']);
|
|
39
|
+
|
|
40
|
+
function methodOf(input: RequestInfo | URL, init: RequestInit | undefined): string {
|
|
41
|
+
const fromRequest = typeof input === 'object' && 'method' in input ? (input as Request).method : undefined;
|
|
42
|
+
return (init?.method ?? fromRequest ?? 'GET').toUpperCase();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Tell the banner what a mutating request's answer says about the deployment. Never throws, never delays the caller. */
|
|
46
|
+
function signalWriteAccess(input: RequestInfo | URL, init: RequestInit | undefined, response: Response): void {
|
|
47
|
+
if (READING_METHODS.has(methodOf(input, init))) return;
|
|
48
|
+
if (response.ok) {
|
|
49
|
+
window.dispatchEvent(new Event(WRITE_ACCEPTED_EVENT));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (response.status !== 403) return;
|
|
53
|
+
// A copy is read, so the caller still has the body to itself.
|
|
54
|
+
void response
|
|
55
|
+
.clone()
|
|
56
|
+
.json()
|
|
57
|
+
.then((body: { code?: unknown } | null) => {
|
|
58
|
+
if (body?.code === READ_ONLY_CODE) window.dispatchEvent(new Event(WRITE_REFUSED_EVENT));
|
|
59
|
+
})
|
|
60
|
+
.catch(() => undefined);
|
|
61
|
+
}
|
|
62
|
+
|
|
16
63
|
function signalUnreachable(): void {
|
|
17
64
|
window.dispatchEvent(new Event(API_UNREACHABLE_EVENT));
|
|
18
65
|
}
|
|
@@ -98,5 +145,7 @@ export async function authFetch(
|
|
|
98
145
|
clearToken();
|
|
99
146
|
}
|
|
100
147
|
|
|
148
|
+
signalWriteAccess(input, init, response);
|
|
149
|
+
|
|
101
150
|
return response;
|
|
102
151
|
}
|
|
@@ -392,7 +392,7 @@ export interface PathPrincipals {
|
|
|
392
392
|
write: AccessPrincipalRef[];
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
-
/** One file's holders where it is now and where a move would put it. */
|
|
395
|
+
/** One file's or folder's holders where it is now and where a move would put it. */
|
|
396
396
|
export interface ProspectiveAccess {
|
|
397
397
|
before: PathPrincipals;
|
|
398
398
|
after: PathPrincipals;
|
|
@@ -400,9 +400,11 @@ export interface ProspectiveAccess {
|
|
|
400
400
|
|
|
401
401
|
/**
|
|
402
402
|
* Resolve who holds read and write on `relativePath` today and who would hold
|
|
403
|
-
* them once
|
|
404
|
-
* file's own frontmatter
|
|
405
|
-
*
|
|
403
|
+
* them once it sits in `toDir` — the destination's folder rules with what the
|
|
404
|
+
* move carries layered on top: a file's own frontmatter, or the `access.md`
|
|
405
|
+
* files inside a folder, counted at the paths they land on. Both paths are
|
|
406
|
+
* repo-relative (`Knowledge/Foo.md`, `Knowledge/Sales`); `toDir` is `''` for
|
|
407
|
+
* the repo root.
|
|
406
408
|
*
|
|
407
409
|
* `signal` lets the move dialog give up on it: the answer decorates the
|
|
408
410
|
* confirmation and must never hold it open.
|
|
@@ -6,15 +6,19 @@ import { AdminContext } from '../state/admin.context';
|
|
|
6
6
|
import { AuthContext, type AuthContextValue } from '../../auth/state/auth.context';
|
|
7
7
|
import {
|
|
8
8
|
createAccount,
|
|
9
|
+
deactivateAccount,
|
|
9
10
|
deleteAccount,
|
|
10
11
|
getAccountReferences,
|
|
11
12
|
listAccounts,
|
|
13
|
+
reactivateAccount,
|
|
12
14
|
type AccountReferences,
|
|
13
15
|
} from '../../auth/services/account.api';
|
|
14
16
|
|
|
15
17
|
vi.mock('../../auth/services/account.api', () => ({
|
|
16
18
|
createAccount: vi.fn(),
|
|
19
|
+
deactivateAccount: vi.fn(),
|
|
17
20
|
deleteAccount: vi.fn(),
|
|
21
|
+
reactivateAccount: vi.fn(),
|
|
18
22
|
getAccountReferences: vi.fn(),
|
|
19
23
|
listAccounts: vi.fn(),
|
|
20
24
|
}));
|
|
@@ -39,6 +43,8 @@ const ALICE = {
|
|
|
39
43
|
hasPassword: false,
|
|
40
44
|
isEnvAdmin: false,
|
|
41
45
|
createdAt: '2026-01-01T00:00:00Z',
|
|
46
|
+
deactivatedAt: null,
|
|
47
|
+
isSystem: false,
|
|
42
48
|
};
|
|
43
49
|
const BOB = {
|
|
44
50
|
id: 'u-bob',
|
|
@@ -47,6 +53,8 @@ const BOB = {
|
|
|
47
53
|
hasPassword: true,
|
|
48
54
|
isEnvAdmin: false,
|
|
49
55
|
createdAt: '2026-01-01T00:00:00Z',
|
|
56
|
+
deactivatedAt: null,
|
|
57
|
+
isSystem: false,
|
|
50
58
|
};
|
|
51
59
|
// The deployment admin (ADMIN_EMAIL) — a different account from the signed-in
|
|
52
60
|
// admin, so its row offers the actions. No hash stored yet.
|
|
@@ -57,6 +65,8 @@ const ROOT = {
|
|
|
57
65
|
hasPassword: false,
|
|
58
66
|
isEnvAdmin: true,
|
|
59
67
|
createdAt: '2026-01-01T00:00:00Z',
|
|
68
|
+
deactivatedAt: null,
|
|
69
|
+
isSystem: false,
|
|
60
70
|
};
|
|
61
71
|
|
|
62
72
|
/** The "email · Joined … · sign-in method" line of the named account's row. */
|
|
@@ -98,12 +108,14 @@ beforeEach(() => {
|
|
|
98
108
|
vi.mocked(listAccounts)
|
|
99
109
|
.mockReset()
|
|
100
110
|
.mockResolvedValue([
|
|
101
|
-
{ ...ME, hasPassword: true, isEnvAdmin: false, createdAt: '2026-01-01T00:00:00Z' },
|
|
111
|
+
{ ...ME, hasPassword: true, isEnvAdmin: false, createdAt: '2026-01-01T00:00:00Z', deactivatedAt: null, isSystem: false },
|
|
102
112
|
ALICE,
|
|
103
113
|
]);
|
|
104
114
|
vi.mocked(deleteAccount).mockReset().mockResolvedValue(null);
|
|
105
115
|
vi.mocked(getAccountReferences).mockReset().mockResolvedValue(REFS);
|
|
106
116
|
vi.mocked(createAccount).mockReset().mockResolvedValue(undefined);
|
|
117
|
+
vi.mocked(deactivateAccount).mockReset().mockResolvedValue(undefined);
|
|
118
|
+
vi.mocked(reactivateAccount).mockReset().mockResolvedValue(undefined);
|
|
107
119
|
});
|
|
108
120
|
|
|
109
121
|
describe('UserAccountsPage', () => {
|
|
@@ -567,3 +579,79 @@ describe('UserAccountsPage', () => {
|
|
|
567
579
|
expect(screen.queryByText('Loading…')).not.toBeInTheDocument();
|
|
568
580
|
});
|
|
569
581
|
});
|
|
582
|
+
|
|
583
|
+
describe('UserAccountsPage — switching accounts off and on', () => {
|
|
584
|
+
it('asks before switching another account off, then shows it off; offers no switch for your own', async () => {
|
|
585
|
+
const user = userEvent.setup();
|
|
586
|
+
vi.mocked(listAccounts)
|
|
587
|
+
.mockResolvedValueOnce([ALICE])
|
|
588
|
+
.mockResolvedValueOnce([{ ...ALICE, deactivatedAt: '2026-09-01T00:00:00Z' }]);
|
|
589
|
+
renderPage();
|
|
590
|
+
await waitFor(() => expect(screen.getByText('Alice')).toBeInTheDocument());
|
|
591
|
+
expect(screen.queryByRole('button', { name: 'Switch off admin@example.com' })).not.toBeInTheDocument();
|
|
592
|
+
await user.click(screen.getByRole('button', { name: 'Switch off alice@example.com' }));
|
|
593
|
+
// Nothing happens until it is confirmed.
|
|
594
|
+
expect(deactivateAccount).not.toHaveBeenCalled();
|
|
595
|
+
const dialog = screen.getByRole('dialog');
|
|
596
|
+
expect(dialog).toHaveTextContent('Nothing is deleted');
|
|
597
|
+
await user.click(within(dialog).getByRole('button', { name: 'Switch off' }));
|
|
598
|
+
expect(deactivateAccount).toHaveBeenCalledWith('u-alice');
|
|
599
|
+
// The refreshed list shows it off, and offers to switch it on.
|
|
600
|
+
expect(await screen.findByText('(switched off)')).toBeInTheDocument();
|
|
601
|
+
expect(screen.getByRole('button', { name: 'Switch on alice@example.com' })).toBeInTheDocument();
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
it('switches nothing off when the confirmation is cancelled', async () => {
|
|
605
|
+
const user = userEvent.setup();
|
|
606
|
+
vi.mocked(listAccounts).mockResolvedValue([ALICE]);
|
|
607
|
+
renderPage();
|
|
608
|
+
await user.click(await screen.findByRole('button', { name: 'Switch off alice@example.com' }));
|
|
609
|
+
await user.click(within(screen.getByRole('dialog')).getByRole('button', { name: 'Cancel' }));
|
|
610
|
+
expect(deactivateAccount).not.toHaveBeenCalled();
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
it('marks a switched-off account and switches it back on, then shows it on', async () => {
|
|
614
|
+
const user = userEvent.setup();
|
|
615
|
+
vi.mocked(listAccounts)
|
|
616
|
+
.mockResolvedValueOnce([{ ...ALICE, deactivatedAt: '2026-09-01T00:00:00Z' }])
|
|
617
|
+
.mockResolvedValueOnce([ALICE]);
|
|
618
|
+
renderPage();
|
|
619
|
+
await waitFor(() => expect(screen.getByText('(switched off)')).toBeInTheDocument());
|
|
620
|
+
await user.click(screen.getByRole('button', { name: 'Switch on alice@example.com' }));
|
|
621
|
+
expect(reactivateAccount).toHaveBeenCalledWith('u-alice');
|
|
622
|
+
expect(await screen.findByRole('button', { name: 'Switch off alice@example.com' })).toBeInTheDocument();
|
|
623
|
+
expect(screen.queryByText('(switched off)')).not.toBeInTheDocument();
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
it('offers no switch on an account the platform runs its own work as', async () => {
|
|
627
|
+
vi.mocked(listAccounts).mockResolvedValue([{ ...ALICE, id: 'u-bot', email: 'recovery-bot@bevel.local', name: 'Recovery Bot', isSystem: true }]);
|
|
628
|
+
renderPage();
|
|
629
|
+
await waitFor(() => expect(screen.getByText('Recovery Bot')).toBeInTheDocument());
|
|
630
|
+
expect(screen.queryByRole('button', { name: 'Switch off recovery-bot@bevel.local' })).not.toBeInTheDocument();
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
it("shows the deployment's reason when there is no room to switch one on", async () => {
|
|
634
|
+
const user = userEvent.setup();
|
|
635
|
+
vi.mocked(listAccounts).mockResolvedValue([{ ...ALICE, deactivatedAt: '2026-09-01T00:00:00Z' }]);
|
|
636
|
+
vi.mocked(reactivateAccount).mockRejectedValue(new Error('All 3 seats are taken'));
|
|
637
|
+
renderPage();
|
|
638
|
+
await user.click(await screen.findByRole('button', { name: 'Switch on alice@example.com' }));
|
|
639
|
+
expect(await screen.findByText('All 3 seats are taken')).toBeInTheDocument();
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
it('offers no switch on the deployment admin, whose environment password is the way back in', async () => {
|
|
643
|
+
vi.mocked(listAccounts).mockResolvedValue([ROOT]);
|
|
644
|
+
renderPage();
|
|
645
|
+
await waitFor(() => expect(screen.getByText('Root')).toBeInTheDocument());
|
|
646
|
+
expect(screen.queryByRole('button', { name: 'Switch off root@example.com' })).not.toBeInTheDocument();
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
it('adds an account without a password, for single sign-on', async () => {
|
|
650
|
+
const user = userEvent.setup();
|
|
651
|
+
renderPage();
|
|
652
|
+
await waitFor(() => expect(screen.getByText('Alice')).toBeInTheDocument());
|
|
653
|
+
await user.type(screen.getByLabelText('Email'), 'new@example.com');
|
|
654
|
+
await user.click(screen.getByRole('button', { name: 'Add account' }));
|
|
655
|
+
expect(createAccount).toHaveBeenCalledWith('new@example.com', '', '');
|
|
656
|
+
});
|
|
657
|
+
});
|
|
@@ -5,9 +5,11 @@ import { useAdmin } from '../state/admin.context';
|
|
|
5
5
|
import { useAuth } from '../../auth/state/auth.context';
|
|
6
6
|
import {
|
|
7
7
|
createAccount,
|
|
8
|
+
deactivateAccount,
|
|
8
9
|
deleteAccount,
|
|
9
10
|
getAccountReferences,
|
|
10
11
|
listAccounts,
|
|
12
|
+
reactivateAccount,
|
|
11
13
|
type AccountReferences,
|
|
12
14
|
type AccountSummary,
|
|
13
15
|
} from '../../auth/services/account.api';
|
|
@@ -155,9 +157,13 @@ export function UserAccountsPage() {
|
|
|
155
157
|
const [addPassword, setAddPassword] = useState('');
|
|
156
158
|
const [addError, setAddError] = useState<string | null>(null);
|
|
157
159
|
const [adding, setAdding] = useState(false);
|
|
160
|
+
// The account being switched off or on, while the request and the refresh after it are in flight.
|
|
161
|
+
const [switching, setSwitching] = useState<string | null>(null);
|
|
162
|
+
// The account awaiting confirmation before it is switched off; non-null drives that Dialog.
|
|
163
|
+
const [pendingDeactivate, setPendingDeactivate] = useState<AccountSummary | null>(null);
|
|
158
164
|
|
|
159
165
|
const refresh = useCallback(() => {
|
|
160
|
-
listAccounts()
|
|
166
|
+
return listAccounts()
|
|
161
167
|
.then((rows) => {
|
|
162
168
|
setAccounts(rows);
|
|
163
169
|
setError(null);
|
|
@@ -266,6 +272,24 @@ export function UserAccountsPage() {
|
|
|
266
272
|
}
|
|
267
273
|
}
|
|
268
274
|
|
|
275
|
+
async function toggleActive(account: AccountSummary) {
|
|
276
|
+
if (switching) return;
|
|
277
|
+
setSwitching(account.id);
|
|
278
|
+
setError(null);
|
|
279
|
+
try {
|
|
280
|
+
if (account.deactivatedAt) await reactivateAccount(account.id);
|
|
281
|
+
else await deactivateAccount(account.id);
|
|
282
|
+
// Busy until the list shows the new state, so a second click cannot
|
|
283
|
+
// ask for the same change again from the old one.
|
|
284
|
+
await refresh();
|
|
285
|
+
} catch (err) {
|
|
286
|
+
setError(err instanceof Error ? err.message : "Couldn't change this account.");
|
|
287
|
+
} finally {
|
|
288
|
+
setSwitching(null);
|
|
289
|
+
setPendingDeactivate(null);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
269
293
|
async function handleAdd(e: FormEvent<HTMLFormElement>) {
|
|
270
294
|
e.preventDefault();
|
|
271
295
|
if (adding) return;
|
|
@@ -308,9 +332,11 @@ export function UserAccountsPage() {
|
|
|
308
332
|
<p className="text-xs text-ink-muted leading-snug">
|
|
309
333
|
Everyone with an account on this deployment. Deleting an account permanently removes
|
|
310
334
|
the person's data and anonymizes their past review activity; their saves in the
|
|
311
|
-
knowledge base keep their history.
|
|
312
|
-
|
|
313
|
-
|
|
335
|
+
knowledge base keep their history. Switching an account off keeps all of that but
|
|
336
|
+
stops them signing in, and their keys and agent connections stop working until it is
|
|
337
|
+
switched back on. Setting a password lets someone sign in with email + password
|
|
338
|
+
(existing accounts keep everything else); resetting one replaces the password they
|
|
339
|
+
have now.
|
|
314
340
|
</p>
|
|
315
341
|
|
|
316
342
|
{error && (
|
|
@@ -366,6 +392,9 @@ export function UserAccountsPage() {
|
|
|
366
392
|
{isSelf && (
|
|
367
393
|
<span className="ml-1.5 text-meta font-normal text-ink-muted">(you)</span>
|
|
368
394
|
)}
|
|
395
|
+
{account.deactivatedAt && (
|
|
396
|
+
<span className="ml-1.5 text-meta font-normal text-ink-muted">(switched off)</span>
|
|
397
|
+
)}
|
|
369
398
|
</div>
|
|
370
399
|
<div className="text-meta text-ink-muted truncate">
|
|
371
400
|
{account.email} · Joined {new Date(account.createdAt).toLocaleDateString()} ·{' '}
|
|
@@ -393,6 +422,26 @@ export function UserAccountsPage() {
|
|
|
393
422
|
{passwordAction(account).label}
|
|
394
423
|
</button>
|
|
395
424
|
))}
|
|
425
|
+
{!isSelf && !account.isEnvAdmin && !account.isSystem && (
|
|
426
|
+
// Not for your own account (the backend refuses it, so
|
|
427
|
+
// an admin always remains who can sign in), nor the
|
|
428
|
+
// deployment admin's (its environment password is the
|
|
429
|
+
// way back in), nor one the platform runs its own work
|
|
430
|
+
// as. Switching off asks first; switching on does not.
|
|
431
|
+
<button
|
|
432
|
+
onClick={() => (account.deactivatedAt ? toggleActive(account) : setPendingDeactivate(account))}
|
|
433
|
+
disabled={switching !== null}
|
|
434
|
+
className="text-xs px-2 py-1 rounded-sm text-ink hover:bg-hover border border-line disabled:opacity-50"
|
|
435
|
+
title={
|
|
436
|
+
account.deactivatedAt
|
|
437
|
+
? 'Let this person sign in again.'
|
|
438
|
+
: 'Stop this person signing in, without deleting anything.'
|
|
439
|
+
}
|
|
440
|
+
aria-label={`${account.deactivatedAt ? 'Switch on' : 'Switch off'} ${account.email}`}
|
|
441
|
+
>
|
|
442
|
+
{account.deactivatedAt ? 'Switch on' : 'Switch off'}
|
|
443
|
+
</button>
|
|
444
|
+
)}
|
|
396
445
|
{!isSelf && (
|
|
397
446
|
<button
|
|
398
447
|
onClick={() => openDeleteDialog(account)}
|
|
@@ -440,13 +489,16 @@ export function UserAccountsPage() {
|
|
|
440
489
|
<span className="text-xs text-ink-muted">Password</span>
|
|
441
490
|
<input
|
|
442
491
|
type="password"
|
|
443
|
-
required
|
|
444
492
|
autoComplete="new-password"
|
|
493
|
+
aria-describedby="add-account-password-hint"
|
|
445
494
|
value={addPassword}
|
|
446
495
|
onChange={(e) => setAddPassword(e.target.value)}
|
|
447
496
|
className={inputClass}
|
|
448
497
|
/>
|
|
449
498
|
</label>
|
|
499
|
+
<p id="add-account-password-hint" className="text-meta text-ink-faint">
|
|
500
|
+
Optional. Leave it empty and they sign in with single sign-on.
|
|
501
|
+
</p>
|
|
450
502
|
{addError && (
|
|
451
503
|
<div className="text-xs text-red-600" role="alert">
|
|
452
504
|
{addError}
|
|
@@ -590,6 +642,42 @@ export function UserAccountsPage() {
|
|
|
590
642
|
)}
|
|
591
643
|
</div>
|
|
592
644
|
</Dialog>
|
|
645
|
+
|
|
646
|
+
<Dialog
|
|
647
|
+
open={pendingDeactivate !== null}
|
|
648
|
+
onClose={() => setPendingDeactivate(null)}
|
|
649
|
+
title="Switch off account"
|
|
650
|
+
size="sm"
|
|
651
|
+
busy={switching !== null}
|
|
652
|
+
footer={
|
|
653
|
+
<>
|
|
654
|
+
<button
|
|
655
|
+
onClick={() => setPendingDeactivate(null)}
|
|
656
|
+
disabled={switching !== null}
|
|
657
|
+
className="px-3 py-1.5 text-sm rounded-sm text-ink hover:bg-hover border border-line disabled:opacity-50"
|
|
658
|
+
>
|
|
659
|
+
Cancel
|
|
660
|
+
</button>
|
|
661
|
+
<button
|
|
662
|
+
onClick={() => pendingDeactivate && toggleActive(pendingDeactivate)}
|
|
663
|
+
disabled={switching !== null}
|
|
664
|
+
className="px-3 py-1.5 text-sm rounded-sm bg-red-600 hover:bg-red-700 text-white disabled:opacity-50 disabled:hover:bg-red-600"
|
|
665
|
+
>
|
|
666
|
+
{switching !== null ? 'Switching off…' : 'Switch off'}
|
|
667
|
+
</button>
|
|
668
|
+
</>
|
|
669
|
+
}
|
|
670
|
+
>
|
|
671
|
+
<p className="text-xs text-ink leading-snug">
|
|
672
|
+
Switch off{' '}
|
|
673
|
+
<span className="font-medium">
|
|
674
|
+
{pendingDeactivate?.name} ({pendingDeactivate?.email})
|
|
675
|
+
</span>
|
|
676
|
+
? Nothing is deleted: they keep their history and their place in roles and groups. But
|
|
677
|
+
they can no longer sign in, and their connection keys and agent connections stop working,
|
|
678
|
+
until the account is switched back on.
|
|
679
|
+
</p>
|
|
680
|
+
</Dialog>
|
|
593
681
|
</>
|
|
594
682
|
);
|
|
595
683
|
}
|
|
@@ -13,6 +13,9 @@ const OAUTH_ERROR_MESSAGES: Record<string, string> = {
|
|
|
13
13
|
start: 'Could not start sign-in. Please try again.',
|
|
14
14
|
not_configured: 'Single sign-on is not configured on this deployment.',
|
|
15
15
|
admission: 'This workspace has no seat available for your account. Ask its admin.',
|
|
16
|
+
// On file, switched off until an admin switches the account on.
|
|
17
|
+
waiting: 'This workspace has no seat left right now. Its admin can see you are waiting and can let you in.',
|
|
18
|
+
deactivated: 'Your account on this workspace is switched off. Ask its admin to turn it back on.',
|
|
16
19
|
// Who you are was proven; nobody has given that person an account here.
|
|
17
20
|
not_invited: 'You do not have an account in this workspace yet. Ask its admin to invite you.',
|
|
18
21
|
// The provider signed the person in but does not vouch for the address.
|
|
@@ -12,6 +12,10 @@ export interface AccountSummary {
|
|
|
12
12
|
* in with the environment password whether or not a hash is stored.
|
|
13
13
|
*/
|
|
14
14
|
isEnvAdmin: boolean;
|
|
15
|
+
/** When an admin switched the account off; null while it is on. */
|
|
16
|
+
deactivatedAt: string | null;
|
|
17
|
+
/** One of the accounts the platform runs its own work as: it is never switched off. */
|
|
18
|
+
isSystem: boolean;
|
|
15
19
|
createdAt: string;
|
|
16
20
|
}
|
|
17
21
|
|
|
@@ -40,20 +44,39 @@ export async function listAccounts(): Promise<AccountSummary[]> {
|
|
|
40
44
|
return body.accounts;
|
|
41
45
|
}
|
|
42
46
|
|
|
43
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Create an account (or reset an existing account's password — deliberate
|
|
49
|
+
* upsert). Without a password the account is for single sign-on: the person
|
|
50
|
+
* finds it waiting the first time they sign in.
|
|
51
|
+
*/
|
|
44
52
|
export async function createAccount(
|
|
45
53
|
email: string,
|
|
46
54
|
name: string,
|
|
47
|
-
password
|
|
55
|
+
password?: string,
|
|
48
56
|
): Promise<void> {
|
|
49
57
|
const res = await authFetch('/api/admin/accounts', {
|
|
50
58
|
method: 'POST',
|
|
51
59
|
headers: { 'Content-Type': 'application/json' },
|
|
52
|
-
body: JSON.stringify({ email, name: name || undefined, password }),
|
|
60
|
+
body: JSON.stringify({ email, name: name || undefined, password: password || undefined }),
|
|
53
61
|
});
|
|
54
62
|
if (!res.ok) throw new Error(await readError(res, 'Could not create account'));
|
|
55
63
|
}
|
|
56
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Switch an account off: it keeps its history and its place in roles and
|
|
67
|
+
* groups, but cannot sign in, and its keys and agent connections stop working.
|
|
68
|
+
*/
|
|
69
|
+
export async function deactivateAccount(userId: string): Promise<void> {
|
|
70
|
+
const res = await authFetch(`/api/admin/accounts/${encodeURIComponent(userId)}/deactivate`, { method: 'POST' });
|
|
71
|
+
if (!res.ok) throw new Error(await readError(res, 'Could not switch this account off'));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Switch it back on — refused (with the deployment's reason) when there is no room for it. */
|
|
75
|
+
export async function reactivateAccount(userId: string): Promise<void> {
|
|
76
|
+
const res = await authFetch(`/api/admin/accounts/${encodeURIComponent(userId)}/reactivate`, { method: 'POST' });
|
|
77
|
+
if (!res.ok) throw new Error(await readError(res, 'Could not switch this account on'));
|
|
78
|
+
}
|
|
79
|
+
|
|
57
80
|
/**
|
|
58
81
|
* How many places in the knowledge base name an account's address
|
|
59
82
|
* (`GET /api/admin/accounts/:id/references`), whether removing them is
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
CanDownloadContext,
|
|
8
8
|
DownloadFileButton,
|
|
9
9
|
} from '../../workspace/components/renderers/DownloadFileButton';
|
|
10
|
+
import { READ_PANE } from '../../workspace/components/renderers/readPane';
|
|
10
11
|
import {
|
|
11
12
|
RendererWorkspaceContext,
|
|
12
13
|
getFileRenderer,
|
|
@@ -298,7 +299,12 @@ export function BranchFilePreview({
|
|
|
298
299
|
return (
|
|
299
300
|
<div className="flex h-full min-h-0 flex-col">
|
|
300
301
|
{header}
|
|
301
|
-
|
|
302
|
+
{/* The pane's own region: a viewer's "Try again" unmounts itself, and
|
|
303
|
+
this is what stays mounted around it for focus to land on — see
|
|
304
|
+
`RetryReadButton`. */}
|
|
305
|
+
<div {...READ_PANE} className="min-h-0 flex-1">
|
|
306
|
+
{body}
|
|
307
|
+
</div>
|
|
302
308
|
</div>
|
|
303
309
|
);
|
|
304
310
|
}
|