diff --git a/frontend/src/features/users/pages/UsersPage.test.tsx b/frontend/src/features/users/pages/UsersPage.test.tsx index 4905c10..7118fc1 100644 --- a/frontend/src/features/users/pages/UsersPage.test.tsx +++ b/frontend/src/features/users/pages/UsersPage.test.tsx @@ -247,3 +247,44 @@ describe('UsersPage keeps up with changes made elsewhere', () => { }); }); +describe('UsersPage role change confirmation', () => { + it('shows a success toast with the name and the new role', async () => { + mockAuthenticated(); + renderApp('/users'); + await screen.findByTestId('users-table'); + + await userEvent.click(screen.getByTestId('user-actions-22222222-2222-2222-2222-222222222222')); + await userEvent.click(await screen.findByTestId('user-change-role-22222222-2222-2222-2222-222222222222')); + await userEvent.click(await screen.findByRole('menuitem', { name: 'User' })); + + expect(await screen.findByText('Role of Admin User changed to User')).toBeInTheDocument(); + }); + + it('shows the toast after the Owner confirmation too', async () => { + mockAuthenticated(); + renderApp('/users'); + await screen.findByTestId('users-table'); + + await userEvent.click(screen.getByTestId('user-actions-22222222-2222-2222-2222-222222222222')); + await userEvent.click(await screen.findByTestId('user-change-role-22222222-2222-2222-2222-222222222222')); + await userEvent.click(await screen.findByRole('menuitem', { name: 'Owner' })); + await userEvent.click(await screen.findByRole('button', { name: 'Make Owner' })); + + expect(await screen.findByText('Role of Admin User changed to Owner')).toBeInTheDocument(); + }); + + it('shows no success toast when the change is refused', async () => { + server.use(http.put(`${USERS_URL}/:userId/role`, () => HttpResponse.json({}, { status: 403 }))); + mockAuthenticated(); + renderApp('/users'); + await screen.findByTestId('users-table'); + + await userEvent.click(screen.getByTestId('user-actions-22222222-2222-2222-2222-222222222222')); + await userEvent.click(await screen.findByTestId('user-change-role-22222222-2222-2222-2222-222222222222')); + await userEvent.click(await screen.findByRole('menuitem', { name: 'User' })); + + await screen.findByText(/permission/i); + expect(screen.queryByText(/changed to/)).not.toBeInTheDocument(); + }); +}); + diff --git a/frontend/src/features/users/pages/UsersPage.tsx b/frontend/src/features/users/pages/UsersPage.tsx index cc45082..5a016d5 100644 --- a/frontend/src/features/users/pages/UsersPage.tsx +++ b/frontend/src/features/users/pages/UsersPage.tsx @@ -171,9 +171,15 @@ export function UsersPage() { void executeRoleChange(user.id, newRole); }; + const announceRoleChange = (userId: string, newRole: UserRole, name?: string) => { + const shown = name ?? users?.find((u) => u.id === userId)?.name ?? ''; + toast.success(t('users.actions.roleChanged', { name: shown, role: t(`users.roles.${newRole}`) })); + }; + const executeRoleChange = async (userId: string, newRole: UserRole) => { try { await changeRole.mutateAsync({ userId, newRole }); + announceRoleChange(userId, newRole); } catch (err) { if (err instanceof ProblemDetailsError) { if (err.status === 400) { @@ -209,6 +215,7 @@ export function UsersPage() { if (!ownerAssignTarget) return; try { await changeRole.mutateAsync({ userId: ownerAssignTarget.userId, newRole: 'Owner' }); + announceRoleChange(ownerAssignTarget.userId, 'Owner', ownerAssignTarget.userName); setOwnerAssignTarget(null); } catch (err) { setOwnerAssignTarget(null); diff --git a/frontend/src/i18n/locales/en/translation.json b/frontend/src/i18n/locales/en/translation.json index a0e7c2d..9d8df90 100644 --- a/frontend/src/i18n/locales/en/translation.json +++ b/frontend/src/i18n/locales/en/translation.json @@ -135,7 +135,8 @@ "deactivate": "Deactivate", "activate": "Activate", "delete": "Delete user", - "linkCopied": "Invite link copied to clipboard" + "linkCopied": "Invite link copied to clipboard", + "roleChanged": "Role of {{name}} changed to {{role}}" }, "active": { "successDeactivated": "{{name}} has been deactivated.", diff --git a/frontend/src/i18n/locales/nl/translation.json b/frontend/src/i18n/locales/nl/translation.json index f06a873..a2fe6bc 100644 --- a/frontend/src/i18n/locales/nl/translation.json +++ b/frontend/src/i18n/locales/nl/translation.json @@ -135,7 +135,8 @@ "deactivate": "Deactiveren", "activate": "Activeren", "delete": "Gebruiker verwijderen", - "linkCopied": "Uitnodigingslink gekopieerd naar klembord" + "linkCopied": "Uitnodigingslink gekopieerd naar klembord", + "roleChanged": "Rol van {{name}} gewijzigd naar {{role}}" }, "active": { "successDeactivated": "{{name}} is gedeactiveerd.", diff --git a/frontend/themes/asf/logo-mail.png b/frontend/themes/asf/logo-mail.png new file mode 100644 index 0000000..2fb2624 Binary files /dev/null and b/frontend/themes/asf/logo-mail.png differ diff --git a/frontend/themes/asf/make-mail-logo.py b/frontend/themes/asf/make-mail-logo.py new file mode 100644 index 0000000..f18d78e --- /dev/null +++ b/frontend/themes/asf/make-mail-logo.py @@ -0,0 +1,27 @@ +""" +One-off tool: builds logo-mail.png, the logo for e-mail headers, from logo-on-light.png. + +Mail clients that invert colours themselves (the Gmail and Outlook apps) turn a dark logo on a transparent +background into a dark logo on a dark header. A white rounded badge baked into the PNG is the same in every client: +on the white mail card it disappears into the page, on a dark header it is a tidy white badge. + +Run from this folder with Pillow installed: python make-mail-logo.py +Displayed height in the mail is 56 px; the file is 3x that for sharp rendering on high-density screens. +""" +from PIL import Image, ImageDraw + +SCALE = 3 +CONTENT_H = 40 * SCALE # the logo itself, 40 px high when displayed +PAD = 8 * SCALE # white margin around it +RADIUS = 8 * SCALE + +src = Image.open("logo-on-light.png").convert("RGBA") +src = src.crop(src.getchannel("A").getbbox()) # drop the transparent margin of the original +logo = src.resize((round(src.width * CONTENT_H / src.height), CONTENT_H), Image.LANCZOS) + +w, h = logo.width + 2 * PAD, CONTENT_H + 2 * PAD +badge = Image.new("RGBA", (w, h), (0, 0, 0, 0)) +ImageDraw.Draw(badge).rounded_rectangle((0, 0, w - 1, h - 1), radius=RADIUS, fill=(255, 255, 255, 255)) +badge.alpha_composite(logo, (PAD, PAD)) +badge.save("logo-mail.png", optimize=True) +print(f"logo-mail.png {w}x{h} (display height {h // SCALE}px)") diff --git a/frontend/themes/resolveTheme.test.ts b/frontend/themes/resolveTheme.test.ts index aec0ee6..0f5460c 100644 --- a/frontend/themes/resolveTheme.test.ts +++ b/frontend/themes/resolveTheme.test.ts @@ -29,6 +29,14 @@ describe('resolveTheme', () => { expect(fs.existsSync(logo!.onLight) && fs.existsSync(logo!.onDark)).toBe(true); }); + it('ships the asf e-mail logo (white badge) next to the others', () => { + const { logo } = resolveTheme('asf'); + + expect(logo?.mail).not.toBeNull(); + expect(fs.existsSync(logo!.mail!)).toBe(true); + expect(fs.readFileSync(logo!.mail!).subarray(1, 4).toString()).toBe('PNG'); + }); + it('treats a theme with only one logo variant as having no logo', () => { const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'themes-')); try { diff --git a/frontend/themes/resolveTheme.ts b/frontend/themes/resolveTheme.ts index 6e552f6..d3b9fd9 100644 --- a/frontend/themes/resolveTheme.ts +++ b/frontend/themes/resolveTheme.ts @@ -11,7 +11,7 @@ export interface ResolvedTheme { * 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; + logo: { onLight: string; onDark: string; mail: string | null } | null; } const THEMES_DIR = import.meta.dirname; @@ -47,9 +47,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'); + // Optional: the logo for e-mail headers, on a baked-in white badge (see themes/asf/make-mail-logo.py). + const mail = path.join(dir, trimmed, 'logo-mail.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, + logo: fs.existsSync(onLight) && fs.existsSync(onDark) ? { onLight, onDark, mail: fs.existsSync(mail) ? mail : null } : null, }; } diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 087af08..b05dbaf 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -16,12 +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, logo: { onLight: string; onDark: string } | null): Plugin { +function themeFavicon(faviconPath: string | null, logo: { onLight: string; onDark: string; mail: string | null } | 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 = logo === null ? {} : { 'brand-logo-on-light.png': logo.onLight, 'brand-logo-on-dark.png': logo.onDark, + ...(logo.mail === null ? {} : { 'brand-logo-mail.png': logo.mail }), }; return { name: 'cms-theme-favicon', diff --git a/src/SlpModularCms.Api.AndreaSlopFotografie.Tests/HostConfigurationTests.cs b/src/SlpModularCms.Api.AndreaSlopFotografie.Tests/HostConfigurationTests.cs index de0ea90..0063cf6 100644 --- a/src/SlpModularCms.Api.AndreaSlopFotografie.Tests/HostConfigurationTests.cs +++ b/src/SlpModularCms.Api.AndreaSlopFotografie.Tests/HostConfigurationTests.cs @@ -84,7 +84,7 @@ public class HostConfigurationTests config["Email:Smtp:Username"].Should().BeNullOrEmpty(); config["Email:Smtp:Password"].Should().BeNullOrEmpty(); config["Email:FromAddress"].Should().NotBeNullOrEmpty(); - config["Email:LogoUrl"].Should().Be("/admin/brand-logo-on-light.png"); + config["Email:LogoUrl"].Should().Be("/admin/brand-logo-mail.png"); config["Email:LogoDarkUrl"].Should().Be("/admin/brand-logo-on-dark.png"); } } diff --git a/src/SlpModularCms.Api.AndreaSlopFotografie/appsettings.json b/src/SlpModularCms.Api.AndreaSlopFotografie/appsettings.json index 9840e68..957375a 100644 --- a/src/SlpModularCms.Api.AndreaSlopFotografie/appsettings.json +++ b/src/SlpModularCms.Api.AndreaSlopFotografie/appsettings.json @@ -57,7 +57,7 @@ "FromAddress": "no-reply@slpsoftware.nl", "FromName": "Andrea Slop Fotografie", "AllowedFromAddresses": [], - "LogoUrl": "/admin/brand-logo-on-light.png", + "LogoUrl": "/admin/brand-logo-mail.png", "LogoDarkUrl": "/admin/brand-logo-on-dark.png", "BrandColor": "#5f6a58", "Smtp": { diff --git a/src/SlpModularCms.Core.Tests/Email/EmailRulesAndRendererTests.cs b/src/SlpModularCms.Core.Tests/Email/EmailRulesAndRendererTests.cs index d8c27b2..6a973f5 100644 --- a/src/SlpModularCms.Core.Tests/Email/EmailRulesAndRendererTests.cs +++ b/src/SlpModularCms.Core.Tests/Email/EmailRulesAndRendererTests.cs @@ -240,17 +240,19 @@ public class MailTemplateRendererTests html.Should().MatchRegex("class=\"mail-logo-dark\"[^>]*display:none;[^>]*mso-hide:all"); // ... and the dark block swaps them and drops the plate html.Should().Contain(".mail-logo-light{display:none !important").And.Contain(".mail-logo-dark{display:block !important") - .And.Contain(".mail-plate{background:transparent !important"); +; + html.Should().NotContain("mail-plate"); // no grey plate any more } [Fact] - public void WithoutADarkLogo_ThereIsNoSwap_AndTheLightLogoKeepsItsLightPlate() + public void WithoutADarkLogo_ThereIsNoSwap_AndNoPlateEither() { var html = _renderer.Render(MailKind.Invitation, "nl", Model()).Html; - html.Should().NotContain("mail-logo-dark").And.NotContain(".mail-logo-light{").And.NotContain(".mail-plate{"); - // the plate survives clients that invert backgrounds or ignore the media query - html.Should().Contain("class=\"mail-plate\" bgcolor=\"#f3f4f6\"").And.Contain("background-image:linear-gradient(#f3f4f6,#f3f4f6)"); + html.Should().NotContain("mail-logo-dark").And.NotContain(".mail-logo-light{").And.NotContain("mail-plate") + .And.NotContain("#f3f4f6;background-image"); + // the logo is shown as the image it is (a badge baked into the file), at its display height + html.Should().Contain("class=\"mail-logo-light\" src=\"https://t.nl/admin/brand-logo-on-light.png\" alt=\"Andrea Slop Fotografie\" height=\"56\""); } [Fact] diff --git a/src/SlpModularCms.Core/Email/MailTemplateRenderer.cs b/src/SlpModularCms.Core/Email/MailTemplateRenderer.cs index 36ec701..1fd6982 100644 --- a/src/SlpModularCms.Core/Email/MailTemplateRenderer.cs +++ b/src/SlpModularCms.Core/Email/MailTemplateRenderer.cs @@ -160,7 +160,6 @@ public sealed class MailTemplateRenderer : IMailTemplateRenderer private const string DarkPage = "#111827"; private const string DarkCard = "#1f2937"; - private const string PlateColour = "#f3f4f6"; private static string BuildHtml( MailModel model, string site, string colour, string? greeting, string heading, string intro, @@ -187,10 +186,9 @@ public sealed class MailTemplateRenderer : IMailTemplateRenderer sb.Append(".mail-muted{color:#9ca3af !important;}.mail-rule{border-color:#374151 !important;}"); if (hasDarkLogo) { - // Swap: hide the light logo and its plate, show the dark variant. + // Swap: hide the light logo, show the dark variant. sb.Append(".mail-logo-light{display:none !important;max-height:0 !important;overflow:hidden !important;mso-hide:all !important;}"); sb.Append(".mail-logo-dark{display:block !important;max-height:none !important;overflow:visible !important;mso-hide:none !important;}"); - sb.Append(".mail-plate{background:transparent !important;background-image:none !important;padding:0 !important;}"); } sb.Append("}"); sb.Append(""); @@ -199,15 +197,12 @@ public sealed class MailTemplateRenderer : IMailTemplateRenderer sb.Append($""); if (!string.IsNullOrEmpty(model.LogoUrl)) { - // The light-background logo sits on a light plate (bgcolor + a flat gradient image, which clients that - // invert backgrounds, like the Gmail and Outlook apps, leave alone), so it stays readable even when the - // client ignores the dark-mode rules. With a dark variant, dark mode swaps the two and drops the plate. - sb.Append(""); - sb.Append($"
"); - sb.Append($"\"{E(site)}\""); + // The default logo is meant to be a self-contained image (ASF: a white badge baked into the PNG), so it is + // readable in every client, also those that invert colours themselves and ignore the dark-mode rules. + // With a dark variant, clients that support prefers-color-scheme swap to it. + sb.Append($"\"{E(site)}\""); if (hasDarkLogo) sb.Append($"\"{E(site)}\""); - sb.Append("
"); } else sb.Append($"{E(site)}");