Gebruikerslijst: verlopen uitnodiging tonen, Beheerder mag uitnodiging intrekken, neutrale tekst bij ongeldige link
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -28,6 +28,10 @@ describe('InviteCompletePage', () => {
|
||||
|
||||
expect(await screen.findByTestId('invite-error')).toBeInTheDocument();
|
||||
expect(screen.queryByTestId('invite-name-input')).not.toBeInTheDocument();
|
||||
// Neutral wording: expired, withdrawn and unknown links look the same to the visitor, and the
|
||||
// card must not talk about "system setup".
|
||||
expect(screen.getByText('Link invalid or expired')).toBeInTheDocument();
|
||||
expect(screen.queryByText(/setup required/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows an error state for a used token', async () => {
|
||||
|
||||
@@ -110,7 +110,7 @@ export function InviteCompletePage() {
|
||||
<div className="flex min-h-svh items-center justify-center bg-secondary/40 p-4" data-testid="invite-error">
|
||||
<Card className="w-full max-w-sm">
|
||||
<CardHeader>
|
||||
<CardTitle className="text-destructive">{t('errors.setupRequired')}</CardTitle>
|
||||
<CardTitle className="text-destructive">{t('inviteComplete.invalidTitle')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
|
||||
@@ -4,7 +4,7 @@ import userEvent from '@testing-library/user-event';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { renderApp, mockAuthenticated } from '@/test/utils';
|
||||
import { server } from '@/mocks/server';
|
||||
import { API_BASE } from '@/features/auth/mocks/fixtures';
|
||||
import { API_BASE, makeAuthResponse, mockUser } from '@/features/auth/mocks/fixtures';
|
||||
import { getMockUsers } from '@/features/users/mocks/handlers';
|
||||
import { _resetSetupStatusCache } from '@/router';
|
||||
|
||||
@@ -57,6 +57,63 @@ describe('UsersPage', () => {
|
||||
expect(screen.getByTestId(`user-copy-link-${pendingUser.id}`)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('lets the Owner delete a pending invitation', async () => {
|
||||
mockAuthenticated();
|
||||
renderApp('/users');
|
||||
|
||||
await screen.findByTestId('users-table');
|
||||
const pendingUser = getMockUsers().find((u) => u.invitationPending)!;
|
||||
await userEvent.click(screen.getByTestId(`user-actions-${pendingUser.id}`));
|
||||
|
||||
expect(screen.getByTestId(`user-delete-${pendingUser.id}`)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('lets an Administrator withdraw a pending invitation for a User, but not delete accounts', async () => {
|
||||
server.use(
|
||||
http.post(`${API_BASE}/api/v1/auth/refresh`, () =>
|
||||
HttpResponse.json(makeAuthResponse({ user: { ...mockUser, role: 'Administrator', name: 'Test Admin' } })),
|
||||
),
|
||||
);
|
||||
renderApp('/users');
|
||||
|
||||
await screen.findByTestId('users-table');
|
||||
const pendingUser = getMockUsers().find((u) => u.invitationPending)!;
|
||||
await userEvent.click(screen.getByTestId(`user-actions-${pendingUser.id}`));
|
||||
expect(screen.getByTestId(`user-delete-${pendingUser.id}`)).toBeInTheDocument();
|
||||
await userEvent.keyboard('{Escape}');
|
||||
|
||||
const account = getMockUsers().find((u) => !u.invitationPending && u.role === 'Administrator')!;
|
||||
expect(screen.queryByTestId(`user-delete-${account.id}`)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('lists an expired invitation as expired, removable, without a copy-link action', async () => {
|
||||
mockAuthenticated();
|
||||
server.use(
|
||||
http.get(USERS_URL, () =>
|
||||
HttpResponse.json([
|
||||
{
|
||||
id: '44444444-4444-4444-4444-444444444444',
|
||||
email: 'late@example.com',
|
||||
name: 'late@example.com',
|
||||
role: 'User',
|
||||
isActive: true,
|
||||
createdAt: '2026-01-01T00:00:00.000Z',
|
||||
invitationPending: true,
|
||||
invitationExpired: true,
|
||||
inviteLink: null,
|
||||
},
|
||||
]),
|
||||
),
|
||||
);
|
||||
renderApp('/users');
|
||||
|
||||
const row = await screen.findByTestId('user-row-44444444-4444-4444-4444-444444444444');
|
||||
expect(within(row).getByText('Invitation expired')).toBeInTheDocument();
|
||||
await userEvent.click(screen.getByTestId('user-actions-44444444-4444-4444-4444-444444444444'));
|
||||
expect(screen.getByTestId('user-delete-44444444-4444-4444-4444-444444444444')).toBeInTheDocument();
|
||||
expect(screen.queryByTestId('user-copy-link-44444444-4444-4444-4444-444444444444')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows an error message when the API fails', async () => {
|
||||
mockAuthenticated();
|
||||
server.use(http.get(USERS_URL, () => HttpResponse.json({}, { status: 500 })));
|
||||
|
||||
@@ -49,6 +49,7 @@ function statusBadgeVariant(user: UserListItem) {
|
||||
}
|
||||
|
||||
function statusLabel(user: UserListItem, t: (key: string) => string) {
|
||||
if (user.invitationPending && user.invitationExpired) return t('users.status.inviteExpired');
|
||||
if (user.invitationPending) return t('users.status.pendingInvite');
|
||||
if (!user.isActive) return t('users.status.inactive');
|
||||
return t('users.status.active');
|
||||
@@ -93,10 +94,14 @@ export function UsersPage() {
|
||||
const canToggleActive = (user: UserListItem) =>
|
||||
isOwnerAction(user) && !user.invitationPending;
|
||||
|
||||
const canDelete = (user: UserListItem) => isOwnerAction(user);
|
||||
// An Administrator may withdraw an open invitation for a plain User (the same reach as assigning
|
||||
// that role); removing accounts stays with the Owner.
|
||||
const canDelete = (user: UserListItem) =>
|
||||
isOwnerAction(user) ||
|
||||
(currentUser?.role === 'Administrator' && user.invitationPending && user.role === 'User');
|
||||
|
||||
const hasAnyActions = (user: UserListItem) =>
|
||||
user.invitationPending ||
|
||||
Boolean(user.invitationPending) ||
|
||||
availableRolesFor(user).length > 0 ||
|
||||
canToggleActive(user) ||
|
||||
canDelete(user);
|
||||
@@ -270,7 +275,7 @@ export function UsersPage() {
|
||||
{t('users.table.actions')}
|
||||
</DropdownMenuLabel>
|
||||
|
||||
{user.invitationPending && (
|
||||
{user.invitationPending && user.inviteLink && (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
|
||||
@@ -4,6 +4,8 @@ export interface UserListItem extends User {
|
||||
createdAt: string;
|
||||
invitationPending: boolean;
|
||||
inviteLink: string | null;
|
||||
/** Pending invitation whose link has expired: still listed so it can be removed. */
|
||||
invitationExpired?: boolean;
|
||||
}
|
||||
|
||||
export interface InviteUserPayload {
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
"confirmPasswordLabel": "Confirm password",
|
||||
"submitButton": "Complete setup",
|
||||
"loadingMessage": "Validating your invitation…",
|
||||
"invalidTitle": "Link invalid or expired",
|
||||
"invalidTokenMessage": "This invitation link has expired or is invalid.",
|
||||
"requestNewInvitationLink": "Request a new invitation link",
|
||||
"successMessage": "Account setup complete. You can now sign in."
|
||||
@@ -96,7 +97,8 @@
|
||||
"status": {
|
||||
"active": "Active",
|
||||
"inactive": "Inactive",
|
||||
"pendingInvite": "Pending invite"
|
||||
"pendingInvite": "Pending invite",
|
||||
"inviteExpired": "Invitation expired"
|
||||
},
|
||||
"actions": {
|
||||
"copyInviteLink": "Copy invite link",
|
||||
|
||||
@@ -58,7 +58,8 @@
|
||||
"confirmPasswordLabel": "Wachtwoord bevestigen",
|
||||
"submitButton": "Setup voltooien",
|
||||
"loadingMessage": "Uitnodiging valideren…",
|
||||
"invalidTokenMessage": "Deze uitnodigingslink is verlopen of ongeldig.",
|
||||
"invalidTitle": "Link ongeldig of verlopen",
|
||||
"invalidTokenMessage": "Deze uitnodigingslink is verlopen, ingetrokken of ongeldig. Vraag de beheerder om een nieuwe uitnodiging.",
|
||||
"requestNewInvitationLink": "Vraag een nieuwe uitnodigingslink aan",
|
||||
"successMessage": "Account-setup voltooid. Je kunt nu inloggen."
|
||||
},
|
||||
@@ -96,7 +97,8 @@
|
||||
"status": {
|
||||
"active": "Actief",
|
||||
"inactive": "Inactief",
|
||||
"pendingInvite": "Uitnodiging in behandeling"
|
||||
"pendingInvite": "Uitnodiging in behandeling",
|
||||
"inviteExpired": "Uitnodiging verlopen"
|
||||
},
|
||||
"actions": {
|
||||
"copyInviteLink": "Uitnodigingslink kopiëren",
|
||||
|
||||
Reference in New Issue
Block a user