@bevel-software/platform-core-frontend 0.27.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/core/ProductName.tsx +4 -4
- package/src/core/__tests__/ProductName.test.tsx +46 -0
- package/src/core/maker-url.ts +30 -0
- package/src/core/registry.ts +27 -0
- package/src/lib/__tests__/latest-request.test.ts +48 -0
- package/src/lib/latest-request.ts +45 -0
- package/src/modules/access/__tests__/ManageAccessDialog.no-sso-invite.test.tsx +222 -0
- package/src/modules/access/api.ts +19 -3
- package/src/modules/access/components/ManageAccessDialog.tsx +60 -7
- package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +16 -1
- package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +284 -39
- package/src/modules/admin/components/AdminRolesPage.tsx +13 -14
- package/src/modules/admin/components/UserAccountsPage.tsx +91 -107
- package/src/modules/admin/services/roles.api.ts +14 -1
- package/src/modules/auth/__tests__/LoginScreen.test.tsx +80 -5
- package/src/modules/auth/__tests__/sso-strict-probe.test.ts +66 -0
- package/src/modules/auth/components/LoginScreen.tsx +100 -75
- package/src/modules/auth/services/account.api.ts +31 -2
- package/src/modules/auth/services/sso.ts +29 -8
- package/src/modules/auth/state/use-sign-in-methods.ts +41 -0
- package/src/modules/onboarding/__tests__/InviteButton.test.tsx +214 -0
- package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +56 -1
- package/src/modules/onboarding/__tests__/get-started-column.test.tsx +538 -81
- package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +543 -124
- package/src/modules/onboarding/__tests__/invite-emails.test.ts +247 -0
- package/src/modules/onboarding/components/GetStartedColumn.tsx +30 -11
- package/src/modules/onboarding/components/InviteButton.tsx +119 -15
- package/src/modules/onboarding/components/InviteDialog.tsx +392 -75
- package/src/modules/onboarding/first-page-prompt.ts +34 -0
- package/src/modules/onboarding/invite-emails.ts +171 -33
- package/src/modules/onboarding/state/invite-dialog.context.ts +7 -4
- package/src/modules/onboarding/state/invite-dialog.tsx +12 -4
- package/src/modules/toolbar/commands/actions.tsx +10 -4
- package/src/modules/toolbar/commands/useCommandActions.ts +5 -3
- package/src/modules/toolbar/components/AppSwitcher.tsx +19 -0
- package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +46 -1
- package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +34 -2
- package/src/modules/workspace/hooks/__tests__/useCreatePage.test.ts +137 -0
- package/src/modules/workspace/hooks/__tests__/useKnowledgeWriteTarget.test.ts +302 -0
- package/src/modules/workspace/hooks/useCreatePage.ts +118 -28
- package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +238 -0
|
@@ -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 = '
|
|
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;
|
|
@@ -4,6 +4,10 @@ import userEvent from '@testing-library/user-event';
|
|
|
4
4
|
import { UserAccountsPage } from '../components/UserAccountsPage';
|
|
5
5
|
import { AdminContext } from '../state/admin.context';
|
|
6
6
|
import { AuthContext, type AuthContextValue } from '../../auth/state/auth.context';
|
|
7
|
+
import {
|
|
8
|
+
InviteDialogContext,
|
|
9
|
+
type InviteDialogController,
|
|
10
|
+
} from '../../onboarding/state/invite-dialog.context';
|
|
7
11
|
import {
|
|
8
12
|
createAccount,
|
|
9
13
|
deactivateAccount,
|
|
@@ -12,6 +16,7 @@ import {
|
|
|
12
16
|
listAccounts,
|
|
13
17
|
reactivateAccount,
|
|
14
18
|
type AccountReferences,
|
|
19
|
+
type AccountSummary,
|
|
15
20
|
} from '../../auth/services/account.api';
|
|
16
21
|
|
|
17
22
|
vi.mock('../../auth/services/account.api', () => ({
|
|
@@ -42,6 +47,8 @@ const ALICE = {
|
|
|
42
47
|
name: 'Alice',
|
|
43
48
|
hasPassword: false,
|
|
44
49
|
isEnvAdmin: false,
|
|
50
|
+
isOwner: false,
|
|
51
|
+
ownerCanBeDeleted: false,
|
|
45
52
|
createdAt: '2026-01-01T00:00:00Z',
|
|
46
53
|
deactivatedAt: null,
|
|
47
54
|
isSystem: false,
|
|
@@ -52,18 +59,22 @@ const BOB = {
|
|
|
52
59
|
name: 'Bob',
|
|
53
60
|
hasPassword: true,
|
|
54
61
|
isEnvAdmin: false,
|
|
62
|
+
isOwner: false,
|
|
63
|
+
ownerCanBeDeleted: false,
|
|
55
64
|
createdAt: '2026-01-01T00:00:00Z',
|
|
56
65
|
deactivatedAt: null,
|
|
57
66
|
isSystem: false,
|
|
58
67
|
};
|
|
59
|
-
// The
|
|
60
|
-
//
|
|
68
|
+
// The owner (ADMIN_EMAIL) on a self-hosted deployment with ADMIN_PASSWORD set
|
|
69
|
+
// — a different account from the signed-in admin. No hash stored yet.
|
|
61
70
|
const ROOT = {
|
|
62
71
|
id: 'u-root',
|
|
63
72
|
email: 'root@example.com',
|
|
64
73
|
name: 'Root',
|
|
65
74
|
hasPassword: false,
|
|
66
75
|
isEnvAdmin: true,
|
|
76
|
+
isOwner: true,
|
|
77
|
+
ownerCanBeDeleted: true,
|
|
67
78
|
createdAt: '2026-01-01T00:00:00Z',
|
|
68
79
|
deactivatedAt: null,
|
|
69
80
|
isSystem: false,
|
|
@@ -76,7 +87,7 @@ function row(name: string): HTMLElement {
|
|
|
76
87
|
return within(li).getByText(/· Joined /);
|
|
77
88
|
}
|
|
78
89
|
|
|
79
|
-
function renderPage(opts: { isAdmin?: boolean } = {}) {
|
|
90
|
+
function renderPage(opts: { isAdmin?: boolean; invite?: InviteDialogController | null } = {}) {
|
|
80
91
|
const auth: AuthContextValue = {
|
|
81
92
|
user: ME,
|
|
82
93
|
token: 't',
|
|
@@ -98,7 +109,9 @@ function renderPage(opts: { isAdmin?: boolean } = {}) {
|
|
|
98
109
|
runRolesRecovery: async () => {},
|
|
99
110
|
}}
|
|
100
111
|
>
|
|
101
|
-
<
|
|
112
|
+
<InviteDialogContext.Provider value={opts.invite === undefined ? null : opts.invite}>
|
|
113
|
+
<UserAccountsPage />
|
|
114
|
+
</InviteDialogContext.Provider>
|
|
102
115
|
</AdminContext.Provider>
|
|
103
116
|
</AuthContext.Provider>,
|
|
104
117
|
);
|
|
@@ -108,12 +121,12 @@ beforeEach(() => {
|
|
|
108
121
|
vi.mocked(listAccounts)
|
|
109
122
|
.mockReset()
|
|
110
123
|
.mockResolvedValue([
|
|
111
|
-
{ ...ME, hasPassword: true, isEnvAdmin: false, createdAt: '2026-01-01T00:00:00Z', deactivatedAt: null, isSystem: false },
|
|
124
|
+
{ ...ME, hasPassword: true, isEnvAdmin: false, isOwner: false, ownerCanBeDeleted: false, createdAt: '2026-01-01T00:00:00Z', deactivatedAt: null, isSystem: false },
|
|
112
125
|
ALICE,
|
|
113
126
|
]);
|
|
114
127
|
vi.mocked(deleteAccount).mockReset().mockResolvedValue(null);
|
|
115
128
|
vi.mocked(getAccountReferences).mockReset().mockResolvedValue(REFS);
|
|
116
|
-
vi.mocked(createAccount).mockReset().mockResolvedValue(
|
|
129
|
+
vi.mocked(createAccount).mockReset().mockResolvedValue({});
|
|
117
130
|
vi.mocked(deactivateAccount).mockReset().mockResolvedValue(undefined);
|
|
118
131
|
vi.mocked(reactivateAccount).mockReset().mockResolvedValue(undefined);
|
|
119
132
|
});
|
|
@@ -155,8 +168,8 @@ describe('UserAccountsPage', () => {
|
|
|
155
168
|
expect(row('Alice')).toHaveTextContent(/· No password — signs in with single sign-on$/);
|
|
156
169
|
expect(row('Bob')).toHaveTextContent(/· Password$/);
|
|
157
170
|
// The deployment admin reads the same with or without a stored hash.
|
|
158
|
-
expect(row('Root')).toHaveTextContent(/· Password \(
|
|
159
|
-
expect(row('Root Hashed')).toHaveTextContent(/· Password \(
|
|
171
|
+
expect(row('Root')).toHaveTextContent(/· Password \(owner\)$/);
|
|
172
|
+
expect(row('Root Hashed')).toHaveTextContent(/· Password \(owner\)$/);
|
|
160
173
|
expect(screen.queryByText(/Single sign-on only/)).not.toBeInTheDocument();
|
|
161
174
|
});
|
|
162
175
|
|
|
@@ -167,7 +180,7 @@ describe('UserAccountsPage', () => {
|
|
|
167
180
|
const cases: Array<[string, RegExp]> = [
|
|
168
181
|
['alice@example.com', /No password — signs in with single sign-on: they can sign in again later with single sign-on/],
|
|
169
182
|
['bob@example.com', /Password: to sign in again they will need an admin/],
|
|
170
|
-
['root@example.com', /Password \(
|
|
183
|
+
['root@example.com', /Password \(owner\): they can still sign in with the owner password set on the server, but will start fresh\./],
|
|
171
184
|
];
|
|
172
185
|
for (const [email, wording] of cases) {
|
|
173
186
|
await userEvent.click(screen.getByRole('button', { name: `Delete account ${email}` }));
|
|
@@ -542,31 +555,6 @@ describe('UserAccountsPage', () => {
|
|
|
542
555
|
expect(listAccounts).toHaveBeenCalledTimes(1);
|
|
543
556
|
});
|
|
544
557
|
|
|
545
|
-
it('adds a new account and refreshes the list', async () => {
|
|
546
|
-
renderPage();
|
|
547
|
-
await waitFor(() => screen.getByText('Alice'));
|
|
548
|
-
await userEvent.type(screen.getByLabelText('Email'), 'bob@example.com');
|
|
549
|
-
await userEvent.type(screen.getByLabelText(/Name/), 'Bob');
|
|
550
|
-
await userEvent.type(screen.getByLabelText('Password'), 'bobs-password-1');
|
|
551
|
-
await userEvent.click(screen.getByRole('button', { name: 'Add account' }));
|
|
552
|
-
await waitFor(() =>
|
|
553
|
-
expect(createAccount).toHaveBeenCalledWith('bob@example.com', 'Bob', 'bobs-password-1'),
|
|
554
|
-
);
|
|
555
|
-
expect(listAccounts).toHaveBeenCalledTimes(2);
|
|
556
|
-
});
|
|
557
|
-
|
|
558
|
-
it('surfaces an add failure inline', async () => {
|
|
559
|
-
vi.mocked(createAccount).mockRejectedValueOnce(
|
|
560
|
-
new Error('Password must be at least 8 characters'),
|
|
561
|
-
);
|
|
562
|
-
renderPage();
|
|
563
|
-
await waitFor(() => screen.getByText('Alice'));
|
|
564
|
-
await userEvent.type(screen.getByLabelText('Email'), 'bob@example.com');
|
|
565
|
-
await userEvent.type(screen.getByLabelText('Password'), 'short');
|
|
566
|
-
await userEvent.click(screen.getByRole('button', { name: 'Add account' }));
|
|
567
|
-
expect(await screen.findByRole('alert')).toHaveTextContent('at least 8 characters');
|
|
568
|
-
});
|
|
569
|
-
|
|
570
558
|
// "We could not ask" is not "there is nobody". The failure used to store an
|
|
571
559
|
// empty list, so an admin whose backend was unreachable read "No user
|
|
572
560
|
// accounts." — a deployment they would have had every reason to believe.
|
|
@@ -646,12 +634,269 @@ describe('UserAccountsPage — switching accounts off and on', () => {
|
|
|
646
634
|
expect(screen.queryByRole('button', { name: 'Switch off root@example.com' })).not.toBeInTheDocument();
|
|
647
635
|
});
|
|
648
636
|
|
|
649
|
-
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* One way to create an account: User accounts has no Add account form, and
|
|
641
|
+
* its list ends with an "Invite new users" row that opens the Invite dialog
|
|
642
|
+
* the toolbar opens. A send from that dialog shows on the list without a
|
|
643
|
+
* reload.
|
|
644
|
+
*/
|
|
645
|
+
describe('UserAccountsPage — inviting new users', () => {
|
|
646
|
+
function controller(invitedRevision = 0): InviteDialogController {
|
|
647
|
+
return { open: vi.fn(), invitedRevision };
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
it('has no Add account form', async () => {
|
|
651
|
+
renderPage({ invite: controller() });
|
|
652
|
+
await waitFor(() => expect(screen.getByText('Alice')).toBeInTheDocument());
|
|
653
|
+
expect(screen.queryByText('Add account')).not.toBeInTheDocument();
|
|
654
|
+
expect(screen.queryByRole('button', { name: 'Add account' })).not.toBeInTheDocument();
|
|
655
|
+
expect(screen.queryByLabelText('Email')).not.toBeInTheDocument();
|
|
656
|
+
expect(screen.queryByText(/Leave it empty and they sign in with single sign-on/)).not.toBeInTheDocument();
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
it('ends the account list with "Invite new users", which opens the Invite dialog', async () => {
|
|
660
|
+
const invite = controller();
|
|
661
|
+
renderPage({ invite });
|
|
662
|
+
await waitFor(() => expect(screen.getByText('Alice')).toBeInTheDocument());
|
|
663
|
+
const button = screen.getByRole('button', { name: 'Invite new users' });
|
|
664
|
+
const items = within(button.closest('ul')!).getAllByRole('listitem');
|
|
665
|
+
expect(items[items.length - 1]).toContainElement(button);
|
|
666
|
+
await userEvent.click(button);
|
|
667
|
+
expect(invite.open).toHaveBeenCalledTimes(1);
|
|
668
|
+
expect(createAccount).not.toHaveBeenCalled();
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
it('offers no row without an Invite dialog to open', async () => {
|
|
672
|
+
renderPage({ invite: null });
|
|
673
|
+
await waitFor(() => expect(screen.getByText('Alice')).toBeInTheDocument());
|
|
674
|
+
expect(screen.queryByRole('button', { name: 'Invite new users' })).not.toBeInTheDocument();
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
it('reads the list again after a send, so the new accounts show without a reload', async () => {
|
|
678
|
+
const view = renderPage({ invite: controller(0) });
|
|
679
|
+
await waitFor(() => expect(screen.getByText('Alice')).toBeInTheDocument());
|
|
680
|
+
expect(listAccounts).toHaveBeenCalledTimes(1);
|
|
681
|
+
|
|
682
|
+
vi.mocked(listAccounts).mockResolvedValue([
|
|
683
|
+
{ ...ME, hasPassword: true, isEnvAdmin: false, isOwner: false, ownerCanBeDeleted: false, createdAt: '2026-01-01T00:00:00Z', deactivatedAt: null, isSystem: false },
|
|
684
|
+
ALICE,
|
|
685
|
+
{ ...BOB, id: 'u-lena', email: 'lena@example.com', name: 'lena' },
|
|
686
|
+
]);
|
|
687
|
+
view.rerender(
|
|
688
|
+
<AuthContext.Provider value={{ user: ME, token: 't', isLoading: false, login: vi.fn(async () => {}), logout: vi.fn() }}>
|
|
689
|
+
<AdminContext.Provider
|
|
690
|
+
value={{
|
|
691
|
+
isAdmin: true,
|
|
692
|
+
unreadCount: 0,
|
|
693
|
+
lastSeen: null,
|
|
694
|
+
markSeen: () => {},
|
|
695
|
+
refresh: () => {},
|
|
696
|
+
rolesConfigCorrupted: false,
|
|
697
|
+
rolesConfigErrors: [],
|
|
698
|
+
runRolesRecovery: async () => {},
|
|
699
|
+
}}
|
|
700
|
+
>
|
|
701
|
+
<InviteDialogContext.Provider value={controller(1)}>
|
|
702
|
+
<UserAccountsPage />
|
|
703
|
+
</InviteDialogContext.Provider>
|
|
704
|
+
</AdminContext.Provider>
|
|
705
|
+
</AuthContext.Provider>,
|
|
706
|
+
);
|
|
707
|
+
expect(await screen.findByText('lena')).toBeInTheDocument();
|
|
708
|
+
expect(listAccounts).toHaveBeenCalledTimes(2);
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
it('keeps the refreshed list when an older read answers after it', async () => {
|
|
712
|
+
const withLena = [
|
|
713
|
+
{ ...ME, hasPassword: true, isEnvAdmin: false, isOwner: false, ownerCanBeDeleted: false, createdAt: '2026-01-01T00:00:00Z', deactivatedAt: null, isSystem: false },
|
|
714
|
+
ALICE,
|
|
715
|
+
{ ...BOB, id: 'u-lena', email: 'lena@example.com', name: 'lena' },
|
|
716
|
+
];
|
|
717
|
+
let answerFirst: (rows: typeof withLena) => void = () => {};
|
|
718
|
+
vi.mocked(listAccounts)
|
|
719
|
+
.mockReset()
|
|
720
|
+
.mockImplementationOnce(() => new Promise((resolve) => (answerFirst = resolve)))
|
|
721
|
+
.mockResolvedValue(withLena);
|
|
722
|
+
const page = (revision: number) => (
|
|
723
|
+
<AuthContext.Provider value={{ user: ME, token: 't', isLoading: false, login: vi.fn(async () => {}), logout: vi.fn() }}>
|
|
724
|
+
<AdminContext.Provider
|
|
725
|
+
value={{
|
|
726
|
+
isAdmin: true,
|
|
727
|
+
unreadCount: 0,
|
|
728
|
+
lastSeen: null,
|
|
729
|
+
markSeen: () => {},
|
|
730
|
+
refresh: () => {},
|
|
731
|
+
rolesConfigCorrupted: false,
|
|
732
|
+
rolesConfigErrors: [],
|
|
733
|
+
runRolesRecovery: async () => {},
|
|
734
|
+
}}
|
|
735
|
+
>
|
|
736
|
+
<InviteDialogContext.Provider value={controller(revision)}>
|
|
737
|
+
<UserAccountsPage />
|
|
738
|
+
</InviteDialogContext.Provider>
|
|
739
|
+
</AdminContext.Provider>
|
|
740
|
+
</AuthContext.Provider>
|
|
741
|
+
);
|
|
742
|
+
const view = render(page(0));
|
|
743
|
+
view.rerender(page(1));
|
|
744
|
+
expect(await screen.findByText('lena')).toBeInTheDocument();
|
|
745
|
+
// The first read, from before the send, answers last: it must not land.
|
|
746
|
+
answerFirst([withLena[0]!, ALICE]);
|
|
747
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
748
|
+
expect(screen.getByText('lena')).toBeInTheDocument();
|
|
749
|
+
});
|
|
750
|
+
|
|
751
|
+
it('keeps a switch busy until the latest read lands, even when a send’s refresh overtook its own', async () => {
|
|
650
752
|
const user = userEvent.setup();
|
|
753
|
+
const off = { ...ALICE, deactivatedAt: '2026-09-01T00:00:00Z' };
|
|
754
|
+
let answerSwitch: (rows: AccountSummary[]) => void = () => {};
|
|
755
|
+
let answerSend: (rows: AccountSummary[]) => void = () => {};
|
|
756
|
+
vi.mocked(listAccounts)
|
|
757
|
+
.mockReset()
|
|
758
|
+
.mockResolvedValueOnce([ALICE])
|
|
759
|
+
.mockImplementationOnce(() => new Promise((resolve) => (answerSwitch = resolve)))
|
|
760
|
+
.mockImplementationOnce(() => new Promise((resolve) => (answerSend = resolve)));
|
|
761
|
+
const page = (revision: number) => (
|
|
762
|
+
<AuthContext.Provider value={{ user: ME, token: 't', isLoading: false, login: vi.fn(async () => {}), logout: vi.fn() }}>
|
|
763
|
+
<AdminContext.Provider
|
|
764
|
+
value={{
|
|
765
|
+
isAdmin: true,
|
|
766
|
+
unreadCount: 0,
|
|
767
|
+
lastSeen: null,
|
|
768
|
+
markSeen: () => {},
|
|
769
|
+
refresh: () => {},
|
|
770
|
+
rolesConfigCorrupted: false,
|
|
771
|
+
rolesConfigErrors: [],
|
|
772
|
+
runRolesRecovery: async () => {},
|
|
773
|
+
}}
|
|
774
|
+
>
|
|
775
|
+
<InviteDialogContext.Provider value={controller(revision)}>
|
|
776
|
+
<UserAccountsPage />
|
|
777
|
+
</InviteDialogContext.Provider>
|
|
778
|
+
</AdminContext.Provider>
|
|
779
|
+
</AuthContext.Provider>
|
|
780
|
+
);
|
|
781
|
+
const view = render(page(0));
|
|
782
|
+
await user.click(await screen.findByRole('button', { name: 'Switch off alice@example.com' }));
|
|
783
|
+
await user.click(within(screen.getByRole('dialog')).getByRole('button', { name: 'Switch off' }));
|
|
784
|
+
await waitFor(() => expect(listAccounts).toHaveBeenCalledTimes(2));
|
|
785
|
+
// A send from the Invite dialog reads the list again before the switch's read answers.
|
|
786
|
+
view.rerender(page(1));
|
|
787
|
+
await waitFor(() => expect(listAccounts).toHaveBeenCalledTimes(3));
|
|
788
|
+
answerSwitch([off]);
|
|
789
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
790
|
+
// Its own read was overtaken: still busy, so the stale row offers no second click.
|
|
791
|
+
expect(screen.getByRole('button', { name: 'Switching off…' })).toBeDisabled();
|
|
792
|
+
answerSend([off]);
|
|
793
|
+
expect(await screen.findByText('(switched off)')).toBeInTheDocument();
|
|
794
|
+
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
|
795
|
+
});
|
|
796
|
+
});
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* The owner (`ADMIN_EMAIL`), on a self-hosted deployment with a server-held
|
|
800
|
+
* owner password (ROOT) and on one without (the cloud's configuration).
|
|
801
|
+
*/
|
|
802
|
+
describe('UserAccountsPage — the owner', () => {
|
|
803
|
+
// The cloud: the owner signs in with single sign-on, the server holds no password for them.
|
|
804
|
+
const CLOUD_OWNER = {
|
|
805
|
+
...ALICE,
|
|
806
|
+
id: 'u-owner',
|
|
807
|
+
email: 'owner@example.com',
|
|
808
|
+
name: 'Olive',
|
|
809
|
+
isOwner: true,
|
|
810
|
+
ownerCanBeDeleted: false,
|
|
811
|
+
};
|
|
812
|
+
|
|
813
|
+
for (const [label, owner] of [
|
|
814
|
+
['with a server-held owner password', ROOT],
|
|
815
|
+
['without one (the cloud)', CLOUD_OWNER],
|
|
816
|
+
] as const) {
|
|
817
|
+
it(`labels the owner's row "Owner" and offers no Switch off or password action, ${label}`, async () => {
|
|
818
|
+
vi.mocked(listAccounts).mockResolvedValue([ALICE, owner]);
|
|
819
|
+
renderPage();
|
|
820
|
+
await waitFor(() => screen.getByText(owner.name));
|
|
821
|
+
const li = screen.getByText(owner.name).closest('li')!;
|
|
822
|
+
expect(within(li).getByText('Owner')).toBeInTheDocument();
|
|
823
|
+
expect(screen.queryByRole('button', { name: `Switch off ${owner.email}` })).not.toBeInTheDocument();
|
|
824
|
+
expect(screen.queryByRole('button', { name: `Set password for ${owner.email}` })).not.toBeInTheDocument();
|
|
825
|
+
expect(screen.queryByRole('button', { name: `Reset password for ${owner.email}` })).not.toBeInTheDocument();
|
|
826
|
+
// The account beside it keeps every control, and no label.
|
|
827
|
+
const alice = screen.getByText('Alice').closest('li')!;
|
|
828
|
+
expect(within(alice).queryByText('Owner')).not.toBeInTheDocument();
|
|
829
|
+
expect(screen.getByRole('button', { name: 'Switch off alice@example.com' })).toBeInTheDocument();
|
|
830
|
+
expect(screen.getByRole('button', { name: 'Set password for alice@example.com' })).toBeInTheDocument();
|
|
831
|
+
expect(screen.getByRole('button', { name: 'Delete account alice@example.com' })).toBeInTheDocument();
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
it('offers Delete account for the owner only where the server allows it', async () => {
|
|
836
|
+
vi.mocked(listAccounts).mockResolvedValue([ROOT, CLOUD_OWNER]);
|
|
651
837
|
renderPage();
|
|
652
|
-
await waitFor(() =>
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
838
|
+
await waitFor(() => screen.getByText('Olive'));
|
|
839
|
+
expect(screen.getByRole('button', { name: 'Delete account root@example.com' })).toBeInTheDocument();
|
|
840
|
+
expect(screen.queryByRole('button', { name: 'Delete account owner@example.com' })).not.toBeInTheDocument();
|
|
841
|
+
// No controls at all on the cloud owner's row.
|
|
842
|
+
expect(within(screen.getByText('Olive').closest('li')!).queryAllByRole('button')).toHaveLength(0);
|
|
843
|
+
});
|
|
844
|
+
|
|
845
|
+
it('the delete dialog for the owner says they keep their place in roles and access rules', async () => {
|
|
846
|
+
vi.mocked(listAccounts).mockResolvedValue([ROOT]);
|
|
847
|
+
vi.mocked(getAccountReferences).mockResolvedValue({
|
|
848
|
+
...REFS,
|
|
849
|
+
removable: false,
|
|
850
|
+
blockedReason: 'The owner stays in roles and access rules.',
|
|
851
|
+
});
|
|
852
|
+
renderPage();
|
|
853
|
+
await waitFor(() => screen.getByText('Root'));
|
|
854
|
+
await userEvent.click(screen.getByRole('button', { name: 'Delete account root@example.com' }));
|
|
855
|
+
const dialog = screen.getByRole('dialog');
|
|
856
|
+
expect(dialog).toHaveTextContent(
|
|
857
|
+
'Password (owner): they can still sign in with the owner password set on the server, but will start fresh.',
|
|
858
|
+
);
|
|
859
|
+
expect(dialog).toHaveTextContent('The owner stays in roles and access rules.');
|
|
860
|
+
expect(dialog).not.toHaveTextContent('ADMIN_EMAIL');
|
|
861
|
+
expect(dialog).not.toHaveTextContent('deployment admin');
|
|
862
|
+
const option = within(dialog).getByRole('checkbox', { name: 'Also remove them from roles, groups and access rules' });
|
|
863
|
+
expect(option).toBeDisabled();
|
|
864
|
+
expect(option).not.toBeChecked();
|
|
865
|
+
await userEvent.click(within(dialog).getByRole('button', { name: 'Delete account' }));
|
|
866
|
+
await waitFor(() => expect(deleteAccount).toHaveBeenCalledWith('u-root', { removeFromAccess: false }));
|
|
867
|
+
});
|
|
868
|
+
|
|
869
|
+
it("the owner's note is the server's reason once it has arrived, and the same sentence when it cannot be fetched", async () => {
|
|
870
|
+
vi.mocked(listAccounts).mockResolvedValue([ROOT]);
|
|
871
|
+
vi.mocked(getAccountReferences).mockResolvedValue({ ...REFS, removable: false, blockedReason: 'Reason from the server.' });
|
|
872
|
+
renderPage();
|
|
873
|
+
await waitFor(() => screen.getByText('Root'));
|
|
874
|
+
await userEvent.click(screen.getByRole('button', { name: 'Delete account root@example.com' }));
|
|
875
|
+
await waitFor(() => expect(screen.getByRole('dialog')).toHaveTextContent('Reason from the server.'));
|
|
876
|
+
expect(screen.getByRole('dialog')).not.toHaveTextContent('The owner stays in roles and access rules.');
|
|
877
|
+
await userEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: 'Cancel' }));
|
|
878
|
+
|
|
879
|
+
vi.mocked(getAccountReferences).mockRejectedValue(new Error('offline'));
|
|
880
|
+
await userEvent.click(screen.getByRole('button', { name: 'Delete account root@example.com' }));
|
|
881
|
+
await waitFor(() => expect(screen.getByRole('dialog')).toHaveTextContent('offline'));
|
|
882
|
+
expect(screen.getByRole('dialog')).toHaveTextContent('The owner stays in roles and access rules.');
|
|
883
|
+
});
|
|
884
|
+
|
|
885
|
+
it('the owner viewing their own row sees "(you)" and "Owner", and no buttons', async () => {
|
|
886
|
+
vi.mocked(listAccounts).mockResolvedValue([{ ...CLOUD_OWNER, id: ME.id, email: ME.email, name: ME.name }, ALICE]);
|
|
887
|
+
renderPage();
|
|
888
|
+
await waitFor(() => screen.getByText('Admin'));
|
|
889
|
+
const li = screen.getByText('Admin').closest('li')!;
|
|
890
|
+
expect(li).toHaveTextContent('(you)');
|
|
891
|
+
expect(within(li).getByText('Owner')).toBeInTheDocument();
|
|
892
|
+
expect(within(li).queryAllByRole('button')).toHaveLength(0);
|
|
893
|
+
});
|
|
894
|
+
|
|
895
|
+
it('an owner switched off before the server refused it can still be switched back on', async () => {
|
|
896
|
+
vi.mocked(listAccounts).mockResolvedValue([{ ...CLOUD_OWNER, deactivatedAt: '2026-10-10T00:00:00Z' }]);
|
|
897
|
+
renderPage();
|
|
898
|
+
await waitFor(() => screen.getByText('Olive'));
|
|
899
|
+
await userEvent.click(screen.getByRole('button', { name: 'Switch on owner@example.com' }));
|
|
900
|
+
expect(reactivateAccount).toHaveBeenCalledWith('u-owner');
|
|
656
901
|
});
|
|
657
902
|
});
|
|
@@ -27,15 +27,6 @@ interface SelfRemoveTarget {
|
|
|
27
27
|
email: string;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
/**
|
|
31
|
-
* The note beside a fixed Admin member, and the refusal shown when someone
|
|
32
|
-
* tries to add that address as a regular member. Word-for-word the sentence
|
|
33
|
-
* the backend's 422 leads with (`roles-admin.service.ts`), so the two
|
|
34
|
-
* surfaces say the same thing.
|
|
35
|
-
*/
|
|
36
|
-
const FIXED_ADMIN_NOTE =
|
|
37
|
-
'Deployment admin, set in the server configuration; cannot be removed here';
|
|
38
|
-
|
|
39
30
|
/**
|
|
40
31
|
* App roles (formerly Roles & Members), routed standalone at `/roles-and-members` (below the
|
|
41
32
|
* persistent toolbar). Admin-gated: non-admins get a clear "Admins only"
|
|
@@ -192,6 +183,10 @@ function RoleCard({
|
|
|
192
183
|
// `ADMIN_EMAIL` renders once.
|
|
193
184
|
const fixedMembers = role.fixedMembers ?? [];
|
|
194
185
|
const fixedLower = new Set(fixedMembers.map((m) => m.toLowerCase()));
|
|
186
|
+
// The note beside those chips, and the lead of the refusal to add one: the
|
|
187
|
+
// server's own sentence (`roles-admin.service.ts`), sent with the roster so
|
|
188
|
+
// the page holds no copy of it to drift.
|
|
189
|
+
const fixedNote = role.fixedMembersNote ?? null;
|
|
195
190
|
|
|
196
191
|
// Members shown in the UI = server members minus any optimistically-removed,
|
|
197
192
|
// plus any optimistically-added not yet reflected in the server roster.
|
|
@@ -211,6 +206,10 @@ function RoleCard({
|
|
|
211
206
|
// the email is no longer in role.members, so drop it from pendingRemovals.
|
|
212
207
|
// Without this, a no-op remove would hide a still-present member forever.
|
|
213
208
|
useEffect(() => {
|
|
209
|
+
// Intentional reconcile-on-roster-change: the updaters return `prev`
|
|
210
|
+
// unchanged unless the server roster settled a pending entry, so this
|
|
211
|
+
// re-renders at most once per new roster.
|
|
212
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
214
213
|
setPendingRemovals((prev) => {
|
|
215
214
|
if (prev.size === 0) return prev;
|
|
216
215
|
const present = new Set(role.members.map((m) => m.toLowerCase()));
|
|
@@ -267,7 +266,7 @@ function RoleCard({
|
|
|
267
266
|
// (422 `fixed-deployment-admin`). Mirrored here so the refusal is instant
|
|
268
267
|
// and no optimistic chip flashes for a write that can never land.
|
|
269
268
|
if (fixedLower.has(lower)) {
|
|
270
|
-
setError(`${
|
|
269
|
+
setError(`${fixedNote ? `${fixedNote}. ` : ''}${email} is already an Admin.`);
|
|
271
270
|
setMemberEmail('');
|
|
272
271
|
return;
|
|
273
272
|
}
|
|
@@ -424,9 +423,9 @@ function RoleCard({
|
|
|
424
423
|
// No remove control, deliberately: the server configuration owns
|
|
425
424
|
// this membership. The note below the row says so, and
|
|
426
425
|
// `aria-describedby` ties it to every fixed chip.
|
|
427
|
-
aria-describedby={fixedNoteId}
|
|
426
|
+
aria-describedby={fixedNote ? fixedNoteId : undefined}
|
|
428
427
|
className="inline-flex max-w-full items-center gap-1.5 pl-1 pr-2 py-1 bg-sunken border border-line rounded-full text-xs text-ink"
|
|
429
|
-
title={
|
|
428
|
+
title={fixedNote ?? undefined}
|
|
430
429
|
>
|
|
431
430
|
<span className="w-5 h-5 shrink-0 rounded-full bg-ink-muted text-white text-[9px] font-semibold flex items-center justify-center">
|
|
432
431
|
{initials(email)}
|
|
@@ -471,9 +470,9 @@ function RoleCard({
|
|
|
471
470
|
</div>
|
|
472
471
|
|
|
473
472
|
{/* Why those chips have no X. Rendered once for the row, not per chip. */}
|
|
474
|
-
{fixedMembers.length > 0 && (
|
|
473
|
+
{fixedMembers.length > 0 && fixedNote && (
|
|
475
474
|
<p id={fixedNoteId} className="mt-1.5 text-xs text-ink-muted">
|
|
476
|
-
{
|
|
475
|
+
{fixedNote}.
|
|
477
476
|
</p>
|
|
478
477
|
)}
|
|
479
478
|
|