Files
slp-modular-cms/aidlc-docs/bugs/cms-admin-nine-points/bug-fix.md
T

6.8 KiB

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