Admin-teksten en merklogo: Weergavenaam, Wachtwoord wijzigen, Eerste account aanmaken, logo per thema
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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 |
|
||||
|
||||
@@ -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
|
||||
@@ -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(<BrandLogo logo={null} />);
|
||||
|
||||
expect(screen.getByTestId('brand-fallback')).toHaveTextContent('SlpModularCms');
|
||||
expect(screen.queryByTestId('brand-logo')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows the default (unthemed) admin the same way', () => {
|
||||
renderWithProviders(<BrandLogo />);
|
||||
|
||||
expect(screen.getByTestId('brand-fallback')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('draws the logo for both colour modes, named for screen readers', () => {
|
||||
renderWithProviders(<BrandLogo logo={{ onLight: '/admin/l.png', onDark: '/admin/d.png' }} />);
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
@@ -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 (
|
||||
<div className={cn('flex items-center gap-2', className)} data-testid="brand-fallback">
|
||||
<span className="h-3 w-3 rounded-full bg-primary" aria-hidden="true" />
|
||||
<span className="text-lg font-semibold">{name}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={cn('flex items-center', className)} data-testid="brand-logo">
|
||||
<img src={resolved.onLight} alt={name} className="h-10 w-auto dark:hidden" />
|
||||
<img src={resolved.onDark} alt={name} className="hidden h-10 w-auto dark:block" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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) {
|
||||
>
|
||||
<Menu className="size-5" />
|
||||
</button>
|
||||
<span className="font-semibold">{t('common.appName')}</span>
|
||||
<BrandLogo className="[&_img]:h-8 [&_span]:text-base" />
|
||||
</header>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -265,7 +265,9 @@ export function ProfilePage() {
|
||||
{/* Security card */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">Security</CardTitle>
|
||||
<CardTitle className="text-base" data-testid="profile-security-title">
|
||||
{t('profile.securityTitle')}
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Button
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { screen } from '@testing-library/react';
|
||||
import { renderWithProviders } from '@/test/utils';
|
||||
import { DeleteUserDialog } from '@/features/users/components/DeleteUserDialog';
|
||||
import type { UserListItem } from '@/features/users/services/types';
|
||||
|
||||
function userItem(overrides: Partial<UserListItem>): UserListItem {
|
||||
return {
|
||||
id: '22222222-2222-2222-2222-222222222222',
|
||||
email: 'info@x.nl',
|
||||
name: 'Bryan',
|
||||
role: 'User',
|
||||
isActive: true,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
invitationPending: false,
|
||||
inviteLink: null,
|
||||
...overrides,
|
||||
} as UserListItem;
|
||||
}
|
||||
|
||||
function renderDialog(user: UserListItem) {
|
||||
return renderWithProviders(
|
||||
<DeleteUserDialog user={user} open onOpenChange={vi.fn()} onConfirm={vi.fn()} isPending={false} />,
|
||||
);
|
||||
}
|
||||
|
||||
describe('DeleteUserDialog', () => {
|
||||
it('names the person and their e-mail address', async () => {
|
||||
renderDialog(userItem({}));
|
||||
expect(await screen.findByTestId('delete-user-dialog')).toHaveTextContent('Bryan (info@x.nl)');
|
||||
});
|
||||
|
||||
it('does not repeat the address when the account has no display name', async () => {
|
||||
renderDialog(userItem({ name: 'info@x.nl' }));
|
||||
const text = (await screen.findByTestId('delete-user-dialog')).textContent ?? '';
|
||||
expect(text).toContain('info@x.nl');
|
||||
expect(text).not.toContain('info@x.nl (info@x.nl)');
|
||||
});
|
||||
});
|
||||
@@ -28,6 +28,9 @@ export function DeleteUserDialog({
|
||||
const { t } = useTranslation();
|
||||
if (!user) return null;
|
||||
|
||||
// Accounts without a display name come back with the e-mail address as their name; "a@b (a@b)" is noise.
|
||||
const hasName = user.name.trim() !== '' && user.name.toLowerCase() !== user.email.toLowerCase();
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-md" data-testid="delete-user-dialog">
|
||||
@@ -36,7 +39,9 @@ export function DeleteUserDialog({
|
||||
<DialogDescription>
|
||||
{user.invitationPending
|
||||
? t('users.delete.descriptionPending', { email: user.email })
|
||||
: t('users.delete.description', { name: user.name, email: user.email })}
|
||||
: hasName
|
||||
? t('users.delete.description', { name: user.name, email: user.email })
|
||||
: t('users.delete.descriptionNoName', { email: user.email })}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter className="gap-2">
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
}
|
||||
},
|
||||
"setup": {
|
||||
"title": "System Setup",
|
||||
"nameLabel": "Full name",
|
||||
"title": "Create first account",
|
||||
"nameLabel": "Display name",
|
||||
"emailLabel": "Email",
|
||||
"passwordLabel": "Password",
|
||||
"confirmPasswordLabel": "Confirm password",
|
||||
@@ -53,7 +53,7 @@
|
||||
"inviteComplete": {
|
||||
"title": "Complete your account",
|
||||
"emailLabel": "Email",
|
||||
"nameLabel": "Full name",
|
||||
"nameLabel": "Display name",
|
||||
"passwordLabel": "Password",
|
||||
"confirmPasswordLabel": "Confirm password",
|
||||
"submitButton": "Complete setup",
|
||||
@@ -113,6 +113,7 @@
|
||||
"delete": {
|
||||
"title": "Delete user",
|
||||
"description": "Are you sure you want to delete {{name}} ({{email}})? This action cannot be undone.",
|
||||
"descriptionNoName": "Are you sure you want to delete {{email}}? This action cannot be undone.",
|
||||
"descriptionPending": "Are you sure you want to delete the pending invitation for {{email}}? This action cannot be undone.",
|
||||
"confirmButton": "Delete",
|
||||
"success": "{{name}} has been deleted."
|
||||
@@ -151,12 +152,13 @@
|
||||
},
|
||||
"profile": {
|
||||
"title": "My Profile",
|
||||
"name": "Full name",
|
||||
"name": "Display name",
|
||||
"email": "Email address",
|
||||
"role": "Role",
|
||||
"save": "Save changes",
|
||||
"saving": "Saving…",
|
||||
"saveSuccess": "Profile updated successfully",
|
||||
"securityTitle": "Change password",
|
||||
"changePassword": "Change password",
|
||||
"changePasswordDialog": {
|
||||
"title": "Change Password",
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
}
|
||||
},
|
||||
"setup": {
|
||||
"title": "Systeeminstallatie",
|
||||
"nameLabel": "Volledige naam",
|
||||
"title": "Eerste account aanmaken",
|
||||
"nameLabel": "Weergavenaam",
|
||||
"emailLabel": "E-mail",
|
||||
"passwordLabel": "Wachtwoord",
|
||||
"confirmPasswordLabel": "Wachtwoord bevestigen",
|
||||
@@ -53,7 +53,7 @@
|
||||
"inviteComplete": {
|
||||
"title": "Account voltooien",
|
||||
"emailLabel": "E-mail",
|
||||
"nameLabel": "Volledige naam",
|
||||
"nameLabel": "Weergavenaam",
|
||||
"passwordLabel": "Wachtwoord",
|
||||
"confirmPasswordLabel": "Wachtwoord bevestigen",
|
||||
"submitButton": "Setup voltooien",
|
||||
@@ -113,6 +113,7 @@
|
||||
"delete": {
|
||||
"title": "Gebruiker verwijderen",
|
||||
"description": "Weet je zeker dat je {{name}} ({{email}}) wilt verwijderen? Deze actie kan niet ongedaan worden gemaakt.",
|
||||
"descriptionNoName": "Weet je zeker dat je {{email}} wilt verwijderen? Deze actie kan niet ongedaan worden gemaakt.",
|
||||
"descriptionPending": "Weet je zeker dat je de openstaande uitnodiging voor {{email}} wilt verwijderen? Deze actie kan niet ongedaan worden gemaakt.",
|
||||
"confirmButton": "Verwijderen",
|
||||
"success": "{{name}} is verwijderd."
|
||||
@@ -151,12 +152,13 @@
|
||||
},
|
||||
"profile": {
|
||||
"title": "Mijn profiel",
|
||||
"name": "Volledige naam",
|
||||
"name": "Weergavenaam",
|
||||
"email": "E-mailadres",
|
||||
"role": "Rol",
|
||||
"save": "Wijzigingen opslaan",
|
||||
"saving": "Opslaan…",
|
||||
"saveSuccess": "Profiel succesvol bijgewerkt",
|
||||
"securityTitle": "Wachtwoord wijzigen",
|
||||
"changePassword": "Wachtwoord wijzigen",
|
||||
"changePasswordDialog": {
|
||||
"title": "Wachtwoord wijzigen",
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { getBrand, themeLogo } from '@/lib/brand';
|
||||
|
||||
describe('themeLogo', () => {
|
||||
it('points at the emitted logo files under the app base path', () => {
|
||||
expect(themeLogo(true, '/admin/')).toEqual({
|
||||
onLight: '/admin/brand-logo-on-light.png',
|
||||
onDark: '/admin/brand-logo-on-dark.png',
|
||||
});
|
||||
});
|
||||
|
||||
it('tolerates a base without trailing slash and the dev root', () => {
|
||||
expect(themeLogo(true, '/admin')?.onLight).toBe('/admin/brand-logo-on-light.png');
|
||||
expect(themeLogo(true, '/')?.onDark).toBe('/brand-logo-on-dark.png');
|
||||
});
|
||||
|
||||
it('has no logo when the theme ships none', () => {
|
||||
expect(themeLogo(false)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getBrand', () => {
|
||||
it('has no logo without a theme (the default admin is unchanged)', () => {
|
||||
expect(getBrand().logo).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* The site's brand as the admin shows it: one place, so where it comes from can change later
|
||||
* without touching the components that draw it.
|
||||
*
|
||||
* Today the logo is a build-time theme asset (themes/<VITE_THEME>/logo-on-*.png, emitted by
|
||||
* vite.config.ts). When brand settings become editable (site settings), only getBrand() changes:
|
||||
* it would return the stored logo URLs instead, and BrandLogo keeps working as is.
|
||||
*/
|
||||
export interface BrandLogo {
|
||||
/** For light backgrounds (dark ink). */
|
||||
onLight: string;
|
||||
/** For dark backgrounds (light ink). */
|
||||
onDark: string;
|
||||
}
|
||||
|
||||
export interface Brand {
|
||||
/** Absent when the site has no logo: callers fall back to the application name. */
|
||||
logo: BrandLogo | null;
|
||||
}
|
||||
|
||||
declare const __THEME_HAS_LOGO__: boolean | undefined;
|
||||
|
||||
export function themeLogo(hasLogo: boolean, base: string = import.meta.env.BASE_URL): BrandLogo | null {
|
||||
if (!hasLogo) return null;
|
||||
const prefix = base.endsWith('/') ? base : `${base}/`;
|
||||
return { onLight: `${prefix}brand-logo-on-light.png`, onDark: `${prefix}brand-logo-on-dark.png` };
|
||||
}
|
||||
|
||||
export function getBrand(): Brand {
|
||||
// Defined by vite.config.ts; absent where that config does not run.
|
||||
const hasLogo = typeof __THEME_HAS_LOGO__ !== 'undefined' && __THEME_HAS_LOGO__;
|
||||
return { logo: themeLogo(hasLogo) };
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
@@ -10,6 +10,7 @@ describe('resolveTheme', () => {
|
||||
|
||||
expect(path.basename(theme.css)).toBe('none.css');
|
||||
expect(theme.favicon).toBeNull();
|
||||
expect(theme.logo).toBeNull();
|
||||
expect(fs.readFileSync(theme.css, 'utf-8')).not.toMatch(/--[a-z-]+\s*:/);
|
||||
});
|
||||
|
||||
@@ -21,6 +22,25 @@ describe('resolveTheme', () => {
|
||||
expect(theme.favicon !== null && fs.existsSync(theme.favicon)).toBe(true);
|
||||
});
|
||||
|
||||
it('ships the asf brand logo for both colour modes', () => {
|
||||
const { logo } = resolveTheme('asf');
|
||||
|
||||
expect(logo).not.toBeNull();
|
||||
expect(fs.existsSync(logo!.onLight) && fs.existsSync(logo!.onDark)).toBe(true);
|
||||
});
|
||||
|
||||
it('treats a theme with only one logo variant as having no logo', () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'themes-'));
|
||||
try {
|
||||
fs.mkdirSync(path.join(dir, 'half'));
|
||||
fs.writeFileSync(path.join(dir, 'half', 'theme.css'), '');
|
||||
fs.writeFileSync(path.join(dir, 'half', 'logo-on-light.png'), '');
|
||||
expect(resolveTheme('half', dir).logo).toBeNull();
|
||||
} finally {
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('lists the available themes', () => {
|
||||
expect(availableThemes()).toContain('asf');
|
||||
});
|
||||
|
||||
@@ -6,6 +6,12 @@ export interface ResolvedTheme {
|
||||
css: string;
|
||||
/** Absolute path of the theme favicon, or null when there is no theme or it ships none. */
|
||||
favicon: string | null;
|
||||
/**
|
||||
* Brand logo files: one for light backgrounds (dark ink) and one for dark backgrounds (light
|
||||
* ink), or null when the theme ships none. Both or neither: a logo that is invisible in one
|
||||
* colour mode is worse than none.
|
||||
*/
|
||||
logo: { onLight: string; onDark: string } | null;
|
||||
}
|
||||
|
||||
const THEMES_DIR = import.meta.dirname;
|
||||
@@ -27,7 +33,7 @@ export function availableThemes(dir: string = THEMES_DIR): string[] {
|
||||
export function resolveTheme(name: string | undefined, dir: string = THEMES_DIR): ResolvedTheme {
|
||||
const trimmed = (name ?? '').trim();
|
||||
if (trimmed === '') {
|
||||
return { css: path.join(dir, 'none.css'), favicon: null };
|
||||
return { css: path.join(dir, 'none.css'), favicon: null, logo: null };
|
||||
}
|
||||
|
||||
// The name becomes a path segment: only known theme folders are accepted.
|
||||
@@ -39,8 +45,11 @@ export function resolveTheme(name: string | undefined, dir: string = THEMES_DIR)
|
||||
}
|
||||
|
||||
const favicon = path.join(dir, trimmed, 'favicon.png');
|
||||
const onLight = path.join(dir, trimmed, 'logo-on-light.png');
|
||||
const onDark = path.join(dir, trimmed, 'logo-on-dark.png');
|
||||
return {
|
||||
css: path.join(dir, trimmed, 'theme.css'),
|
||||
favicon: fs.existsSync(favicon) ? favicon : null,
|
||||
logo: fs.existsSync(onLight) && fs.existsSync(onDark) ? { onLight, onDark } : null,
|
||||
};
|
||||
}
|
||||
|
||||
+18
-2
@@ -16,8 +16,13 @@ function themeFor(mode: string) {
|
||||
* Per-site favicon (VITE_THEME): the page links the theme favicon instead of the default one.
|
||||
* Build emits it as an asset; the dev server serves it from the theme folder.
|
||||
*/
|
||||
function themeFavicon(faviconPath: string | null): Plugin {
|
||||
function themeFavicon(faviconPath: string | null, logo: { onLight: string; onDark: string } | null): Plugin {
|
||||
const publicName = 'favicon-theme.png';
|
||||
// Brand logo files, served/emitted next to the favicon (see src/lib/brand.ts for the names' consumer).
|
||||
const logoFiles: Record<string, string> = logo === null ? {} : {
|
||||
'brand-logo-on-light.png': logo.onLight,
|
||||
'brand-logo-on-dark.png': logo.onDark,
|
||||
};
|
||||
return {
|
||||
name: 'cms-theme-favicon',
|
||||
// 'post': Vite has already prefixed the base path (/admin/) by then, so match any prefix.
|
||||
@@ -29,6 +34,12 @@ function themeFavicon(faviconPath: string | null): Plugin {
|
||||
},
|
||||
},
|
||||
configureServer(server) {
|
||||
for (const [name, file] of Object.entries(logoFiles)) {
|
||||
server.middlewares.use(`/${name}`, (_req, res) => {
|
||||
res.setHeader('Content-Type', 'image/png');
|
||||
res.end(fs.readFileSync(file));
|
||||
});
|
||||
}
|
||||
if (faviconPath === null) return;
|
||||
server.middlewares.use(`/${publicName}`, (_req, res) => {
|
||||
res.setHeader('Content-Type', 'image/png');
|
||||
@@ -36,6 +47,9 @@ function themeFavicon(faviconPath: string | null): Plugin {
|
||||
});
|
||||
},
|
||||
generateBundle() {
|
||||
for (const [name, file] of Object.entries(logoFiles)) {
|
||||
this.emitFile({ type: 'asset', fileName: name, source: fs.readFileSync(file) });
|
||||
}
|
||||
if (faviconPath === null) return;
|
||||
this.emitFile({ type: 'asset', fileName: publicName, source: fs.readFileSync(faviconPath) });
|
||||
},
|
||||
@@ -46,10 +60,12 @@ function themeFavicon(faviconPath: string | null): Plugin {
|
||||
export default defineConfig(({ command, mode }) => ({
|
||||
// Production builds are deployed under /admin (see Program.cs); the dev server keeps serving from '/'.
|
||||
base: command === 'build' ? '/admin/' : '/',
|
||||
plugins: [react(), tailwindcss(), themeFavicon(themeFor(mode).favicon)],
|
||||
plugins: [react(), tailwindcss(), themeFavicon(themeFor(mode).favicon, themeFor(mode).logo)],
|
||||
define: {
|
||||
// Injected at build time, used as the Sentry `release` tag (see src/lib/sentry.ts).
|
||||
__APP_VERSION__: JSON.stringify(version),
|
||||
// Whether the selected theme ships a brand logo (consumed by src/lib/brand.ts).
|
||||
__THEME_HAS_LOGO__: JSON.stringify(themeFor(mode).logo !== null),
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
|
||||
Reference in New Issue
Block a user