From 0932ee36b32eaa05877fbb31d53b798412aaa85d Mon Sep 17 00:00:00 2001 From: Sluijsens Date: Sun, 8 Nov 2026 15:49:33 +0100 Subject: [PATCH] Gebruikerslijst: verlopen uitnodiging tonen, Beheerder mag uitnodiging intrekken, neutrale tekst bij ongeldige link Co-Authored-By: Claude Sonnet 5.5 --- aidlc-docs/active-features.md | 1 + .../invitation-delete-and-lifetime/bug-fix.md | 55 +++++++++++++++++ .../pages/InviteCompletePage.test.tsx | 4 ++ .../invitation/pages/InviteCompletePage.tsx | 2 +- .../features/users/pages/UsersPage.test.tsx | 59 ++++++++++++++++++- .../src/features/users/pages/UsersPage.tsx | 11 +++- frontend/src/features/users/services/types.ts | 2 + frontend/src/i18n/locales/en/translation.json | 4 +- frontend/src/i18n/locales/nl/translation.json | 6 +- 9 files changed, 136 insertions(+), 8 deletions(-) create mode 100644 aidlc-docs/bugs/invitation-delete-and-lifetime/bug-fix.md diff --git a/aidlc-docs/active-features.md b/aidlc-docs/active-features.md index 69b2607..c08dbb0 100644 --- a/aidlc-docs/active-features.md +++ b/aidlc-docs/active-features.md @@ -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 | diff --git a/aidlc-docs/bugs/invitation-delete-and-lifetime/bug-fix.md b/aidlc-docs/bugs/invitation-delete-and-lifetime/bug-fix.md new file mode 100644 index 0000000..3efe363 --- /dev/null +++ b/aidlc-docs/bugs/invitation-delete-and-lifetime/bug-fix.md @@ -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 diff --git a/frontend/src/features/invitation/pages/InviteCompletePage.test.tsx b/frontend/src/features/invitation/pages/InviteCompletePage.test.tsx index ef46250..699e1d9 100644 --- a/frontend/src/features/invitation/pages/InviteCompletePage.test.tsx +++ b/frontend/src/features/invitation/pages/InviteCompletePage.test.tsx @@ -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 () => { diff --git a/frontend/src/features/invitation/pages/InviteCompletePage.tsx b/frontend/src/features/invitation/pages/InviteCompletePage.tsx index 285cc30..d1da117 100644 --- a/frontend/src/features/invitation/pages/InviteCompletePage.tsx +++ b/frontend/src/features/invitation/pages/InviteCompletePage.tsx @@ -110,7 +110,7 @@ export function InviteCompletePage() {
- {t('errors.setupRequired')} + {t('inviteComplete.invalidTitle')}

diff --git a/frontend/src/features/users/pages/UsersPage.test.tsx b/frontend/src/features/users/pages/UsersPage.test.tsx index a49689a..861dcfe 100644 --- a/frontend/src/features/users/pages/UsersPage.test.tsx +++ b/frontend/src/features/users/pages/UsersPage.test.tsx @@ -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 }))); diff --git a/frontend/src/features/users/pages/UsersPage.tsx b/frontend/src/features/users/pages/UsersPage.tsx index 65d1ae4..5dacbb2 100644 --- a/frontend/src/features/users/pages/UsersPage.tsx +++ b/frontend/src/features/users/pages/UsersPage.tsx @@ -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')} - {user.invitationPending && ( + {user.invitationPending && user.inviteLink && ( <>