Identity e-mail notifications, ASF-hosting en testfixes (run 636) #11

Merged
Sluijsens merged 66 commits from feature/identity-email-notifications into master 2026-11-10 13:04:03 +01:00
9 changed files with 136 additions and 8 deletions
Showing only changes of commit 0932ee36b3 - Show all commits
+1
View File
@@ -11,3 +11,4 @@
| Feature | SlpSoftware Production API (slpsoftware-api) | ✅ Complete | feature/slpsoftware-api | Clients (new Api.SlpSoftware), Modules (new Offerings module + Tests), Core (CmsHost), CI/CD (retargeted to Api.SlpSoftware) | 2026-08-02 |
| Feature | Andrea's site hosting (andreaslop-site-hosting) | 🟡 Operations (wacht op CI-proef en eerste test-deploy) | feature/andreaslop-site-hosting | Core (CmsHost, CSP, static content), Clients (new Api.AndreaSlopFotografie), Frontend (theme), CI/CD | 2026-11-06 |
| Bug | [cms-admin-nine-points](bugs/cms-admin-nine-points/bug-fix.md) | ✅ Complete (wacht op goedkeuring ASF test) | feature/andreaslop-site-hosting | Core (auth, invitations), Identity, Availability, Frontend | 2026-11-08 |
| Bug | [invitation-delete-and-lifetime](bugs/invitation-delete-and-lifetime/bug-fix.md) | ✅ Complete (wacht op goedkeuring ASF test) | feature/andreaslop-site-hosting | Core (invitations), Identity, Frontend | 2026-11-08 |
@@ -0,0 +1,55 @@
# Bug Fix: pending invitations cannot be removed; invitation lifetime not configurable
- **Slug**: invitation-delete-and-lifetime
- **Status**: Complete (pending ASF test approval by Bryan)
- **Issue**: None (relayed by session "CMS & API" from Bryan, 2026-11-08)
- **Branch**: feature/andreaslop-site-hosting
- **Started**: 2026-11-08
- **Documentation Language**: English
- **Conversation Language**: Dutch (user language)
## Report
A. An invited but not yet activated user cannot be deleted.
B. The activation lifetime is too short; wanted: 24 hours, configurable (Identity option), no second place with another duration.
C. "Nieuwe activatiecode aanvragen" does nothing, no mails are sent (analysis only, nothing built without Bryan's go).
## Root Cause
**A.** The delete path itself works (`DELETE Users/{id}` falls back to `DeleteInvitationByIdAsync`, the row is removed and the token stops working). Two causes made it unreachable:
1. `GetAllPendingInvitationsAsync` listed only unexpired invitations. An invitation that was not activated in time disappeared from the list: invisible, so impossible to remove.
2. The Delete action was Owner-only in the UI. An Administrator (who can invite) saw no Delete action on a pending invitation.
The cause could not be confirmed against Bryan's actual session; both are real and fixed.
**B.** One place, hardcoded: `InvitationService.CreateInvitationAsync` used `AddDays(1)` (already 24 hours). No other duration exists in backend or frontend texts (no text names the duration). If Bryan saw a shorter effective time, the likely suspects are the unconfigurable value and the "expired" screen being shown for withdrawn links too; a database time-zone effect on the `datetime` column (DateTimeOffset stored without offset) cannot be excluded from here and needs a look at a real row on the test host.
**C.** See the analysis sent to the peer: there is no mail system anywhere (no SMTP/provider/sender code or config); the button on the invite-error page only navigates to `/`.
## The Fix
- `InvitationSettings` (`Identity:Invitation:ExpiryHours`, default 24, validated 1..720, `ValidateOnStart`); `InvitationService` uses it.
- `GetAllPendingInvitationsAsync` includes expired invitations (`PendingInvitationInfo.IsExpired`); `UserDto.InvitationExpired`; expired rows have no invite link. UI: status "Uitnodiging verlopen", no copy-link action, still removable.
- UI: an Administrator may withdraw a pending invitation for a plain User (same reach as assigning that role); account deletion stays Owner-only.
- Invite-error page: neutral title "Link ongeldig of verlopen" (it used the "system setup required" text) and text that covers expired, withdrawn and unknown links.
**Left unchanged, reported**: `DELETE Users/{id}` has no role hierarchy: an Administrator calling the API directly can delete an Owner or another Administrator (only the last-Owner rule protects). Pre-existing; needs a decision before changing.
## Verification
**Path used**: Automated test framework
- Revocation really invalidates: delete -> `ValidateInvitationAsync` false and `CompleteInvitationAsync` throws Unauthorized, no user created.
- Expired invitation is listed with `IsExpired` and can be deleted; controller returns `InvitationExpired` and no link for it.
- Lifetime: default 24 h, configured 72 h, config binding default/48, out-of-range values (0, -5, 721) rejected.
- Frontend: Owner and Administrator delete rules, expired row (label, no copy link, deletable), neutral invalid-link text.
- Core.Tests 379, Identity 58, Availability 82, Master 57, Offerings 57; frontend 322; tsc and eslint clean.
## Impact on SlpSoftware
No migration. Behaviour: expired invitations now appear in the users list (removable), lifetime configurable (default unchanged at 24 h; an invalid value fails startup), Administrator can withdraw User invitations, invite-error text changed.
## Result
- **PR(s)**: None
- **Commit(s)**: see branch history
- **Completed**: 2026-11-08
@@ -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",