From 55dcab121bb99b9a556806b8cc71a637bc27afe9 Mon Sep 17 00:00:00 2001 From: Sluijsens Date: Sun, 8 Nov 2026 14:36:10 +0100 Subject: [PATCH] Admin-teksten en merklogo: Weergavenaam, Wachtwoord wijzigen, Eerste account aanmaken, logo per thema Co-Authored-By: Claude Sonnet 5.5 --- aidlc-docs/active-features.md | 21 +++--- .../bugs/cms-admin-nine-points/bug-fix.md | 61 ++++++++++++++++++ .../src/components/layout/BrandLogo.test.tsx | 29 +++++++++ frontend/src/components/layout/BrandLogo.tsx | 36 +++++++++++ frontend/src/components/layout/MobileBar.tsx | 3 +- .../components/InviteUserDialog.test.tsx | 22 +++++++ .../components/InviteUserDialog.tsx | 5 +- .../profile/pages/ProfilePage.test.tsx | 18 ++++++ .../features/profile/pages/ProfilePage.tsx | 4 +- .../components/DeleteUserDialog.test.tsx | 39 +++++++++++ .../users/components/DeleteUserDialog.tsx | 7 +- frontend/src/i18n/locales/en/translation.json | 10 +-- frontend/src/i18n/locales/nl/translation.json | 10 +-- frontend/src/lib/brand.test.ts | 26 ++++++++ frontend/src/lib/brand.ts | 33 ++++++++++ frontend/themes/asf/logo-on-dark.png | Bin 0 -> 24767 bytes frontend/themes/asf/logo-on-light.png | Bin 0 -> 23369 bytes frontend/themes/resolveTheme.test.ts | 20 ++++++ frontend/themes/resolveTheme.ts | 11 +++- frontend/vite.config.ts | 20 +++++- 20 files changed, 350 insertions(+), 25 deletions(-) create mode 100644 aidlc-docs/bugs/cms-admin-nine-points/bug-fix.md create mode 100644 frontend/src/components/layout/BrandLogo.test.tsx create mode 100644 frontend/src/components/layout/BrandLogo.tsx create mode 100644 frontend/src/features/users/components/DeleteUserDialog.test.tsx create mode 100644 frontend/src/lib/brand.test.ts create mode 100644 frontend/src/lib/brand.ts create mode 100644 frontend/themes/asf/logo-on-dark.png create mode 100644 frontend/themes/asf/logo-on-light.png diff --git a/aidlc-docs/active-features.md b/aidlc-docs/active-features.md index c9d296f..69b2607 100644 --- a/aidlc-docs/active-features.md +++ b/aidlc-docs/active-features.md @@ -1,12 +1,13 @@ # Active Features -| Feature | Status | Branch | Affected Components | Session Start | -|---------|--------|--------|---------------------|---------------| -| SlpModularCms.Api Implementation (slp-modular-cms-api) | βœ… Complete | unknown | Core, Identity, Availability, Shell | 2026-06-07 | -| CMS Frontend (cms-frontend) | βœ… Complete | unknown | Frontend, Identity (Auth), Availability | 2026-06-16 | -| Master CMS Module (master-cms-module) | βœ… Complete | unknown | Modules, Availability | 2026-06-26 | -| Tech Debt Backlog (tech-debt-backlog) | πŸ”΅ Inception | unknown | Modules.Master, Frontend | 2026-07-01 | -| Local Dev Master/Slave Setup (local-dev-master-slave-setup) | βœ… Complete | unknown | Modules.Master, Api, Frontend | 2026-07-02 | -| Gitea Deployment Workflow (gitea-deployment-workflow) | 🟑 Operations (wacht op CI-proef en eerste test-deploy) | feature/gitea-deployment-workflow | CI/CD, Api (hosting/config), Core, Modules, Frontend (build), Docs | 2026-07-27 | -| 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 | -| 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 | +| Type | Name | Status | Branch | Affected Components | Session Start | +|------|------|--------|--------|---------------------|---------------| +| Feature | SlpModularCms.Api Implementation (slp-modular-cms-api) | βœ… Complete | unknown | Core, Identity, Availability, Shell | 2026-06-07 | +| Feature | CMS Frontend (cms-frontend) | βœ… Complete | unknown | Frontend, Identity (Auth), Availability | 2026-06-16 | +| Feature | Master CMS Module (master-cms-module) | βœ… Complete | unknown | Modules, Availability | 2026-06-26 | +| Feature | Tech Debt Backlog (tech-debt-backlog) | πŸ”΅ Inception | unknown | Modules.Master, Frontend | 2026-07-01 | +| Feature | Local Dev Master/Slave Setup (local-dev-master-slave-setup) | βœ… Complete | unknown | Modules.Master, Api, Frontend | 2026-07-02 | +| Feature | Gitea Deployment Workflow (gitea-deployment-workflow) | 🟑 Operations (wacht op CI-proef en eerste test-deploy) | feature/gitea-deployment-workflow | CI/CD, Api (hosting/config), Core, Modules, Frontend (build), Docs | 2026-07-27 | +| 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 | diff --git a/aidlc-docs/bugs/cms-admin-nine-points/bug-fix.md b/aidlc-docs/bugs/cms-admin-nine-points/bug-fix.md new file mode 100644 index 0000000..79e1fbc --- /dev/null +++ b/aidlc-docs/bugs/cms-admin-nine-points/bug-fix.md @@ -0,0 +1,61 @@ +# Bug Fix: CMS admin - nine points (names, labels, settings role, deactivation, invitations, brand logo) + +- **Slug**: cms-admin-nine-points +- **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 + +Nine points found by Bryan while using the ASF test admin. Not ASF-specific: all but 9 affect SlpSoftware too (shared Core/Identity/frontend). Points 2, 3, 8 are pure text changes and point 9 is a small addition; they are bundled here instead of a feature record because they need no design decision. Points 5 and 7 are real defects. + +## Root Cause + +| # | Cause | +|---|-------| +| 1, 6 | The invite page collects `name` and the frontend sends it, but `CompleteSetupRequest(Token, Password)` had no `Name` and `InvitationService.CompleteInvitationAsync` never set `ApplicationUser.DisplayName`. `DisplayName` stays null; the API falls back to the e-mail address, so the profile page and the delete dialog show the e-mail ("info@x (info@x)"). The first owner (setup flow) was never affected: `SetupService` stores the name. | +| 5 | `AddJwtBearer` validated signature/lifetime only. Nothing looked at `IsActive` or whether the user still exists, so a deactivated or deleted user kept full access (reads and writes) until the access token expired (`JwtSettings:ExpiryMinutes`, 60 by default). `RefreshTokenAsync` also did not check `IsActive`, so a deactivated user could mint new access tokens. | +| 7 | `CreateInvitationAsync` looked for an invitation by e-mail without filtering on accepted/expired. Accepting an invitation keeps the row (`IsAccepted = true`), and `DeleteUser` removed only non-accepted invitations. So the address was blocked forever. The resulting `InvitationOrUserAlreadyExistsException` was not mapped in `GlobalExceptionHandler`, so it became a 500 with the generic "Er is iets misgegaan". | +| 4 | "Site-instellingen" = `/settings` (availability). `AvailabilityController.UpdateStatus` required `OwnerOnly`; frontend route guard and sidebar item were Owner-only. Reading status is anonymous. | + +**Confirmed with user**: root causes were sent to "CMS & API" (which relays Bryan) before fixing; the order itself covers the fixes. + +## The Fix + +- `Core/Identity/Authorization/ActiveUserTokenValidation.cs` (new): `OnTokenValidated` check against the database (user exists and `IsActive`), no cache; `UseCmsTokenValidation` is the single place the bearer scheme is configured. Wired in `ServiceCollectionExtensions`. +- `AuthService.RefreshTokenAsync`: inactive user -> refresh token revoked, 401. (Deleting a user cascades its refresh tokens.) +- `InvitationService`: `CompleteInvitationAsync(token, password, name)` stores a trimmed `DisplayName`; `CreateInvitationAsync` distinguishes "user exists" and "open invitation exists" (specific Dutch messages) and replaces stale (expired / accepted-but-user-gone) invitations; `DeleteInvitationsByEmailAsync` (renamed) removes all invitations of an address, also accepted ones, when a user is deleted. +- `GlobalExceptionHandler`: `InvitationOrUserAlreadyExistsException` -> 409 with its Dutch message as `detail`. +- `CompleteSetupRequest` gets an optional `Name`; `InvitationController` passes it. +- `AvailabilityController.UpdateStatus`: `AdminOnly`; frontend `/settings` route and sidebar item allow Administrator. +- Frontend: "Volledige naam" -> "Weergavenaam" (profile, setup, invite; en: "Display name"), setup title "Eerste account aanmaken", profile card "Wachtwoord wijzigen" (new key `profile.securityTitle`), delete dialog shows only the e-mail when the account has no name, invite dialog shows the server's 409 message. +- Brand logo: `lib/brand.ts` (`getBrand`, one place; later replaceable by site settings), `components/layout/BrandLogo.tsx` (logo for light and dark mode, fallback = app name with dot), used by `Sidebar` and `MobileBar`. Theme folder gets `logo-on-light.png` / `logo-on-dark.png` (copied read-only from the website's `logo-dark.png` / `logo-light.png`; website repo untouched). `resolveTheme` returns `logo` (both files or none); the Vite plugin emits `brand-logo-on-*.png`; default build unchanged (no files emitted). + +**Why this and not something else** +- Deactivation: a per-request DB lookup instead of a short token lifetime or a security stamp. It is the only option that is immediate for every endpoint without changing the token format; the cost is one indexed query per authenticated request. A cache was rejected because it would reopen the window. +- Invitations: no schema change or migration. The unique index is on `Token` only; the blocking came from the logic, so fixing the logic also repairs existing rows in test databases (stale rows are ignored/replaced on the next invite). +- Existing accounts without a display name are not migrated; they can set it in the profile. + +## Verification + +**Path used**: Automated test framework + +**Before the fix**: `DeactivatedUserAccessTests` (real JwtBearer pipeline on TestServer + in-memory DB): with the check disabled 4 of 5 fail (deactivated GET/POST, deleted, unknown user were all served). + +**After the fix**: Core.Tests 369 (incl. `DeactivatedUserAccessTests` 5, refresh for a deactivated user, 7 new invitation scenarios: name stored, blank name, accepted+deleted re-invite, expired replaced, open-invitation message, existing-user message, delete removes accepted), Identity 57, Availability 82, Master 57, Offerings 57; frontend 319 (Vitest) + eslint + tsc clean; `VITE_THEME=asf` build emits the logo files, the default build none. Not run locally (no MariaDB): `Api.Tests` and `Api.AndreaSlopFotografie.Tests/HostPipelineTests` (CI runs them). + +## Impact on SlpSoftware and consequences + +- **Migrations: none** (points 5 and 7). +- **Behaviour changes (shared code)**: a deactivated or deleted user now gets 401 on the next request (1 extra query per authenticated request); `POST Users/invite` conflicts return 409 with a specific message instead of 500; re-inviting an address after its user was deleted works; Administrator can change site availability; labels/titles changed; no logo unless a theme ships one. +- **Left as is, inconsistent with point 4 (reported)**: `CmsInstanceController` (Master module) stays `OwnerOnly`, `/cms` stays Owner-only, assigning the Owner role stays Owner-only. On a master-controlled instance availability changes still answer 409 as before. +- **Known, not changed**: the role claim is baked into the access token, so a role downgrade also applies only after expiry (same family as point 5, not asked). `AdminTokenValidator` (availability gate bypass) does not check `IsActive`; protected endpoints do via the new check, so it cannot expose data. + +## Result + +- **PR(s)**: None +- **Commit(s)**: see branch history after this entry +- **Completed**: 2026-11-08 diff --git a/frontend/src/components/layout/BrandLogo.test.tsx b/frontend/src/components/layout/BrandLogo.test.tsx new file mode 100644 index 0000000..6375979 --- /dev/null +++ b/frontend/src/components/layout/BrandLogo.test.tsx @@ -0,0 +1,29 @@ +import { describe, expect, it } from 'vitest'; +import { screen } from '@testing-library/react'; +import { renderWithProviders } from '@/test/utils'; +import { BrandLogo } from '@/components/layout/BrandLogo'; + +describe('BrandLogo', () => { + it('falls back to the application name with its dot when the site has no logo', () => { + renderWithProviders(); + + expect(screen.getByTestId('brand-fallback')).toHaveTextContent('SlpModularCms'); + expect(screen.queryByTestId('brand-logo')).not.toBeInTheDocument(); + }); + + it('shows the default (unthemed) admin the same way', () => { + renderWithProviders(); + + expect(screen.getByTestId('brand-fallback')).toBeInTheDocument(); + }); + + it('draws the logo for both colour modes, named for screen readers', () => { + renderWithProviders(); + + const images = screen.getAllByRole('img', { hidden: true }); + expect(images).toHaveLength(2); + expect(images.map((i) => i.getAttribute('src'))).toEqual(['/admin/l.png', '/admin/d.png']); + images.forEach((i) => expect(i).toHaveAttribute('alt', 'SlpModularCms')); + expect(screen.queryByTestId('brand-fallback')).not.toBeInTheDocument(); + }); +}); diff --git a/frontend/src/components/layout/BrandLogo.tsx b/frontend/src/components/layout/BrandLogo.tsx new file mode 100644 index 0000000..841a5eb --- /dev/null +++ b/frontend/src/components/layout/BrandLogo.tsx @@ -0,0 +1,36 @@ +import { useTranslation } from 'react-i18next'; +import { cn } from '@/lib/utils'; +import { getBrand } from '@/lib/brand'; +import type { BrandLogo as BrandLogoFiles } from '@/lib/brand'; + +interface BrandLogoProps { + /** Overrides the site brand; mainly for tests and, later, a logo loaded from site settings. */ + logo?: BrandLogoFiles | null; + className?: string; +} + +/** + * The site's logo, or, when it has none, the application name with its dot (what the admin always + * showed). The single place the admin draws the brand: do not hardcode it elsewhere. + */ +export function BrandLogo({ logo, className }: BrandLogoProps) { + const { t } = useTranslation(); + const resolved = logo === undefined ? getBrand().logo : logo; + const name = t('common.appName'); + + if (resolved === null) { + return ( +
+
+ ); + } + + return ( +
+ {name} + {name} +
+ ); +} diff --git a/frontend/src/components/layout/MobileBar.tsx b/frontend/src/components/layout/MobileBar.tsx index cfdc128..d8f0b3e 100644 --- a/frontend/src/components/layout/MobileBar.tsx +++ b/frontend/src/components/layout/MobileBar.tsx @@ -1,5 +1,6 @@ import { Menu } from 'lucide-react'; import { useTranslation } from 'react-i18next'; +import { BrandLogo } from './BrandLogo'; interface MobileBarProps { onMenuOpen: () => void; @@ -22,7 +23,7 @@ export function MobileBar({ onMenuOpen }: MobileBarProps) { > - {t('common.appName')} + ); } diff --git a/frontend/src/features/invitation/components/InviteUserDialog.test.tsx b/frontend/src/features/invitation/components/InviteUserDialog.test.tsx index 865d686..f18fd64 100644 --- a/frontend/src/features/invitation/components/InviteUserDialog.test.tsx +++ b/frontend/src/features/invitation/components/InviteUserDialog.test.tsx @@ -81,6 +81,28 @@ describe('InviteUserDialog', () => { expect(await screen.findByTestId('form-error-banner')).toBeInTheDocument(); }); + it('shows the specific conflict message instead of a generic error', async () => { + server.use( + http.post(`${API_BASE}/api/v1/Users/invite`, () => + HttpResponse.json( + { status: 409, title: 'Conflict', detail: 'Er staat al een openstaande uitnodiging voor dit e-mailadres.' }, + { status: 409 }, + ), + ), + ); + await openDialog(); + + await userEvent.type(screen.getByTestId('invite-dialog-email'), 'dup@example.com'); + await userEvent.click(screen.getByTestId('invite-dialog-role')); + const opts = await screen.findAllByRole('option'); + await userEvent.click(opts.find((o) => o.textContent === 'User')!); + await userEvent.click(screen.getByTestId('invite-dialog-submit')); + + expect(await screen.findByTestId('form-error-banner')).toHaveTextContent( + 'Er staat al een openstaande uitnodiging voor dit e-mailadres.', + ); + }); + it('resets to step 1 when dialog is closed and reopened', async () => { await openDialog(); await userEvent.type(screen.getByTestId('invite-dialog-email'), 'test@example.com'); diff --git a/frontend/src/features/invitation/components/InviteUserDialog.tsx b/frontend/src/features/invitation/components/InviteUserDialog.tsx index 636f130..05c2f12 100644 --- a/frontend/src/features/invitation/components/InviteUserDialog.tsx +++ b/frontend/src/features/invitation/components/InviteUserDialog.tsx @@ -24,7 +24,7 @@ import { FormErrorBanner } from '@/components/ui/FormErrorBanner'; import { FieldError } from '@/components/ui/FieldError'; import { useInviteUser } from '@/features/users/services/useUsers'; import { inviteUserSchema, type InviteUserFormData } from '@/features/users/schemas/users'; -import { NetworkError } from '@/lib/api-client'; +import { NetworkError, ProblemDetailsError } from '@/lib/api-client'; interface InviteUserDialogProps { open: boolean; @@ -40,6 +40,9 @@ export function InviteUserDialog({ open, onOpenChange }: InviteUserDialogProps) onError: (err) => { if (err instanceof NetworkError) { setServerError(t('errors.network')); + } else if (err instanceof ProblemDetailsError && err.status === 409 && err.problem.detail) { + // The server words the conflict (user exists / open invitation exists) in Dutch. + setServerError(err.problem.detail); } else { setServerError(t('errors.generic')); } diff --git a/frontend/src/features/profile/pages/ProfilePage.test.tsx b/frontend/src/features/profile/pages/ProfilePage.test.tsx index 2a201a2..ee7df24 100644 --- a/frontend/src/features/profile/pages/ProfilePage.test.tsx +++ b/frontend/src/features/profile/pages/ProfilePage.test.tsx @@ -6,6 +6,7 @@ import { renderApp, mockAuthenticated, mockGuest } from '@/test/utils'; import { server } from '@/mocks/server'; import { API_BASE } from '@/features/auth/mocks/fixtures'; import { _resetSetupStatusCache } from '@/router'; +import i18n from '@/i18n/config'; beforeEach(() => { _resetSetupStatusCache(); @@ -22,6 +23,23 @@ describe('ProfilePage', () => { expect(screen.getByTestId('profile-role-badge')).toBeInTheDocument(); }); + it('titles the password card with what it does, not "Security"', async () => { + mockAuthenticated(); + renderApp('/profile'); + + const title = await screen.findByTestId('profile-security-title', {}, { timeout: 10000 }); + expect(title).toHaveTextContent(i18n.t('profile.securityTitle')); + expect(title).not.toHaveTextContent('Security'); + expect(i18n.t('profile.securityTitle', { lng: 'nl' })).toBe('Wachtwoord wijzigen'); + }); + + it('labels the name field "Weergavenaam" in Dutch', () => { + expect(i18n.t('profile.name', { lng: 'nl' })).toBe('Weergavenaam'); + expect(i18n.t('inviteComplete.nameLabel', { lng: 'nl' })).toBe('Weergavenaam'); + expect(i18n.t('setup.nameLabel', { lng: 'nl' })).toBe('Weergavenaam'); + expect(i18n.t('setup.title', { lng: 'nl' })).toBe('Eerste account aanmaken'); + }); + it('pre-fills name and email from authenticated user', async () => { mockAuthenticated(); renderApp('/profile'); diff --git a/frontend/src/features/profile/pages/ProfilePage.tsx b/frontend/src/features/profile/pages/ProfilePage.tsx index 92d5b17..797d257 100644 --- a/frontend/src/features/profile/pages/ProfilePage.tsx +++ b/frontend/src/features/profile/pages/ProfilePage.tsx @@ -265,7 +265,9 @@ export function ProfilePage() { {/* Security card */} - Security + + {t('profile.securityTitle')} +