@bevel-software/platform-core-frontend 0.21.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 +140 -0
- package/src/lib/api.ts +49 -0
- package/src/modules/access/__tests__/ManageAccessDialog.request.test.tsx +376 -0
- package/src/modules/access/api.ts +6 -4
- package/src/modules/access/components/AccessRequestControl.tsx +155 -0
- package/src/modules/{library → access}/components/AccessRequestsBanner.tsx +62 -24
- package/src/modules/access/components/ManageAccessDialog.tsx +81 -4
- package/src/modules/access/hooks/useAccessRequests.ts +183 -0
- package/src/modules/access/requests.api.ts +121 -0
- 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 +8 -0
- package/src/modules/auth/services/account.api.ts +26 -3
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +171 -38
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +34 -19
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +173 -6
- package/src/modules/change-requests/components/BranchFilePreview.tsx +7 -1
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +155 -98
- 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/library/__tests__/SkillPage.test.tsx +15 -0
- package/src/modules/library/__tests__/ToolPage.test.tsx +15 -1
- package/src/modules/library/__tests__/title-row-actions.ts +53 -1
- package/src/modules/library/components/PluginJoinRequests.tsx +2 -2
- package/src/modules/library/components/skill-page/SkillPage.tsx +2 -2
- package/src/modules/library/components/tool-page/ToolPage.tsx +11 -1
- package/src/modules/library/hooks/useJoinRequests.ts +26 -101
- package/src/modules/pr/services/pr-merge.api.ts +10 -2
- package/src/modules/settings/components/DeploymentPage.tsx +22 -0
- package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +72 -4
- package/src/modules/setup/__tests__/setup.first-run.test.tsx +276 -0
- package/src/modules/setup/__tests__/setup.github.test.tsx +416 -0
- package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +275 -0
- package/src/modules/setup/__tests__/setup.repository-change.test.tsx +296 -0
- package/src/modules/setup/__tests__/setup.repository.test.tsx +463 -0
- package/src/modules/setup/__tests__/setup.test.tsx +13 -17
- package/src/modules/setup/components/GitHubRepositoryPanel.tsx +369 -0
- package/src/modules/setup/components/SetupGate.tsx +1 -0
- package/src/modules/setup/components/SetupScreen.tsx +608 -41
- package/src/modules/setup/services/setup.api.ts +171 -3
- package/src/modules/setup/utils/kept-draft.ts +86 -0
- 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/components/SlotBoundary.tsx +51 -0
- package/src/shared/markdown/__tests__/hrefs.test.ts +111 -0
- package/src/shared/markdown/hrefs.ts +80 -4
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { authFetch } from '../../lib/api';
|
|
2
|
+
import { handleApiResponse } from '../git/services/git.api';
|
|
3
|
+
|
|
4
|
+
/** The two levels the Manage access dialog can ask for. Owner covers Can edit. */
|
|
5
|
+
export type RequestLevel = 'write' | 'owner';
|
|
6
|
+
|
|
7
|
+
/** The dialog's own words for a level — the same ones its row menu uses. */
|
|
8
|
+
export const LEVEL_WORDS: Record<RequestLevel, string> = {
|
|
9
|
+
write: 'Can edit',
|
|
10
|
+
owner: 'Owner',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** The longest note a request can carry, in characters. Mirrors the server's cap. */
|
|
14
|
+
export const REQUEST_NOTE_MAX = 500;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* What the requester's own dialog shows in place of the control.
|
|
18
|
+
*
|
|
19
|
+
* `not-accepted` means their last request closed without the access landing —
|
|
20
|
+
* declined by an editor, or withdrawn by themselves. The two read the same on
|
|
21
|
+
* purpose: nothing records WHO closed a request, and inventing a difference
|
|
22
|
+
* would need a new column.
|
|
23
|
+
*/
|
|
24
|
+
export interface AccessRequestStatus {
|
|
25
|
+
state: 'none' | 'pending' | 'not-accepted';
|
|
26
|
+
level?: RequestLevel;
|
|
27
|
+
number?: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** One grant a request still proposes — the shape `grantAccess` takes. */
|
|
31
|
+
export interface AccessProposal {
|
|
32
|
+
verb: 'read' | 'write' | 'owner' | 'download';
|
|
33
|
+
/** Canonical identity (lowercased email / canonical role) — a stable key. */
|
|
34
|
+
id: string;
|
|
35
|
+
principal:
|
|
36
|
+
| { kind: 'user'; email: string; displayName: string }
|
|
37
|
+
| { kind: 'role'; role: string };
|
|
38
|
+
label: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** One open request, as the editors' surfaces render it. */
|
|
42
|
+
export interface AccessRequestRow {
|
|
43
|
+
number: number;
|
|
44
|
+
branch: string;
|
|
45
|
+
requesterName: string;
|
|
46
|
+
createdAt: string;
|
|
47
|
+
/** Still-pending proposals; a request with none left is already closed. */
|
|
48
|
+
proposals: AccessProposal[];
|
|
49
|
+
/** The requester's note, as plain text, when they wrote one. */
|
|
50
|
+
note?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Repo- or workspace-relative path plus what it is; both are sent verbatim. */
|
|
54
|
+
interface TargetQuery {
|
|
55
|
+
path: string;
|
|
56
|
+
kind: 'folder' | 'file';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const query = (t: TargetQuery) => `path=${encodeURIComponent(t.path)}&kind=${t.kind}`;
|
|
60
|
+
|
|
61
|
+
/** Where the caller's own request on this item stands. */
|
|
62
|
+
export async function fetchAccessRequestStatus(
|
|
63
|
+
workspaceId: string,
|
|
64
|
+
target: TargetQuery,
|
|
65
|
+
): Promise<AccessRequestStatus> {
|
|
66
|
+
return handleApiResponse(
|
|
67
|
+
await authFetch(`/api/workspace/${workspaceId}/access/request?${query(target)}`),
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Ask for `level` on this item. Idempotent by (person, item): a second send
|
|
73
|
+
* while a request is open answers with that same request rather than opening
|
|
74
|
+
* a rival, so a double click leaves exactly one.
|
|
75
|
+
*/
|
|
76
|
+
export async function sendAccessRequest(
|
|
77
|
+
workspaceId: string,
|
|
78
|
+
input: TargetQuery & { level: RequestLevel; note?: string },
|
|
79
|
+
): Promise<{ number: number; level: RequestLevel }> {
|
|
80
|
+
return handleApiResponse(
|
|
81
|
+
await authFetch(`/api/workspace/${workspaceId}/access/request`, {
|
|
82
|
+
method: 'POST',
|
|
83
|
+
headers: { 'Content-Type': 'application/json' },
|
|
84
|
+
body: JSON.stringify(input),
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The open requests for an item the caller EDITS. Everyone else gets `[]`
|
|
91
|
+
* rather than a 403, so the dialog may ask unconditionally — "am I an editor
|
|
92
|
+
* here" stays a question only the server answers.
|
|
93
|
+
*/
|
|
94
|
+
export async function listAccessRequests(
|
|
95
|
+
workspaceId: string,
|
|
96
|
+
target: TargetQuery,
|
|
97
|
+
): Promise<AccessRequestRow[]> {
|
|
98
|
+
const data = await handleApiResponse<{ requests: AccessRequestRow[] }>(
|
|
99
|
+
await authFetch(`/api/workspace/${workspaceId}/access/requests?${query(target)}`),
|
|
100
|
+
);
|
|
101
|
+
return data.requests;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Ask the server to settle a request whose proposals have all landed. The
|
|
106
|
+
* listing does this lazily too, so a failure here only delays it.
|
|
107
|
+
*/
|
|
108
|
+
export async function reconcileAccessRequest(
|
|
109
|
+
workspaceId: string,
|
|
110
|
+
number: number,
|
|
111
|
+
target: TargetQuery,
|
|
112
|
+
): Promise<boolean> {
|
|
113
|
+
const data = await handleApiResponse<{ closed: boolean }>(
|
|
114
|
+
await authFetch(`/api/workspace/${workspaceId}/access/requests/${number}/reconcile`, {
|
|
115
|
+
method: 'POST',
|
|
116
|
+
headers: { 'Content-Type': 'application/json' },
|
|
117
|
+
body: JSON.stringify(target),
|
|
118
|
+
}),
|
|
119
|
+
);
|
|
120
|
+
return data.closed;
|
|
121
|
+
}
|
|
@@ -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,14 @@ 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.',
|
|
19
|
+
// Who you are was proven; nobody has given that person an account here.
|
|
20
|
+
not_invited: 'You do not have an account in this workspace yet. Ask its admin to invite you.',
|
|
21
|
+
// The provider signed the person in but does not vouch for the address.
|
|
22
|
+
unverified_email:
|
|
23
|
+
'Your sign-in provider has not verified your email address, so it cannot be used to sign in here.',
|
|
16
24
|
};
|
|
17
25
|
|
|
18
26
|
export function LoginScreen() {
|
|
@@ -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
|