mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-12-05 09:18:53 +00:00
feat(web-app-listmonk): carry the design in Listmonk's appearance settings
Listmonk serves its admin and public pages with the custom CSS and JS it keeps in the settings table, so the role writes the design there: tasks/03_design.yml, included after the settings reaper in tasks/02_manager_ops.yml, pipes templates/design/appearance.sql.j2 into psql. With design on it writes the marked admin stylesheet, admin script and public stylesheet, but only over an empty value or one that starts with the role's own marker, so custom CSS an operator wrote stays; with design off it empties only its own values. The same SQL sets app.logo_url, app.favicon_url and app.site_name from the design lookup and restores the former values when design is off; those keys move from LISTMONK_SETTINGS to LISTMONK_DESIGN_BRANDING in vars/main.yml. templates/design/admin.css.j2 maps the colors of the Bulma and Buefy admin onto the design tokens, templates/design/public.css.j2 does the same for the subscription pages, and templates/design/admin.js.j2 keeps favicon and title on the configured ones while the single-page app rewrites its head. meta/services.yml declares the 182x34 logo slot of the navbar; the emptied files/style.css goes. files/playwright/test-design.js checks tokens, public pages, the administration, navigation and tags, the code editors, logo, favicon and title, that the role writes only its marked settings, and captures the gallery; the native form takes ADMIN_NATIVE_PASSWORD. The unit test renders the SQL for design on, design off and design off without a fallback. README.md links the gallery; TODO.md records the settings task that always reports changed, the secrets it renders into the shell argv, and the logo URLs taken unguarded when the logo replacement is off. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
d22626a9bb
commit
5efd82b9c4
17 files changed
+7575
-46
No files matched your search
@@ -124,6 +124,7 @@ docker run --rm -it \
|
||||
- [Listmonk Official Website](https://listmonk.app/)
|
||||
- [Listmonk Installation Documentation](https://listmonk.app/docs/installation/)
|
||||
- [Listmonk GitHub Repository](https://github.com/knadh/listmonk/)
|
||||
- [Corporate design review: screenshots in light, dark, desktop and mobile](https://claude.ai/artifact/XHHFGfbzxtd6JxuRDB31vy)
|
||||
|
||||
## Credits
|
||||
|
||||
|
||||
@@ -21,3 +21,22 @@
|
||||
`roles/web-app-pixelfed/files/playwright/test-seaweedfs.js`. The
|
||||
`# nocheck: seaweedfs-playwright` marker in `meta/services.yml` comes off with
|
||||
it.
|
||||
- The task "Apply all Listmonk settings" in `tasks/02_manager_ops.yml` reports
|
||||
`changed` on every run (`changed_when: true`) and notifies
|
||||
`container-recreate`, so every role sync recreates the container even when no
|
||||
setting moved. Option: add `AND value IS DISTINCT FROM '<value>'::jsonb` to
|
||||
the `UPDATE` and derive `changed_when` from `UPDATE 1` in its output.
|
||||
- The same task renders each setting value into the `shell:` heredoc, so the
|
||||
SMTP password, the OIDC client secret, the hCaptcha secret and the S3 secret
|
||||
key travel in the `bash -c` argv; `no_log` follows `MASK_CREDENTIALS_IN_LOGS`,
|
||||
which local deploys disable. Option: send the SQL on `stdin:` to
|
||||
`LISTMONK_EXEC_DATABASE`, as the administrator password task does.
|
||||
- `LISTMONK_DESIGN_BRANDING` in `vars/main.yml` and the `DESIGN_*_URL` keys in
|
||||
`templates/playwright.env.j2` read `LISTMONK_DESIGN.urls` unguarded. The
|
||||
design lookup builds those URLs for every slot, while
|
||||
`roles/sys-front-inj-design/tasks/assets.yml` publishes the files only when
|
||||
`design.logo` is a string, so with the logo replacement switched off
|
||||
`app.logo_url` and `app.favicon_url` point at files that do not exist and the
|
||||
design spec asserts them anyway. Option: take the `fallback` for both keys
|
||||
unless `LISTMONK_DESIGN.logo is string`, render the URL keys empty in that
|
||||
case like the other roles, and skip the logo assertions on empty keys.
|
||||
@@ -5,6 +5,7 @@ const { decodeDotenvQuotedValue, normalizeBaseUrl, runAdminFlow, runBiberFlow, r
|
||||
test.use({ ignoreHTTPSErrors: true });
|
||||
|
||||
require("./test-mcp-guest").register();
|
||||
require("./test-design").register();
|
||||
|
||||
const appBaseUrl = normalizeBaseUrl(process.env.APP_BASE_URL || "");
|
||||
const canonicalDomain = decodeDotenvQuotedValue(process.env.CANONICAL_DOMAIN || "");
|
||||
|
||||
@@ -0,0 +1,449 @@
|
||||
const { test, expect } = require("@playwright/test");
|
||||
|
||||
const {
|
||||
assertDesignTokens,
|
||||
assertLightAndDark,
|
||||
assertReadable,
|
||||
assertToken,
|
||||
captureDesignGallery,
|
||||
galleryEnabled,
|
||||
} = require("./design");
|
||||
const {
|
||||
apiGetOnion,
|
||||
decodeDotenvQuotedValue,
|
||||
gotoOnion,
|
||||
normalizeBaseUrl,
|
||||
performKeycloakLogin,
|
||||
} = require("./personas");
|
||||
const { isServiceEnabled, skipUnlessServiceEnabled } = require("./service-gating");
|
||||
const { resolveTimeout } = require("./timeouts");
|
||||
|
||||
const base = normalizeBaseUrl(process.env.APP_BASE_URL || "");
|
||||
const canonicalDomain = decodeDotenvQuotedValue(process.env.CANONICAL_DOMAIN || "");
|
||||
const adminUsername = decodeDotenvQuotedValue(process.env.ADMIN_USERNAME || "");
|
||||
const adminPassword = decodeDotenvQuotedValue(process.env.ADMIN_PASSWORD || "");
|
||||
const adminNativePassword = decodeDotenvQuotedValue(process.env.ADMIN_NATIVE_PASSWORD || "");
|
||||
const faviconUrl = decodeDotenvQuotedValue(process.env.DESIGN_FAVICON_URL || "");
|
||||
const headerUrl = decodeDotenvQuotedValue(process.env.DESIGN_HEADER_URL || "");
|
||||
const iconUrl = decodeDotenvQuotedValue(process.env.DESIGN_ICON_URL || "");
|
||||
const logoUrl = decodeDotenvQuotedValue(process.env.DESIGN_LOGO_URL || "");
|
||||
const designTitle = decodeDotenvQuotedValue(process.env.DESIGN_TITLE || "");
|
||||
|
||||
const MODES = ["light", "dark"];
|
||||
const CSS_MARKER = ":root{--infinito-design-carrier:1}";
|
||||
const JS_MARKER = "window.infinitoDesignCarrier = 1;";
|
||||
const LOGIN_FORM = "section.login form";
|
||||
const LOGIN_USER = `${LOGIN_FORM} #username`;
|
||||
const LOGIN_PASSWORD = `${LOGIN_FORM} #password`;
|
||||
const LOGIN_SUBMIT = `${LOGIN_FORM} button[type='submit']`;
|
||||
const PANEL = ".container.wrap";
|
||||
const NAVBAR = "#app .navbar";
|
||||
const MAIN = "#app .main";
|
||||
const HEADING = ".main h1.title";
|
||||
const ROW = ".main table tbody tr";
|
||||
const CELL = ".main table tbody td";
|
||||
const PRIMARY = ".main [data-cy=btn-new]";
|
||||
const NAV_LINK = ".b-sidebar .menu-list a";
|
||||
const SELECTED_NAV = ".b-sidebar .menu-list ul a.is-active";
|
||||
const SELECTED_GROUP = ".b-sidebar .menu-list > li > a.is-active";
|
||||
const LOGO = ".navbar-brand .full";
|
||||
const SMALL_LOGO = ".navbar-brand .favicon";
|
||||
const PREF_KEY = "listmonk_pref";
|
||||
|
||||
test.use({ ignoreHTTPSErrors: true });
|
||||
|
||||
/**
|
||||
* Args:
|
||||
* page: Playwright page whose finite animations must have ended.
|
||||
*/
|
||||
async function animationsSettled(page) {
|
||||
await expect
|
||||
.poll(
|
||||
() =>
|
||||
page.evaluate(() =>
|
||||
document
|
||||
.getAnimations()
|
||||
.some((a) => a.playState === "running" && a.effect?.getComputedTiming().iterations !== Infinity),
|
||||
),
|
||||
{ message: "every finite animation of the page must have ended", timeout: resolveTimeout(10_000) },
|
||||
)
|
||||
.toBe(false);
|
||||
}
|
||||
|
||||
function shown(selector) {
|
||||
return async (page) => {
|
||||
await expect(page.locator(selector).first()).toBeVisible({ timeout: resolveTimeout(10_000) });
|
||||
await expect(page.locator(".loading-overlay:visible")).toHaveCount(0, { timeout: resolveTimeout(10_000) });
|
||||
await animationsSettled(page);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Args:
|
||||
* page: Playwright page that ends signed in to the Listmonk administration as its administrator, through Keycloak when sso is on and through the native form with ADMIN_NATIVE_PASSWORD otherwise.
|
||||
*/
|
||||
async function signIn(page) {
|
||||
await gotoOnion(page, `${base}/admin/login`);
|
||||
if (isServiceEnabled("sso")) {
|
||||
await page.waitForURL(/openid-connect\/auth/, { timeout: resolveTimeout(30_000) });
|
||||
await performKeycloakLogin(page, adminUsername, adminPassword, canonicalDomain);
|
||||
await gotoOnion(page, `${base}/admin/`);
|
||||
} else {
|
||||
await expect(page.locator(LOGIN_PASSWORD)).toBeEditable({ timeout: resolveTimeout(10_000) });
|
||||
await page.locator(LOGIN_USER).fill(adminUsername);
|
||||
await page.locator(LOGIN_PASSWORD).fill(adminNativePassword);
|
||||
await page.locator(LOGIN_SUBMIT).click({ timeout: resolveTimeout(10_000) });
|
||||
}
|
||||
await expect(page.locator(NAVBAR)).toBeVisible({ timeout: resolveTimeout(30_000) });
|
||||
await expect(page).toHaveURL(/\/admin/);
|
||||
}
|
||||
|
||||
/**
|
||||
* Args:
|
||||
* page: Playwright page on the administration whose stored settings tab is set.
|
||||
* tab: index of the settings tab the next settings page opens on.
|
||||
*/
|
||||
async function settingsTab(page, tab) {
|
||||
await page.evaluate(
|
||||
([key, index]) => {
|
||||
const pref = JSON.parse(localStorage.getItem(key) || "{}");
|
||||
pref["settings.tab"] = index;
|
||||
localStorage.setItem(key, JSON.stringify(pref));
|
||||
},
|
||||
[PREF_KEY, tab],
|
||||
);
|
||||
}
|
||||
|
||||
async function served(page, url) {
|
||||
return page.evaluate(
|
||||
(src) =>
|
||||
new Promise((resolve) => {
|
||||
const image = new Image();
|
||||
image.onload = () => resolve(image.naturalWidth > 0);
|
||||
image.onerror = () => resolve(false);
|
||||
image.src = src;
|
||||
}),
|
||||
url,
|
||||
);
|
||||
}
|
||||
|
||||
function publicViews() {
|
||||
return [
|
||||
{ name: "public-home", url: `${base}/`, prepare: shown("section.center a.button") },
|
||||
{ name: "public-login", url: `${base}/admin/login`, prepare: shown(LOGIN_PASSWORD) },
|
||||
{
|
||||
name: "public-login-error",
|
||||
url: `${base}/admin/login`,
|
||||
prepare: async (page) => {
|
||||
await expect(page.locator(LOGIN_PASSWORD)).toBeEditable({ timeout: resolveTimeout(10_000) });
|
||||
await page.locator(LOGIN_USER).fill("design-gallery-nobody");
|
||||
await page.locator(LOGIN_PASSWORD).fill(`gallery-${Date.now()}`);
|
||||
await page.locator(LOGIN_SUBMIT).click({ timeout: resolveTimeout(10_000) });
|
||||
await shown(".login .error")(page);
|
||||
},
|
||||
},
|
||||
{ name: "public-subscription", url: `${base}/subscription/form`, prepare: shown("ul.lists li") },
|
||||
{ name: "public-archive", url: `${base}/archive`, prepare: shown(`${PANEL} h2`) },
|
||||
{ name: "public-404", url: `${base}/design-gallery-missing`, prepare: shown(PANEL) },
|
||||
];
|
||||
}
|
||||
|
||||
function adminViews() {
|
||||
const view = (name, path, selector) => ({ name, url: `${base}/admin${path}`, prepare: shown(selector) });
|
||||
const lists = `${base}/admin/lists`;
|
||||
const settings = `${base}/admin/settings`;
|
||||
const tabView = (name, index, selector) => ({
|
||||
name,
|
||||
url: settings,
|
||||
prepare: async (page) => {
|
||||
await shown(".settings-tabs .tab-content")(page);
|
||||
await page
|
||||
.locator(".settings-tabs > nav.tabs li")
|
||||
.nth(index)
|
||||
.locator("a")
|
||||
.click({ timeout: resolveTimeout(10_000) });
|
||||
await shown(selector)(page);
|
||||
await settingsTab(page, 0);
|
||||
},
|
||||
});
|
||||
return [
|
||||
view("dashboard", "/", "section.dashboard .counts"),
|
||||
view("lists", "/lists", ROW),
|
||||
{
|
||||
name: "list-new",
|
||||
url: lists,
|
||||
prepare: async (page) => {
|
||||
await shown(ROW)(page);
|
||||
await page.locator(PRIMARY).first().click({ timeout: resolveTimeout(10_000) });
|
||||
await shown(".modal-card")(page);
|
||||
},
|
||||
},
|
||||
view("list-forms", "/lists/forms", HEADING),
|
||||
view("subscribers", "/subscribers", ROW),
|
||||
view("subscriber-detail", "/subscribers/1", ".modal-card"),
|
||||
view("import", "/subscribers/import", "section.import form"),
|
||||
view("bounces", "/subscribers/bounces", HEADING),
|
||||
view("campaigns", "/campaigns", ROW),
|
||||
view("campaign", "/campaigns/1", "section.campaign form"),
|
||||
{
|
||||
name: "campaign-content",
|
||||
url: `${base}/admin/campaigns/1`,
|
||||
prepare: async (page) => {
|
||||
await shown("section.campaign form")(page);
|
||||
await page
|
||||
.locator("section.campaign nav.tabs li")
|
||||
.nth(1)
|
||||
.locator("a")
|
||||
.click({ timeout: resolveTimeout(10_000) });
|
||||
await shown(".tox-tinymce, .code-editor .cm-editor")(page);
|
||||
},
|
||||
},
|
||||
view("campaign-new", "/campaigns/new", "section.campaign form"),
|
||||
view("media", "/campaigns/media", HEADING),
|
||||
view("templates", "/campaigns/templates", ROW),
|
||||
view("analytics", "/campaigns/analytics", HEADING),
|
||||
view("users", "/users", ROW),
|
||||
view("user-roles", "/users/roles/users", ROW),
|
||||
{
|
||||
name: "settings",
|
||||
url: settings,
|
||||
prepare: async (page) => {
|
||||
await settingsTab(page, 0);
|
||||
await gotoOnion(page, settings);
|
||||
await shown(".settings-tabs .tab-content")(page);
|
||||
},
|
||||
},
|
||||
tabView("settings-smtp", 5, ".settings-tabs .tab-item:not([style*='none']) .box, .settings-tabs .tab-content"),
|
||||
tabView("settings-appearance", 8, ".settings .code-editor .cm-editor"),
|
||||
view("maintenance", "/settings/maintenance", HEADING),
|
||||
view("logs", "/settings/logs", ".log-view"),
|
||||
view("profile", "/user/profile", HEADING),
|
||||
{
|
||||
name: "user-menu",
|
||||
url: lists,
|
||||
prepare: async (page) => {
|
||||
await shown(ROW)(page);
|
||||
const burger = page.locator(".navbar-burger");
|
||||
if (await burger.isVisible()) {
|
||||
await burger.click({ timeout: resolveTimeout(10_000) });
|
||||
await shown(".navbar-menu.is-active")(page);
|
||||
}
|
||||
await page.locator(".navbar-item.user .navbar-link").first().click({ timeout: resolveTimeout(10_000) });
|
||||
await shown(".navbar-item.user .navbar-dropdown")(page);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "nav-hover",
|
||||
url: lists,
|
||||
prepare: async (page) => {
|
||||
await shown(ROW)(page);
|
||||
const entry = page.locator(`${NAV_LINK}:visible`).nth(2);
|
||||
if (await entry.isVisible()) {
|
||||
await entry.hover({ timeout: resolveTimeout(10_000) });
|
||||
await animationsSettled(page);
|
||||
}
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
exports.register = function () {
|
||||
test("design: corporate tokens apply in light and dark mode", async ({ page }) => {
|
||||
skipUnlessServiceEnabled("design");
|
||||
await gotoOnion(page, `${base}/`);
|
||||
await shown("section.center a.button")(page);
|
||||
await assertDesignTokens(page, "listmonk");
|
||||
});
|
||||
|
||||
test("design: the public pages take surface, panel, form, primary action and text from the palette", async ({
|
||||
page,
|
||||
}) => {
|
||||
skipUnlessServiceEnabled("design");
|
||||
const form = "form.form";
|
||||
for (const mode of MODES) {
|
||||
await page.emulateMedia({ colorScheme: mode });
|
||||
await gotoOnion(page, `${base}/subscription/form`);
|
||||
await shown("ul.lists li")(page);
|
||||
await assertToken(page, "body", "background-color", "--design-surface-1", `subscription ${mode}`);
|
||||
await assertToken(page, PANEL, "background-color", "--design-surface-2", `subscription ${mode}`);
|
||||
await assertToken(page, PANEL, "border-top-color", "--design-border", `subscription ${mode}`);
|
||||
await assertToken(page, ".header", "border-bottom-color", "--design-border", `subscription divider ${mode}`);
|
||||
await assertToken(page, `${form} label`, "color", "--design-text", `subscription ${mode}`);
|
||||
await assertToken(page, `${form} input[name=name]`, "border-top-color", "--design-border-strong", `field ${mode}`);
|
||||
await page.locator(`${form} input[type=email]`).focus();
|
||||
await assertToken(page, `${form} input[type=email]`, "border-top-color", "--design-link", `focused field ${mode}`);
|
||||
await assertToken(page, `${form} .button`, "background-color", "--design-primary", `primary action ${mode}`);
|
||||
await assertToken(page, `${form} .button`, "color", "--design-on-primary", `primary action ${mode}`);
|
||||
}
|
||||
await page.emulateMedia({ colorScheme: null });
|
||||
await assertLightAndDark(page, PANEL, "listmonk public panel");
|
||||
await assertReadable(
|
||||
page,
|
||||
[
|
||||
`${form} label`,
|
||||
`${form} .button`,
|
||||
"footer.container",
|
||||
{ selector: ".lists .description", optional: true },
|
||||
{ selector: "footer.container a", optional: true },
|
||||
],
|
||||
"listmonk public",
|
||||
);
|
||||
});
|
||||
|
||||
test("design: the administration takes surfaces, primary action, text and dividers from the palette", async ({
|
||||
page,
|
||||
}) => {
|
||||
skipUnlessServiceEnabled("design");
|
||||
await signIn(page);
|
||||
for (const mode of MODES) {
|
||||
await page.emulateMedia({ colorScheme: mode });
|
||||
await gotoOnion(page, `${base}/admin/lists`);
|
||||
await shown(ROW)(page);
|
||||
await assertToken(page, "body", "background-color", "--design-surface-1", `shell ${mode}`);
|
||||
await assertToken(page, MAIN, "background-color", "--design-surface-2", `shell ${mode}`);
|
||||
await assertToken(page, NAVBAR, "background-color", "--design-surface-2", `shell ${mode}`);
|
||||
await assertToken(page, HEADING, "color", "--design-text", `shell ${mode}`);
|
||||
await assertToken(page, CELL, "color", "--design-text", `shell ${mode}`);
|
||||
await assertToken(page, CELL, "border-bottom-color", "--design-border", `content divider ${mode}`);
|
||||
await assertToken(page, PRIMARY, "background-color", "--design-primary", `primary action ${mode}`);
|
||||
await assertToken(page, PRIMARY, "color", "--design-on-primary", `primary action ${mode}`);
|
||||
await page.locator(PRIMARY).first().hover({ timeout: resolveTimeout(10_000) });
|
||||
await assertToken(page, PRIMARY, "background-color", "--design-primary-hover", `hovered primary ${mode}`);
|
||||
await page.mouse.move(0, 0);
|
||||
}
|
||||
await page.emulateMedia({ colorScheme: null });
|
||||
await assertLightAndDark(page, MAIN, "listmonk shell");
|
||||
await assertReadable(page, [HEADING, CELL, PRIMARY, { selector: NAV_LINK, optional: true }], "listmonk shell");
|
||||
});
|
||||
|
||||
test("design: the selected navigation entry and the status tags keep readable palette states", async ({ page }) => {
|
||||
skipUnlessServiceEnabled("design");
|
||||
await signIn(page);
|
||||
await gotoOnion(page, `${base}/admin/campaigns/1`);
|
||||
await shown("section.campaign form")(page);
|
||||
for (const mode of MODES) {
|
||||
await page.emulateMedia({ colorScheme: mode });
|
||||
for (const entry of [SELECTED_NAV, SELECTED_GROUP]) {
|
||||
await assertToken(page, entry, "color", "--design-link", `selected entry ${mode}`);
|
||||
await assertToken(page, entry, "background-color", "--design-surface-active", `selected entry ${mode}`);
|
||||
}
|
||||
}
|
||||
await page.emulateMedia({ colorScheme: null });
|
||||
await assertReadable(page, [SELECTED_NAV, SELECTED_GROUP], "listmonk navigation states");
|
||||
await gotoOnion(page, `${base}/admin/lists`);
|
||||
await shown(ROW)(page);
|
||||
for (const mode of MODES) {
|
||||
await page.emulateMedia({ colorScheme: mode });
|
||||
await assertToken(page, ".main .tag.public", "background-color", "--design-info-subtle", `public tag ${mode}`);
|
||||
await assertToken(page, ".main .tag.private", "background-color", "--design-warning-subtle", `private tag ${mode}`);
|
||||
}
|
||||
await page.emulateMedia({ colorScheme: null });
|
||||
await assertReadable(page, [".main .tag.public", ".main .tag.private"], "listmonk states");
|
||||
});
|
||||
|
||||
test("design: the code editors take surface, gutter and text from the palette", async ({ page }) => {
|
||||
skipUnlessServiceEnabled("design");
|
||||
await signIn(page);
|
||||
await settingsTab(page, 8);
|
||||
const editor = ".settings .code-editor .cm-editor";
|
||||
for (const mode of MODES) {
|
||||
await page.emulateMedia({ colorScheme: mode });
|
||||
await gotoOnion(page, `${base}/admin/settings`);
|
||||
await shown(editor)(page);
|
||||
await assertToken(page, editor, "background-color", "--design-surface-2", `code editor ${mode}`);
|
||||
await assertToken(page, editor, "color", "--design-text", `code editor ${mode}`);
|
||||
await assertToken(page, `${editor} .cm-gutters`, "background-color", "--design-surface-2", `code gutter ${mode}`);
|
||||
await assertToken(page, `${editor} .cm-gutters`, "color", "--design-text-muted", `code gutter ${mode}`);
|
||||
}
|
||||
await page.emulateMedia({ colorScheme: null });
|
||||
await assertLightAndDark(page, editor, "listmonk code editor");
|
||||
for (const mode of MODES) {
|
||||
await page.emulateMedia({ colorScheme: mode });
|
||||
const weak = await page.evaluate((selector) => {
|
||||
const ctx = document.createElement("canvas").getContext("2d", { willReadFrequently: true });
|
||||
const rgb = (value) => {
|
||||
ctx.clearRect(0, 0, 1, 1);
|
||||
ctx.fillStyle = value;
|
||||
ctx.fillRect(0, 0, 1, 1);
|
||||
return [...ctx.getImageData(0, 0, 1, 1).data].slice(0, 3);
|
||||
};
|
||||
const lum = (c) =>
|
||||
c
|
||||
.map((v) => v / 255)
|
||||
.map((s) => (s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4))
|
||||
.reduce((sum, v, i) => sum + v * [0.2126, 0.7152, 0.0722][i], 0);
|
||||
const editorElement = document.querySelector(selector);
|
||||
const background = lum(rgb(getComputedStyle(editorElement).backgroundColor));
|
||||
const found = {};
|
||||
for (const span of editorElement.querySelectorAll(".cm-line span")) {
|
||||
const fg = lum(rgb(getComputedStyle(span).color));
|
||||
const ratio = (Math.max(fg, background) + 0.05) / (Math.min(fg, background) + 0.05);
|
||||
if (ratio < 4.5) found[span.className] = ratio.toFixed(2);
|
||||
}
|
||||
return found;
|
||||
}, editor);
|
||||
expect(weak, `${mode}: every highlighted token reaches 4.5:1 against the editor surface`).toEqual({});
|
||||
}
|
||||
await page.emulateMedia({ colorScheme: null });
|
||||
await settingsTab(page, 0);
|
||||
});
|
||||
|
||||
test("design: logo, favicon and title come from the design lookup", async ({ page }) => {
|
||||
skipUnlessServiceEnabled("design");
|
||||
await gotoOnion(page, `${base}/`);
|
||||
await shown("section.center a.button")(page);
|
||||
await expect(page.locator(".header .logo img")).toHaveAttribute("src", headerUrl);
|
||||
await expect(page.locator("link[rel~='icon']")).toHaveAttribute("href", faviconUrl);
|
||||
await expect(page).toHaveTitle(new RegExp(`${designTitle.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`));
|
||||
await signIn(page);
|
||||
await gotoOnion(page, `${base}/admin/lists`);
|
||||
await shown(ROW)(page);
|
||||
await expect(page.locator("link[rel~='icon']")).toHaveAttribute("href", faviconUrl);
|
||||
await expect.poll(() => page.title(), { message: "the admin title ends with the design title" }).toMatch(
|
||||
new RegExp(`${designTitle.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`),
|
||||
);
|
||||
const visible = (await page.locator(LOGO).isVisible()) ? LOGO : SMALL_LOGO;
|
||||
await expect(page.locator(visible)).toHaveCSS("content", `url("${visible === LOGO ? logoUrl : iconUrl}")`);
|
||||
if (visible === LOGO) {
|
||||
const box = await page.locator(LOGO).boundingBox();
|
||||
expect(box.width, "the navbar logo is a wide lockup").toBeGreaterThan(box.height * 3);
|
||||
expect(box.height, "the navbar lockup is tall enough to read its title").toBeGreaterThan(24);
|
||||
}
|
||||
for (const url of [logoUrl, headerUrl, iconUrl, faviconUrl]) {
|
||||
expect(await served(page, url), `the page must be allowed to load ${url}`).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
test("design: the role writes only its own marked appearance settings", async ({ page, request }) => {
|
||||
skipUnlessServiceEnabled("design");
|
||||
await signIn(page);
|
||||
const fetchText = (url) => page.evaluate(async (target) => (await fetch(target)).text(), url);
|
||||
const adminCss = await fetchText(`${base}/admin/custom.css`);
|
||||
expect(adminCss.startsWith(CSS_MARKER), "the admin custom CSS carries the role marker first").toBe(true);
|
||||
expect(/#[0-9a-fA-F]{3,8}\b(?![\w-])/.test(adminCss.replace(/url\([^)]*\)/g, "")), "no literal color").toBe(false);
|
||||
expect((await fetchText(`${base}/admin/custom.js`)).startsWith(JS_MARKER), "the admin custom JS carries the marker").toBe(
|
||||
true,
|
||||
);
|
||||
const publicCss = await apiGetOnion(request, `${base}/public/custom.css`, { timeout: resolveTimeout(30_000) });
|
||||
expect((await publicCss.text()).startsWith(CSS_MARKER), "the public custom CSS carries the role marker first").toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test("design: gallery of public pages, lists, subscribers, campaigns, users and settings", async ({
|
||||
browser,
|
||||
page,
|
||||
}) => {
|
||||
skipUnlessServiceEnabled("design");
|
||||
test.skip(!galleryEnabled(), "INFINITO_PLAYWRIGHT_KEEP is not true");
|
||||
test.setTimeout(resolveTimeout(2_400_000));
|
||||
const failures = [];
|
||||
const visitor = await browser.newContext({ ignoreHTTPSErrors: true });
|
||||
const publicSide = publicViews().filter((v) => !(isServiceEnabled("sso") && v.name.startsWith("public-login")));
|
||||
await captureDesignGallery(await visitor.newPage(), publicSide).catch((error) => failures.push(error.message));
|
||||
await visitor.close();
|
||||
await signIn(page);
|
||||
await captureDesignGallery(page, adminViews()).catch((error) => failures.push(error.message));
|
||||
expect(failures, "design gallery views failed").toEqual([]);
|
||||
});
|
||||
};
|
||||
@@ -1,34 +0,0 @@
|
||||
.wrap {
|
||||
color: var(--design-text);
|
||||
background-color: var(--design-primary-300);
|
||||
box-shadow: 2px 2px 0 var(--design-primary-500);
|
||||
border: 1px solid var(--design-primary-900);
|
||||
border-radius: 6px;
|
||||
|
||||
}
|
||||
|
||||
.lists .description {
|
||||
color: var(--design-primary-950);
|
||||
}
|
||||
|
||||
#app .main {
|
||||
background: var(--design-primary-500);
|
||||
}
|
||||
|
||||
.title {
|
||||
color: var(--design-primary-950);
|
||||
}
|
||||
|
||||
|
||||
.tabs a {
|
||||
border-bottom-color: var(--design-primary-950);
|
||||
color: var(--design-primary-950);
|
||||
}
|
||||
|
||||
.field .help {
|
||||
color: var(--design-primary-950);
|
||||
}
|
||||
|
||||
.field label {
|
||||
color: var(--design-primary-200);
|
||||
}
|
||||
@@ -81,6 +81,10 @@ design:
|
||||
bond: 1
|
||||
enabled: "{{ 'web-svc-design' in group_names }}"
|
||||
shared: "{{ 'web-svc-design' in group_names }}"
|
||||
slots:
|
||||
logo:
|
||||
width: 182
|
||||
height: 34
|
||||
# nocheck: dynamic-flag
|
||||
hcaptcha:
|
||||
enabled: "{{ HCAPTCHA_ENABLED | bool }}"
|
||||
|
||||
@@ -70,5 +70,8 @@
|
||||
async_reap_label: "Listmonk settings"
|
||||
async_reap_tolerate: []
|
||||
|
||||
- name: "🎨 Carry the corporate design in the Listmonk settings"
|
||||
ansible.builtin.include_tasks: 03_design.yml
|
||||
|
||||
- name: "🚿 Recreate Listmonk so the settings above are loaded"
|
||||
ansible.builtin.meta: flush_handlers
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
- name: "🎨 Carry the corporate design in the Listmonk appearance and branding settings"
|
||||
ansible.builtin.command:
|
||||
cmd: "{{ LISTMONK_EXEC_DATABASE }} -v ON_ERROR_STOP=1"
|
||||
stdin: "{{ lookup('template', 'design/appearance.sql.j2') }}"
|
||||
register: listmonk_design_settings
|
||||
changed_when: "'UPDATE 1' in listmonk_design_settings.stdout"
|
||||
notify: container-recreate
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,19 @@
|
||||
{{ LISTMONK_DESIGN_JS_MARKER }}
|
||||
(() => {
|
||||
const label = {{ LISTMONK_DESIGN.label | to_json }};
|
||||
const favicon = {{ LISTMONK_DESIGN.urls.favicon_ico | to_json }};
|
||||
const brand = () => {
|
||||
for (const link of document.querySelectorAll("link[rel~='icon']")) {
|
||||
if (link.href !== favicon) link.href = favicon;
|
||||
}
|
||||
const title = document.title.replace(/listmonk$/, label);
|
||||
if (title !== document.title) document.title = title;
|
||||
};
|
||||
brand();
|
||||
new MutationObserver(brand).observe(document.head, {
|
||||
attributes: true,
|
||||
characterData: true,
|
||||
childList: true,
|
||||
subtree: true,
|
||||
});
|
||||
})();
|
||||
@@ -0,0 +1,16 @@
|
||||
{% for entry in LISTMONK_DESIGN_APPEARANCE %}
|
||||
{% set value = (lookup('template', entry.template) | trim) if LISTMONK_DESIGN_ENABLED | bool else '' %}
|
||||
UPDATE settings
|
||||
SET value = to_jsonb($infinito_value${{ value }}$infinito_value$::text)
|
||||
WHERE key = '{{ entry.key }}'
|
||||
AND (value #>> '{}' = '' OR starts_with(value #>> '{}', $infinito_marker${{ entry.marker }}$infinito_marker$))
|
||||
AND value IS DISTINCT FROM to_jsonb($infinito_value${{ value }}$infinito_value$::text);
|
||||
{% endfor %}
|
||||
{% for entry in LISTMONK_DESIGN_BRANDING %}
|
||||
{% set value = entry.design if LISTMONK_DESIGN_ENABLED | bool else entry.fallback %}
|
||||
UPDATE settings
|
||||
SET value = to_jsonb($infinito_value${{ value }}$infinito_value$::text)
|
||||
WHERE key = '{{ entry.key }}'
|
||||
AND value IS DISTINCT FROM to_jsonb($infinito_value${{ value }}$infinito_value$::text){% if value | length == 0 %}
|
||||
AND value = to_jsonb($infinito_value${{ entry.design }}$infinito_value$::text){% endif %};
|
||||
{% endfor %}
|
||||
@@ -0,0 +1,67 @@
|
||||
{{ LISTMONK_DESIGN_CSS_MARKER }}
|
||||
body {
|
||||
background: var(--design-surface-1);
|
||||
color: var(--design-text);
|
||||
}
|
||||
a {
|
||||
color: var(--design-link);
|
||||
text-decoration-color: currentColor;
|
||||
}
|
||||
a:hover {
|
||||
color: var(--design-text);
|
||||
}
|
||||
label {
|
||||
color: var(--design-text);
|
||||
}
|
||||
input[type="text"], input[type="email"], input[type="password"], select {
|
||||
background: var(--design-surface-2);
|
||||
color: var(--design-text);
|
||||
border-color: var(--design-border-strong);
|
||||
box-shadow: 2px 2px 0 var(--design-border);
|
||||
}
|
||||
input:focus {
|
||||
border-color: var(--design-link);
|
||||
}
|
||||
.error {
|
||||
color: var(--design-danger);
|
||||
}
|
||||
.button {
|
||||
background: var(--design-primary);
|
||||
color: var(--design-on-primary);
|
||||
}
|
||||
.button:hover {
|
||||
background: var(--design-primary-hover);
|
||||
color: var(--design-on-primary);
|
||||
}
|
||||
.button.button-outline {
|
||||
background: var(--design-surface-2);
|
||||
border-color: var(--design-primary);
|
||||
color: var(--design-link);
|
||||
}
|
||||
.button.button-outline:hover {
|
||||
border-color: var(--design-primary-hover);
|
||||
background-color: var(--design-primary-hover);
|
||||
color: var(--design-on-primary);
|
||||
}
|
||||
.wrap {
|
||||
background: var(--design-surface-2);
|
||||
border-color: var(--design-border);
|
||||
box-shadow: 2px 2px 0 var(--design-border);
|
||||
}
|
||||
.header {
|
||||
border-bottom-color: var(--design-border);
|
||||
}
|
||||
.unsub-all {
|
||||
border-top-color: var(--design-border);
|
||||
}
|
||||
.lists .description,
|
||||
.archive .date {
|
||||
color: var(--design-text-muted);
|
||||
}
|
||||
footer.container,
|
||||
footer a {
|
||||
color: var(--design-text-muted);
|
||||
}
|
||||
footer a:hover {
|
||||
color: var(--design-text);
|
||||
}
|
||||
@@ -15,9 +15,18 @@ BIBER_USERNAME={{ lookup('users', 'biber').username | dotenv_quote }}
|
||||
|
||||
CANONICAL_DOMAIN={{ lookup('domain', application_id) | dotenv_quote }}
|
||||
|
||||
# nocheck: playwright-service-gate — assertCspInjections resolves this injector through a computed loop variable (personas/utils/csp.js), never a literal gate argument, so this rule's literal-only regex cannot see the gate
|
||||
DESIGN_FAVICON_URL={{ LISTMONK_DESIGN.urls.favicon_ico | dotenv_quote }}
|
||||
|
||||
DESIGN_HEADER_URL={{ LISTMONK_DESIGN.urls.header.svg | dotenv_quote }}
|
||||
|
||||
DESIGN_ICON_URL={{ LISTMONK_DESIGN.urls.icon.svg | dotenv_quote }}
|
||||
|
||||
DESIGN_LOGO_URL={{ LISTMONK_DESIGN.urls.logo.svg | dotenv_quote }}
|
||||
|
||||
DESIGN_SERVICE_ENABLED={{ lookup('config', application_id, 'services.design.enabled') | string | lower }}
|
||||
|
||||
DESIGN_TITLE={{ LISTMONK_DESIGN.label | dotenv_quote }}
|
||||
|
||||
# nocheck: playwright-service-gate — the SMTP sender is pushed into Listmonk's settings table by tasks/02_manager_ops.yml (the `smtp` entry in vars/main.yml), never into a browser-visible surface, and no scenario in this spec sends a campaign
|
||||
EMAIL_SERVICE_ENABLED={{ lookup('config', application_id, 'services.email.enabled') | string | lower }}
|
||||
|
||||
|
||||
@@ -77,13 +77,6 @@ LISTMONK_SETTINGS:
|
||||
- key: "app.lang"
|
||||
value: '"{{ HOST_LL }}"'
|
||||
|
||||
- key: "app.logo_url"
|
||||
value: '"{{ service_provider.platform.logo }}"'
|
||||
condition: "{{ service_provider.platform.logo | length > 0 }}"
|
||||
|
||||
- key: "app.site_name"
|
||||
value: '"{{ service_provider.company.titel }} Mailing list"'
|
||||
|
||||
- key: "bounce.enabled"
|
||||
value: "true"
|
||||
|
||||
@@ -109,10 +102,6 @@ LISTMONK_SETTINGS:
|
||||
- key: "app.from_email"
|
||||
value: '"{{ service_provider.company.titel }} Newsletter <{{ lookup(''users'', LISTMONK_USER_SEND).email }}>"'
|
||||
|
||||
- key: "app.favicon_url"
|
||||
value: '"{{ service_provider.platform.favicon }}"'
|
||||
condition: "{{ service_provider.platform.favicon | length > 0 }}"
|
||||
|
||||
- key: "app.check_updates"
|
||||
value: "true"
|
||||
|
||||
@@ -150,6 +139,32 @@ LISTMONK_SETTINGS:
|
||||
- key: "upload.s3.bucket_type"
|
||||
value: '"public"'
|
||||
condition: "{{ lookup('objstore', application_id, 'enabled') | bool }}"
|
||||
|
||||
LISTMONK_DESIGN: "{{ lookup('design', application_id) }}"
|
||||
LISTMONK_DESIGN_ENABLED: "{{ lookup('config', application_id, 'services.design.enabled') | bool }}"
|
||||
LISTMONK_DESIGN_CSS_MARKER: ":root{--infinito-design-carrier:1}"
|
||||
LISTMONK_DESIGN_JS_MARKER: "window.infinitoDesignCarrier = 1;"
|
||||
LISTMONK_DESIGN_APPEARANCE:
|
||||
- key: "appearance.admin.custom_css"
|
||||
template: "design/admin.css.j2"
|
||||
marker: "{{ LISTMONK_DESIGN_CSS_MARKER }}"
|
||||
- key: "appearance.admin.custom_js"
|
||||
template: "design/admin.js.j2"
|
||||
marker: "{{ LISTMONK_DESIGN_JS_MARKER }}"
|
||||
- key: "appearance.public.custom_css"
|
||||
template: "design/public.css.j2"
|
||||
marker: "{{ LISTMONK_DESIGN_CSS_MARKER }}"
|
||||
LISTMONK_DESIGN_BRANDING:
|
||||
- key: "app.logo_url"
|
||||
design: "{{ LISTMONK_DESIGN.urls.header.svg }}"
|
||||
fallback: "{{ service_provider.platform.logo }}"
|
||||
- key: "app.favicon_url"
|
||||
design: "{{ LISTMONK_DESIGN.urls.favicon_ico }}"
|
||||
fallback: "{{ service_provider.platform.favicon }}"
|
||||
- key: "app.site_name"
|
||||
design: "{{ LISTMONK_DESIGN.label }}"
|
||||
fallback: "{{ service_provider.company.titel }} Mailing list"
|
||||
|
||||
LISTMONK_MCP_ENABLED: "{{ lookup('config', application_id, 'services.listmonkmcp.enabled') | bool }}"
|
||||
LISTMONK_MCP_SERVICE_KEY: "listmonkmcp"
|
||||
LISTMONK_MCP_CONTAINER: "{{ lookup('config', application_id, 'services.listmonkmcp.name') }}"
|
||||
|
||||
Whitespace-only changes.
@@ -0,0 +1,3 @@
|
||||
from pathlib import Path
|
||||
|
||||
PROJECT_ROOT: Path = Path(__file__).resolve().parents[6]
|
||||
@@ -0,0 +1,155 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
import unittest
|
||||
|
||||
from jinja2 import Environment, FileSystemLoader, StrictUndefined, select_autoescape
|
||||
|
||||
from . import PROJECT_ROOT
|
||||
|
||||
TEMPLATES = PROJECT_ROOT / "roles/web-app-listmonk/templates"
|
||||
LOGO_FALLBACK = "https://files.example.com/logo.png"
|
||||
CSS_MARKER = ":root{--infinito-design-carrier:1}"
|
||||
JS_MARKER = "window.infinitoDesignCarrier = 1;"
|
||||
DESIGN = {
|
||||
"label": "Listmonk",
|
||||
"urls": {
|
||||
"favicon_ico": "https://cdn.example.com/design/favicon.ico",
|
||||
"header": {"svg": "https://cdn.example.com/design/header.svg"},
|
||||
"icon": {"svg": "https://cdn.example.com/design/icon.svg"},
|
||||
"logo": {"svg": "https://cdn.example.com/design/logo.svg"},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def render(enabled: bool, logo_fallback: str) -> str:
|
||||
"""
|
||||
Args:
|
||||
enabled: value of LISTMONK_DESIGN_ENABLED.
|
||||
logo_fallback: app.logo_url the role writes while design is off.
|
||||
"""
|
||||
env = Environment(
|
||||
loader=FileSystemLoader(str(TEMPLATES)),
|
||||
undefined=StrictUndefined,
|
||||
keep_trailing_newline=True,
|
||||
autoescape=select_autoescape(),
|
||||
)
|
||||
env.filters["bool"] = lambda value: (
|
||||
value if isinstance(value, bool) else str(value).lower() == "true"
|
||||
)
|
||||
env.filters["to_json"] = json.dumps
|
||||
context = {
|
||||
"LISTMONK_DESIGN": DESIGN,
|
||||
"LISTMONK_DESIGN_ENABLED": enabled,
|
||||
"LISTMONK_DESIGN_CSS_MARKER": CSS_MARKER,
|
||||
"LISTMONK_DESIGN_JS_MARKER": JS_MARKER,
|
||||
"LISTMONK_DESIGN_APPEARANCE": [
|
||||
{
|
||||
"key": "appearance.admin.custom_css",
|
||||
"template": "design/admin.css.j2",
|
||||
"marker": CSS_MARKER,
|
||||
},
|
||||
{
|
||||
"key": "appearance.admin.custom_js",
|
||||
"template": "design/admin.js.j2",
|
||||
"marker": JS_MARKER,
|
||||
},
|
||||
{
|
||||
"key": "appearance.public.custom_css",
|
||||
"template": "design/public.css.j2",
|
||||
"marker": CSS_MARKER,
|
||||
},
|
||||
],
|
||||
"LISTMONK_DESIGN_BRANDING": [
|
||||
{
|
||||
"key": "app.logo_url",
|
||||
"design": DESIGN["urls"]["header"]["svg"],
|
||||
"fallback": logo_fallback,
|
||||
},
|
||||
{
|
||||
"key": "app.site_name",
|
||||
"design": DESIGN["label"],
|
||||
"fallback": "Example Mailing list",
|
||||
},
|
||||
],
|
||||
}
|
||||
context["lookup"] = lambda kind, name: env.get_template(name).render(context)
|
||||
return env.get_template("design/appearance.sql.j2").render(context)
|
||||
|
||||
|
||||
def statements(sql: str) -> dict[str, str]:
|
||||
return {
|
||||
re.search(r"\nWHERE key = '([^']+)'", statement).group(1): statement
|
||||
for statement in sql.split("UPDATE settings\n")[1:]
|
||||
}
|
||||
|
||||
|
||||
class TestDesignAppearanceSql(unittest.TestCase):
|
||||
def test_design_on_writes_marked_content_only_over_empty_or_own_values(
|
||||
self,
|
||||
) -> None:
|
||||
updates = statements(render(enabled=True, logo_fallback=LOGO_FALLBACK))
|
||||
for key, marker in (
|
||||
("appearance.admin.custom_css", CSS_MARKER),
|
||||
("appearance.admin.custom_js", JS_MARKER),
|
||||
("appearance.public.custom_css", CSS_MARKER),
|
||||
):
|
||||
with self.subTest(key=key):
|
||||
self.assertIn(f"to_jsonb($infinito_value${marker}", updates[key])
|
||||
self.assertIn(
|
||||
f"starts_with(value #>> '{{}}', $infinito_marker${marker}$infinito_marker$)",
|
||||
updates[key],
|
||||
)
|
||||
self.assertIn("value IS DISTINCT FROM", updates[key])
|
||||
self.assertIn(DESIGN["urls"]["header"]["svg"], updates["app.logo_url"])
|
||||
self.assertIn(
|
||||
"$infinito_value$Listmonk$infinito_value$", updates["app.site_name"]
|
||||
)
|
||||
|
||||
def test_design_off_empties_only_the_marked_values_and_restores_the_fallback(
|
||||
self,
|
||||
) -> None:
|
||||
updates = statements(render(enabled=False, logo_fallback=LOGO_FALLBACK))
|
||||
for key in (
|
||||
"appearance.admin.custom_css",
|
||||
"appearance.admin.custom_js",
|
||||
"appearance.public.custom_css",
|
||||
):
|
||||
with self.subTest(key=key):
|
||||
self.assertIn(
|
||||
"SET value = to_jsonb($infinito_value$$infinito_value$::text)",
|
||||
updates[key],
|
||||
)
|
||||
self.assertIn(
|
||||
"starts_with(value #>> '{}', $infinito_marker$", updates[key]
|
||||
)
|
||||
self.assertIn(
|
||||
f"$infinito_value${LOGO_FALLBACK}$infinito_value$", updates["app.logo_url"]
|
||||
)
|
||||
self.assertIn(
|
||||
"$infinito_value$Example Mailing list$infinito_value$",
|
||||
updates["app.site_name"],
|
||||
)
|
||||
|
||||
def test_design_off_without_fallback_clears_only_the_design_value(self) -> None:
|
||||
update = statements(render(enabled=False, logo_fallback=""))["app.logo_url"]
|
||||
self.assertIn(
|
||||
f"AND value = to_jsonb($infinito_value${DESIGN['urls']['header']['svg']}",
|
||||
update,
|
||||
)
|
||||
|
||||
def test_the_carried_css_holds_no_literal_color(self) -> None:
|
||||
sql = render(enabled=True, logo_fallback=LOGO_FALLBACK)
|
||||
css = "\n".join(
|
||||
statement
|
||||
for key, statement in statements(sql).items()
|
||||
if key.endswith("custom_css")
|
||||
)
|
||||
self.assertIsNone(
|
||||
re.search(r"#[0-9a-fA-F]{3,8}(?![\w-])", re.sub(r"url\([^)]*\)", "", css))
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user