From b319bd762ba529bf39d9ccddcccb5f68b3696e0c Mon Sep 17 00:00:00 2001 From: Grok Bot Date: Fri, 20 Nov 2026 23:20:34 +0200 Subject: [PATCH] Implement MT 20 Nov badge rules in product code, with a one-shot shine and pop Gold tick only on an approved, paying school; .official stays after a gift ends and drops after a full refund. Unclaimed schools never get the tick. DFE authors use username.dfe, with a blue tick only while paying. Founding members get a gold compass, removed if the seat lapses. Guests, signed-in ATO replies, the directory, and static generator pages all draw the same inline SVG marks. CSS/SVG only: gold tick and gold compass shine once on first appear; the blue tick does a gentle scale pop. prefers-reduced-motion stays still. Tuned for Pearl, Midnight, Amethyst, and Champagne. No important cascade flags. Audit tests from go-around-design PR #30 are included, with handle regexes that allow the styled suffix span. --- ato-generator/generator.py | 3 +- ato-generator/svg.py | 32 +++- ato-generator/template/ato.html.j2 | 1 + ato-generator/template/parts/badges.j2 | 3 +- cloudflare/functions/_middleware.js | 8 +- cloudflare/lib/ato_review_html.mjs | 5 +- cloudflare/lib/reviews/data.mjs | 10 +- cloudflare/lib/reviews/data_auth.mjs | 14 +- cloudflare/lib/reviews/data_more.mjs | 23 ++- cloudflare/lib/reviews/projection.mjs | 10 +- site/assets/badges/badge-marks.mjs | 90 +++++++++ site/assets/badges/badges.css | 145 ++++++++++++++ site/assets/badges/badges.js | 168 +++++++++++++++-- site/assets/badges/founding-compass-gold.svg | 22 +++ site/ato/index.html | 2 + site/dfe/index.html | 2 + site/ga-directory.mjs | 24 ++- site/me/ato-member.js | 20 +- site/u/index.html | 1 + site/u/profile.mjs | 18 +- tests/reviews/access.test.mjs | 4 +- tests/reviews/added_rules.test.mjs | 3 +- tests/reviews/admin.test.mjs | 2 +- tests/reviews/audit_handles.test.mjs | 187 +++++++++++++++++++ tests/reviews/audit_handles_ui.test.mjs | 86 +++++++++ tests/reviews/security_gate.test.mjs | 2 + tools/reviews/export_for_generator.mjs | 4 +- 27 files changed, 835 insertions(+), 54 deletions(-) create mode 100644 site/assets/badges/badge-marks.mjs create mode 100644 site/assets/badges/badges.css create mode 100644 site/assets/badges/founding-compass-gold.svg create mode 100644 tests/reviews/audit_handles.test.mjs create mode 100644 tests/reviews/audit_handles_ui.test.mjs diff --git a/ato-generator/generator.py b/ato-generator/generator.py index 321a25d9..a9f362aa 100644 --- a/ato-generator/generator.py +++ b/ato-generator/generator.py @@ -57,7 +57,7 @@ CERT_KEYS = {"number", "valid_until", "updated", "current", "date"} REVIEW_KEYS = {"id", "author", "stars", "title", "text", "status", "published_at", "edited", "edited_at", "text_added_at", "up", "upvotes", "vote_records", "voteRecords", "official_replies", "cost", "when", "course", "courses", "trained_from", "trained_to", "still_training", "licence", "old_page", "duplicate", "rating_counted", "privacy_redacted"} -AUTHOR_KEYS = {"name", "anonymous", "badges", "licences", "handle"} +AUTHOR_KEYS = {"name", "anonymous", "badges", "licences", "handle", "display_name"} PRIVATE_KEYS = {"email_private", "private_author_id", "account_id", "author_id", "seat_no", "voter_id", "google_sub", "ip_hash"} PHONE_RE = re.compile(r"^[0-9+ ()-]{7,20}$") @@ -829,6 +829,7 @@ def page_model(ato, today, site=None, index=False, scrub_courses=True, show_cate a.setdefault("anonymous", False); a.setdefault("badges", []); a.setdefault("licences", []) if a["anonymous"]: # anonymous: no name, badges, licences or identifying extras a.update(name="", badges=[], licences=[]) + a.pop("display_name", None) a.pop("handle", None) for k in ("licence", "authorName", "displayName") + EXTRA_KEYS: rv.pop(k, None) diff --git a/ato-generator/svg.py b/ato-generator/svg.py index a369873e..7799afb0 100644 --- a/ato-generator/svg.py +++ b/ato-generator/svg.py @@ -23,31 +23,43 @@ IDS = Ids() def tick(colour, size=15, cls=""): a, b, f = IDS("ta"), IDS("tb"), IDS("tf") - c = f" {cls}" if cls else "" + clip, shine = IDS("tc"), IDS("ts") + extra = f" {cls}" if cls else "" + gold = "is-gold" in (cls or "") + shine_defs = ( + f'' + f'' + f'' + ) if gold else "" + shine_g = f'' if gold else "" return Markup( - f'') + f'{shine_g}') def tick_dfe(size=15): - return tick("#1D9BF0", size, "is-dfe") + return tick("#1D9BF0", size, "ga-badge is-dfe") def tick_ato(size=15): - return tick("#F5B83D", size) + return tick("#F5B83D", size, "ga-badge is-gold") def compass(size=15): - a, f = IDS("wa"), IDS("wf") + a, f, g, s, c = IDS("wa"), IDS("wf"), IDS("wg"), IDS("ws"), IDS("wc") return Markup( - f'Founding Member' + f'Founding Member' + f'' f'' - f'' - f'') + f'' + f'' + f'' + f'' + f'') def _w(frac): diff --git a/ato-generator/template/ato.html.j2 b/ato-generator/template/ato.html.j2 index 80350745..f098e473 100644 --- a/ato-generator/template/ato.html.j2 +++ b/ato-generator/template/ato.html.j2 @@ -15,6 +15,7 @@ + `, { html: true }); } - if (memberView) el.append('', { html: true }); + if (ATO_PAGE.test(path) && res.status === 200) { + el.append('', { html: true }); + } + if (memberView) { + el.append('', { html: true }); + el.append('', { html: true }); + } el.append('', { html: true }); // file 12 §10: on a tool page, a later 401 goes to sign-in with `next`, a 403 opens the Upgrade sheet. if (tool) el.append('', { html: true }); diff --git a/cloudflare/lib/ato_review_html.mjs b/cloudflare/lib/ato_review_html.mjs index a1c032a5..8c83e9f4 100644 --- a/cloudflare/lib/ato_review_html.mjs +++ b/cloudflare/lib/ato_review_html.mjs @@ -1,10 +1,11 @@ // The prebuilt ATO shell may be older than a moderation decision. Render // reviews from the same guest projection used by the public JSON endpoint. +import { nameLineHtml } from "../../site/assets/badges/badge-marks.mjs"; const entities = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }; const escape = (value) => String(value ?? "").replace(/[&<>"']/g, (c) => entities[c]); const note = '

Private details removed by moderation.

'; const opinion = `

Reviews are members' own opinions.

`; -const name = (author) => escape(author.label) + escape(author.suffix); +const name = (author) => nameLineHtml(author.label, author.suffix, author.mark, 16, { displayName: author.display_name }); const monthFormat = new Intl.DateTimeFormat("en-GB", { month: "short", year: "numeric", timeZone: "UTC" }); function replyCard(reply) { @@ -17,7 +18,7 @@ function reviewCard(review) { const anonymous = author.kind === "anonymous"; const initials = anonymous ? "" : ``; const chips = author.chips?.length ? `
${author.chips.map((chip) => `${escape(chip)}`).join("")}
` : ""; - const badge = author.mark === "founding" ? ' Founding' : ""; + const badge = ""; const stars = review.stars == null ? "" : `★ ${escape(review.stars)}`; const replies = review.replies.filter((reply) => reply.author.kind === "school"); const details = []; diff --git a/cloudflare/lib/reviews/data.mjs b/cloudflare/lib/reviews/data.mjs index e8c80a34..7b3fb6f4 100644 --- a/cloudflare/lib/reviews/data.mjs +++ b/cloudflare/lib/reviews/data.mjs @@ -12,7 +12,7 @@ import { CONFIG, CATEGORIES } from "./config.mjs"; import * as R from "./rules.mjs"; import { recomputeStatement, ratingCard, COLLECTED, schoolFamilyCte, reviewFamilyCte, SCHOOL_RATINGS_SQL, FAMILY_SCORE_ELIGIBLE_SQL, FAMILY_SEAT_VISIBLE_SQL, COUNTED_ACCOUNT_AGE_MS_SQL } from "./rating.mjs"; import { publicReview, publicReply, backupRow, memberBadges, schoolBadges } from "./projection.mjs"; -import { createMore } from "./data_more.mjs"; +import { createMore, SCHOOL_EVER_PREMIUM, SCHOOL_EVER_PREMIUM_FOR_LIST } from "./data_more.mjs"; import { alertNow } from "./notify.mjs"; import { createOwner } from "./data_admin.mjs"; import { createAuth, profileRoleLabel } from "./data_auth.mjs"; @@ -1049,7 +1049,8 @@ export function createData(db, opts = {}) { AND COALESCE(grace_until, ends_at) > ?2`, schoolId, t)); } async function schoolEverPaid(schoolId, t) { - return !!(await one("SELECT 1 AS x FROM entitlements WHERE school_id = ?1 AND kind = 'premium' AND starts_at <= ?2", schoolId, t)); + // ATO-08 (MT 20 Nov): a full refund drops .official; an ended gift still keeps it. + return !!(await one(`SELECT 1 AS x WHERE ${SCHOOL_EVER_PREMIUM}`, schoolId, t)); } async function schoolState(s, schoolId, t) { const paid = await schoolPaid(schoolId, t); @@ -1138,7 +1139,7 @@ export function createData(db, opts = {}) { const schools = await all(`SELECT s.id, s.slug, s.name, s.kind, s.status, s.handle, EXISTS (SELECT 1 FROM entitlements e WHERE e.school_id = s.id AND e.kind = 'premium' AND e.starts_at <= ?1 AND COALESCE(e.grace_until, e.ends_at) > ?1) AS paid, - EXISTS (SELECT 1 FROM entitlements e WHERE e.school_id = s.id AND e.kind = 'premium' AND e.starts_at <= ?1) AS ever_paid + ${SCHOOL_EVER_PREMIUM_FOR_LIST} AS ever_paid FROM schools s WHERE s.merged_into IS NULL ORDER BY s.name COLLATE NOCASE, s.slug LIMIT ?2`, t, cap + 1); const truncated = schools.length > cap; if (truncated) schools.pop(); @@ -1583,7 +1584,8 @@ export function createData(db, opts = {}) { spamFlags: spamFlagStmts }); const account = createAccount({ one, all, stmt, commit, audit, now, newId, sha256Hex, needFresh, extraSetting, codeHash, codeMatches, emailHash, emailCanonHash, emailBlocked }); const auth = createAuth({ one, all, stmt, commit, audit, now, newId, cfg, guardStop, sha256Hex, signupAllowed, loginAllowed, - issueTrial: more.issueTrial, account, extraSetting, needFresh, limited, hit, limits, peppers, codeHash, codeMatches, emailHash, emailCanonHash, emailBlocked, pii }); + issueTrial: more.issueTrial, account, extraSetting, needFresh, limited, hit, limits, peppers, codeHash, codeMatches, emailHash, emailCanonHash, emailBlocked, pii, + authorFacts }); const subs = createSubs({ one, all, stmt, commit, audit, now, newId, needFresh, extraSetting, operationalStatus: more.operationalStatus }); const school = createSchool({ one, all, stmt, commit, audit, now, newId, needActive, needAdmin, needFresh, schoolBySlug, extraSetting, subs, viewerForAccount, hit, limited, postTools: more.postTools }); diff --git a/cloudflare/lib/reviews/data_auth.mjs b/cloudflare/lib/reviews/data_auth.mjs index 858bbeb6..e2b72284 100644 --- a/cloudflare/lib/reviews/data_auth.mjs +++ b/cloudflare/lib/reviews/data_auth.mjs @@ -14,6 +14,7 @@ import { MEMBER_RP_ID, memberPasskeyOrigin } from "./app_origin.mjs"; import * as PW from "./passwords.mjs"; import * as R from "./rules.mjs"; import { verifyAssertion, verifyRegistration, randomChallenge, b64u } from "./admin_auth.mjs"; +import { memberBadges } from "./projection.mjs"; const MIN = 60 * 1000, DAY = 24 * 60 * MIN; const SIGNUP_LINK_PREFIX = "signup-link:"; @@ -992,12 +993,21 @@ export function createAuth(ctx) { const t = now(); return { terms: await latestLegal("terms", t), privacy: await latestLegal("privacy", t) }; } - /** "Search the DFE list" for the claim step. The DFE directory is public; only id, name and whether it is claimed. */ + /** Public DFE directory / claim search. Always id, name, claimed. A verified DFE also gets username.dfe and the tick mark (UI-12). */ async function searchDfes(raw) { const q = R.cleanText(raw).slice(0, 40); if (q.length < 2) return { dfes: [] }; const rows = await all("SELECT id, name, account_id FROM dfes WHERE name LIKE ?1 ESCAPE '\\' ORDER BY name LIMIT 10", `%${q.replace(/[\\%_]/g, (c) => `\\${c}`)}%`); - return { dfes: rows.map((d) => ({ id: d.id, name: d.name, claimed: !!d.account_id })) }; + const ids = [...new Set(rows.map((d) => d.account_id).filter(Boolean))]; + const facts = ctx.authorFacts && ids.length ? await ctx.authorFacts(ids, now()) : new Map(); + return { dfes: rows.map((d) => { + const out = { id: d.id, name: d.name, claimed: !!d.account_id }; + const f = d.account_id ? facts.get(d.account_id) : null; + if (!f) return out; + const b = memberBadges(f); + if (b.suffix === ".dfe") { out.label = f.username; out.suffix = ".dfe"; out.mark = b.mark; } + return out; + }) }; } const signupOpen = () => featureOn("feature_signup_open"); diff --git a/cloudflare/lib/reviews/data_more.mjs b/cloudflare/lib/reviews/data_more.mjs index 58599e17..8430b7d9 100644 --- a/cloudflare/lib/reviews/data_more.mjs +++ b/cloudflare/lib/reviews/data_more.mjs @@ -12,9 +12,30 @@ import { alertNow } from "./notify.mjs"; const DAY = 24 * 60 * 60 * 1000; const MODULES = ["announcement", "price", "job", "fleet", "intake", "link"]; // ATO-03–ATO-09 // ?1 is the school ID and ?2 is the evaluation time. +// MT 20 Nov (Q5 / UI-15): gifted Premium unlocks the same extras as a payment. Any active premium counts. export const PAID_SCHOOL_EXTRAS = `EXISTS (SELECT 1 FROM schools sc JOIN entitlements e ON e.school_id = sc.id - WHERE sc.id = ?1 AND sc.status = 'verified' AND e.kind = 'premium' AND e.source = 'payment' + WHERE sc.id = ?1 AND sc.status = 'verified' AND e.kind = 'premium' AND e.starts_at <= ?2 AND COALESCE(e.grace_until, e.ends_at) > ?2)`; +/** .official "ever paid" (ATO-08): a gift or admin grant still counts after it ends; a fully refunded or + * charged-back payment does not. Bound forms only — schoolEverPaid uses ?1/?2, the directory list uses s.id/?1. */ +export const SCHOOL_EVER_PREMIUM = `EXISTS ( + SELECT 1 FROM entitlements e + WHERE e.school_id = ?1 AND e.kind = 'premium' AND e.starts_at <= ?2 + AND (e.source IN ('gift', 'admin') + OR (e.source = 'payment' AND ( + SELECT COALESCE(SUM(a.amount_cents), 0) FROM payment_adjustments a + WHERE a.payment_id = e.payment_id AND a.kind IN ('refund', 'chargeback') + ) < (SELECT p.amount_cents FROM payments p WHERE p.id = e.payment_id))) + )`; +export const SCHOOL_EVER_PREMIUM_FOR_LIST = `EXISTS ( + SELECT 1 FROM entitlements e + WHERE e.school_id = s.id AND e.kind = 'premium' AND e.starts_at <= ?1 + AND (e.source IN ('gift', 'admin') + OR (e.source = 'payment' AND ( + SELECT COALESCE(SUM(a.amount_cents), 0) FROM payment_adjustments a + WHERE a.payment_id = e.payment_id AND a.kind IN ('refund', 'chargeback') + ) < (SELECT p.amount_cents FROM payments p WHERE p.id = e.payment_id))) + )`; const PLANS = ["guest", "free", "trial", "pro", "founding", "ato"]; const NEW_PAGE_DEFAULT = { guest: 0, free: 0, trial: 1, pro: 1, founding: 1, ato: 1 }; // SA-152 diff --git a/cloudflare/lib/reviews/projection.mjs b/cloudflare/lib/reviews/projection.mjs index 05acbc73..a046bdef 100644 --- a/cloudflare/lib/reviews/projection.mjs +++ b/cloudflare/lib/reviews/projection.mjs @@ -44,7 +44,8 @@ const hasBadge = (x) => (badge, fact) => { export function schoolBadges(s) { const has = hasBadge(s); const official = !!s.handle && has("official", s.official ?? s.verified); - return { label: official ? s.handle : s.name, suffix: official ? ".official" : null, mark: has("ato_gold", s.premium) ? "ato_gold" : null }; // DEC-010: gifted Premium shows the tick too + // Gold tick only while paying (paid or gifted) AND the claim is approved (ATO-03 / MT 20 Nov). + return { label: official ? s.handle : s.name, suffix: official ? ".official" : null, mark: official && has("ato_gold", s.premium) ? "ato_gold" : null }; } const day = (ms) => (ms ? sastDay(ms) : null); @@ -54,7 +55,12 @@ function author(row, a) { if (row.anonymous) return { kind: "anonymous", label: "Anonymous", mark: null, suffix: null, chips: [] }; // N-31 if (a.status === "banned") return { kind: "member", label: "Name withheld", mark: null, suffix: null, chips: [] }; if (a.status === "deleted") return { kind: "deleted", label: "Deleted user", ...memberBadges(a) }; // U-33 - return { kind: "member", label: a.display_name || a.username || "Member", ...memberBadges(a) }; + const badges = memberBadges(a); + // MT 20 Nov: the handle is username.dfe, with the display name shown above it (DFE-07). + if (badges.suffix === ".dfe") { + return { kind: "member", label: a.username || a.display_name || "Member", display_name: a.display_name || null, ...badges }; + } + return { kind: "member", label: a.display_name || a.username || "Member", ...badges }; } /** diff --git a/site/assets/badges/badge-marks.mjs b/site/assets/badges/badge-marks.mjs new file mode 100644 index 00000000..6db3859d --- /dev/null +++ b/site/assets/badges/badge-marks.mjs @@ -0,0 +1,90 @@ +// badge-marks.mjs — inline SVG marks for name lines (gold ATO tick, blue DFE tick, gold founding compass). +// Server and tests import this. The browser uses site/assets/badges/badges.js, which keeps the same shapes. +// Unique gradient ids per call so several marks can sit on one page. Animation classes live in badges.css. + +export const BODY = "M11.50 1.63Q12.00 1.40 12.50 1.63Q13.00 1.86 13.40 2.42Q13.79 2.98 14.09 3.56Q14.38 4.14 14.68 4.47Q14.98 4.79 15.43 4.78Q15.87 4.76 16.49 4.55Q17.11 4.35 17.79 4.24Q18.46 4.12 18.98 4.31Q19.50 4.50 19.69 5.02Q19.88 5.54 19.76 6.21Q19.65 6.89 19.45 7.51Q19.24 8.13 19.22 8.57Q19.21 9.02 19.53 9.32Q19.86 9.62 20.44 9.91Q21.02 10.21 21.58 10.60Q22.14 11.00 22.37 11.50Q22.60 12.00 22.37 12.50Q22.14 13.00 21.58 13.40Q21.02 13.79 20.44 14.09Q19.86 14.38 19.53 14.68Q19.21 14.98 19.22 15.43Q19.24 15.87 19.45 16.49Q19.65 17.11 19.76 17.79Q19.88 18.46 19.69 18.98Q19.50 19.50 18.98 19.69Q18.46 19.88 17.79 19.76Q17.11 19.65 16.49 19.45Q15.87 19.24 15.43 19.22Q14.98 19.21 14.68 19.53Q14.38 19.86 14.09 20.44Q13.79 21.02 13.40 21.58Q13.00 22.14 12.50 22.37Q12.00 22.60 11.50 22.37Q11.00 22.14 10.60 21.58Q10.21 21.02 9.91 20.44Q9.62 19.86 9.32 19.53Q9.02 19.21 8.57 19.22Q8.13 19.24 7.51 19.45Q6.89 19.65 6.21 19.76Q5.54 19.88 5.02 19.69Q4.50 19.50 4.31 18.98Q4.12 18.46 4.24 17.79Q4.35 17.11 4.55 16.49Q4.76 15.87 4.78 15.43Q4.79 14.98 4.47 14.68Q4.14 14.38 3.56 14.09Q2.98 13.79 2.42 13.40Q1.86 13.00 1.63 12.50Q1.40 12.00 1.63 11.50Q1.86 11.00 2.42 10.60Q2.98 10.21 3.56 9.91Q4.14 9.62 4.47 9.32Q4.79 9.02 4.78 8.57Q4.76 8.13 4.55 7.51Q4.35 6.89 4.24 6.21Q4.12 5.54 4.31 5.02Q4.50 4.50 5.02 4.31Q5.54 4.12 6.21 4.24Q6.89 4.35 7.51 4.55Q8.13 4.76 8.57 4.78Q9.02 4.79 9.32 4.47Q9.62 4.14 9.91 3.56Q10.21 2.98 10.60 2.42Q11.00 1.86 11.50 1.63Z"; +export const CHECK = "M8.273,14.295 L6.855,12.878 L8.325,11.460 L10.215,13.350 L15.675,8.100 L17.145,9.570 L11.580,15.660 Z"; +export const COMPASS = "M12.00 1.85 L13.47 8.44 L15.92 8.08 L15.56 10.53 L22.15 12.00 L15.56 13.47 L15.92 15.92 L13.47 15.56 L12.00 22.15 L10.53 15.56 L8.08 15.92 L8.44 13.47 L1.85 12.00 L8.44 10.53 L8.08 8.08 L10.53 8.44 Z M16.15 12.00A4.15 4.15 0 1 1 7.85 12.00A4.15 4.15 0 1 1 16.15 12.00Z"; + +export const ALT = Object.freeze({ founding: "Founding Member", dfe: "Verified DFE", ato_gold: "Verified ATO" }); + +let seq = 0; +export function resetBadgeIds() { seq = 0; } +const uid = (p) => `${p}${++seq}`; + +const esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c])); + +function shine(clipId, shineId) { + return ``; +} + +function shineDefs(clipPath, clipId, shineId) { + return `` + + `` + + `` + + `` + + ``; +} + +function tickSvg(fill, size, cls, title, withShine) { + const a = uid("ga"), b = uid("gb"), f = uid("gf"), c = uid("gc"), s = uid("gs"); + const goldFill = fill; + return `` + + `${esc(title)}` + + `` + + `` + + `` + + `` + + `` + + `` + + (withShine ? shineDefs(BODY, c, s) : "") + + `` + + `` + + `` + + `` + + (withShine ? shine(c, s) : "") + + ``; +} + +function compassSvg(size) { + const a = uid("wa"), f = uid("wf"), g = uid("wg"), c = uid("wc"), s = uid("ws"); + return `` + + `${ALT.founding}` + + `` + + `` + + `` + + `` + + `` + + `` + + `` + + `` + + shineDefs(COMPASS, c, s) + + `` + + `` + + `` + + shine(c, s) + + ``; +} + +/** Inline SVG for one mark, or "" when there is nothing to draw (including dfe_unpaid and pro). */ +export function markSvg(mark, size = 16) { + const px = Number(size) || 16; + if (mark === "dfe") return tickSvg("var(--ga-dfe, #1D9BF0)", px, "ga-badge is-dfe", ALT.dfe, false); + if (mark === "ato_gold") return tickSvg("var(--ga-gold, #F5B83D)", px, "ga-badge is-gold", ALT.ato_gold, true); + if (mark === "founding") return compassSvg(px); + return ""; +} + +/** HTML for one name line. displayName, when set, sits above the handle (username.dfe). */ +export function nameLineHtml(label, suffix, mark, size = 16, opts = {}) { + const px = Number(size) || 16; + const display = opts.displayName && opts.displayName !== label ? `${esc(opts.displayName)}` : ""; + let name = `${esc(label)}`; + if (suffix) name += `${esc(suffix)}`; + name += ""; + let markHtml = ""; + if (mark === "pro") markHtml = ''; + else if (mark && mark !== "dfe_unpaid") markHtml = markSvg(mark, px); + const line = `${name}${markHtml}`; + return display ? `${display}${line}` : line; +} diff --git a/site/assets/badges/badges.css b/site/assets/badges/badges.css new file mode 100644 index 00000000..7554662e --- /dev/null +++ b/site/assets/badges/badges.css @@ -0,0 +1,145 @@ +/* badges.css — name-line ticks and the founding compass (20 Nov 2026). + Pearl / Midnight / Amethyst / Champagne. Never raises the cascade with an important flag. Animation is one-shot; + prefers-reduced-motion keeps the marks still. */ + +/* Pearl (day / white) */ +:root, +html[data-theme="day"][data-pal="white"] { + --ga-gold: #E8B44A; + --ga-gold-hi: #F7E3A8; + --ga-gold-lo: #9C7424; + --ga-gold-line: #5A3F0A; + --ga-dfe: #1D9BF0; + --ga-official: #1D4ED8; + --ga-shine: rgba(255, 255, 255, .62); +} + +/* Midnight */ +html[data-theme="night"][data-pal="black"] { + --ga-gold: #F0C056; + --ga-gold-hi: #FFE9B0; + --ga-gold-lo: #B8892A; + --ga-gold-line: #F6E3A6; + --ga-dfe: #5CB6F5; + --ga-official: #8AB4FF; + --ga-shine: rgba(255, 255, 255, .5); +} + +/* Amethyst */ +html[data-theme="night"][data-pal="purple"] { + --ga-gold: #F0C056; + --ga-gold-hi: #FFE6B8; + --ga-gold-lo: #C4923A; + --ga-gold-line: #F6E3A6; + --ga-dfe: #7EB6F7; + --ga-official: #C4A5FF; + --ga-shine: rgba(255, 248, 255, .55); +} + +/* Champagne */ +html[data-theme="day"][data-pal="beige"] { + --ga-gold: #C8962A; + --ga-gold-hi: #F0D48A; + --ga-gold-lo: #8A6418; + --ga-gold-line: #5A3F0A; + --ga-dfe: #0B6FBF; + --ga-official: #1C4A8C; + --ga-shine: rgba(255, 255, 250, .58); +} + +.ga-who { + display: flex; + flex-direction: column; + align-items: flex-start; + gap: 0.08em; + min-width: 0; +} + +.ga-display { + font-size: 0.82em; + font-weight: 500; + letter-spacing: 0.01em; + opacity: 0.78; + line-height: 1.2; +} + +.ga-name-line { + display: inline-flex; + align-items: baseline; + gap: 0.28em; + min-width: 0; +} +.ga-name { + display: inline; + min-width: 0; +} + +.ga-suffix, +.official-suffix, +.dfe-suffix { + color: var(--ga-official, #1D4ED8); + font-weight: 600; +} + +.ga-badge, +svg.ga-badge, +svg.ico-rosette.is-gold, +svg.ico-rosette.is-dfe, +svg.ico-founding.is-gold { + width: 1.05em; + height: 1.05em; + display: inline-block; + vertical-align: -0.18em; + flex: 0 0 auto; + overflow: visible; +} + +.ga-badge-pro { + display: inline-block; + width: 1.05em; + height: 1.05em; + vertical-align: -0.18em; +} + +/* Gold tick + gold compass: a soft shine that crosses once on first appear. */ +.ga-badge.is-gold .ga-shine, +svg.ico-rosette.is-gold .ga-shine, +svg.ico-founding.is-gold .ga-shine { + animation: ga-shine-sweep 0.9s ease-out 0.12s 1 both; +} + +@keyframes ga-shine-sweep { + from { transform: translateX(-24px); } + to { transform: translateX(24px); } +} + +/* Blue DFE tick: a gentle scale pop, once. */ +.ga-badge.is-dfe, +svg.ico-rosette.is-dfe { + transform-origin: 50% 62%; + animation: ga-dfe-pop 0.42s cubic-bezier(0.2, 1.35, 0.32, 1) 1 both; +} + +@keyframes ga-dfe-pop { + 0% { transform: scale(0.82); } + 62% { transform: scale(1.1); } + 100% { transform: scale(1); } +} + +@media (prefers-reduced-motion: reduce) { + .ga-badge.is-gold .ga-shine, + svg.ico-rosette.is-gold .ga-shine, + svg.ico-founding.is-gold .ga-shine, + .ga-badge.is-dfe, + svg.ico-rosette.is-dfe { + animation: none; + } +} + +.ga-handle { + margin: 0.15em 0 0; + font-size: 0.78em; + line-height: 1.25; + color: var(--ga-official, #1D4ED8); + font-weight: 600; +} diff --git a/site/assets/badges/badges.js b/site/assets/badges/badges.js index 5766ff2e..da38f699 100644 --- a/site/assets/badges/badges.js +++ b/site/assets/badges/badges.js @@ -1,24 +1,166 @@ /* badges.js — draws the badge the SERVER computed (file 12 §17). Never decides a badge itself; never stores one. mark: 'founding' | 'pro' | 'dfe' | 'dfe_unpaid' | 'ato_gold' | null. suffix: '.dfe' | '.official' | null. - Uses the exact locked SVGs from badges/locked-9nov (9 Nov, MT t930u/t931u). Order: name -> suffix -> mark (MT t922u). - - Founding Member: compass. Pro: an empty slot until the Pro design exists. Trial, Free, Super Admin: nothing. + Inline SVG (crisp on retina). Order: display name (optional) -> name -> suffix -> mark (MT 20 Nov). + - Founding Member: gold compass. Pro: an empty slot until the Pro design exists. Trial, Free, Super Admin: nothing. - Verified DFE that pays: blue tick after username.dfe. Verified DFE that does not pay: ".dfe" only, no blue tick. - - Paying school: gold tick after name.official. Lapsed school: name.official, no tick. - - Anonymous posts: the server sends mark = null and suffix = null, so nothing is drawn. */ + - Paying, approved school: gold tick after handle.official. Lapsed school: handle.official, no tick. + - Anonymous posts: the server sends mark = null and suffix = null, so nothing is drawn. + attachNameLine writes with DOM nodes only (no innerHTML), for the signed-in ATO view. */ (function () { "use strict"; - var BASE = "/assets/badges/"; - var FILES = { founding: "founding-compass-locked.svg", dfe: "dfe-tick-locked.svg", ato_gold: "ato-tick-locked.svg" }; + var BODY = "M11.50 1.63Q12.00 1.40 12.50 1.63Q13.00 1.86 13.40 2.42Q13.79 2.98 14.09 3.56Q14.38 4.14 14.68 4.47Q14.98 4.79 15.43 4.78Q15.87 4.76 16.49 4.55Q17.11 4.35 17.79 4.24Q18.46 4.12 18.98 4.31Q19.50 4.50 19.69 5.02Q19.88 5.54 19.76 6.21Q19.65 6.89 19.45 7.51Q19.24 8.13 19.22 8.57Q19.21 9.02 19.53 9.32Q19.86 9.62 20.44 9.91Q21.02 10.21 21.58 10.60Q22.14 11.00 22.37 11.50Q22.60 12.00 22.37 12.50Q22.14 13.00 21.58 13.40Q21.02 13.79 20.44 14.09Q19.86 14.38 19.53 14.68Q19.21 14.98 19.22 15.43Q19.24 15.87 19.45 16.49Q19.65 17.11 19.76 17.79Q19.88 18.46 19.69 18.98Q19.50 19.50 18.98 19.69Q18.46 19.88 17.79 19.76Q17.11 19.65 16.49 19.45Q15.87 19.24 15.43 19.22Q14.98 19.21 14.68 19.53Q14.38 19.86 14.09 20.44Q13.79 21.02 13.40 21.58Q13.00 22.14 12.50 22.37Q12.00 22.60 11.50 22.37Q11.00 22.14 10.60 21.58Q10.21 21.02 9.91 20.44Q9.62 19.86 9.32 19.53Q9.02 19.21 8.57 19.22Q8.13 19.24 7.51 19.45Q6.89 19.65 6.21 19.76Q5.54 19.88 5.02 19.69Q4.50 19.50 4.31 18.98Q4.12 18.46 4.24 17.79Q4.35 17.11 4.55 16.49Q4.76 15.87 4.78 15.43Q4.79 14.98 4.47 14.68Q4.14 14.38 3.56 14.09Q2.98 13.79 2.42 13.40Q1.86 13.00 1.63 12.50Q1.40 12.00 1.63 11.50Q1.86 11.00 2.42 10.60Q2.98 10.21 3.56 9.91Q4.14 9.62 4.47 9.32Q4.79 9.02 4.78 8.57Q4.76 8.13 4.55 7.51Q4.35 6.89 4.24 6.21Q4.12 5.54 4.31 5.02Q4.50 4.50 5.02 4.31Q5.54 4.12 6.21 4.24Q6.89 4.35 7.51 4.55Q8.13 4.76 8.57 4.78Q9.02 4.79 9.32 4.47Q9.62 4.14 9.91 3.56Q10.21 2.98 10.60 2.42Q11.00 1.86 11.50 1.63Z"; + var CHECK = "M8.273,14.295 L6.855,12.878 L8.325,11.460 L10.215,13.350 L15.675,8.100 L17.145,9.570 L11.580,15.660 Z"; + var COMPASS = "M12.00 1.85 L13.47 8.44 L15.92 8.08 L15.56 10.53 L22.15 12.00 L15.56 13.47 L15.92 15.92 L13.47 15.56 L12.00 22.15 L10.53 15.56 L8.08 15.92 L8.44 13.47 L1.85 12.00 L8.44 10.53 L8.08 8.08 L10.53 8.44 Z M16.15 12.00A4.15 4.15 0 1 1 7.85 12.00A4.15 4.15 0 1 1 16.15 12.00Z"; var ALT = { founding: "Founding Member", dfe: "Verified DFE", ato_gold: "Verified ATO" }; + var NS = "http://www.w3.org/2000/svg"; + var seq = 0; + function uid(p) { return p + (++seq); } function esc(s) { return String(s == null ? "" : s).replace(/[&<>"']/g, function (c) { return "&#" + c.charCodeAt(0) + ";"; }); } - /** HTML for one name line. size: 14 | 16 | 20 (tick-sized, badge-look rules). */ - function nameLine(label, suffix, mark, size) { - var px = size || 16, out = '' + esc(label); + + function svgEl(name, attrs) { + var el = document.createElementNS(NS, name), k; + for (k in attrs || {}) el.setAttribute(k, attrs[k]); + return el; + } + function stop(parent, off, color, op) { + var s = svgEl("stop", { offset: off, "stop-color": color }); + if (op != null) s.setAttribute("stop-opacity", op); + parent.appendChild(s); + } + function path(d, attrs) { var p = svgEl("path", attrs || {}); p.setAttribute("d", d); return p; } + + function addShine(svg, clipD) { + var clipId = uid("gc"), shineId = uid("gs"); + var defs = svg.querySelector("defs") || svg.insertBefore(svgEl("defs"), svg.firstChild); + var grad = svgEl("linearGradient", { id: shineId, x1: "0", y1: "0", x2: "1", y2: "0", gradientUnits: "objectBoundingBox" }); + stop(grad, "0", "#fff", "0"); stop(grad, ".5", "#fff", ".85"); stop(grad, "1", "#fff", "0"); + defs.appendChild(grad); + var clip = svgEl("clipPath", { id: clipId }); + clip.appendChild(path(clipD)); + defs.appendChild(clip); + var g = svgEl("g", { "clip-path": "url(#" + clipId + ")" }); + g.appendChild(svgEl("rect", { "class": "ga-shine", x: "-20", y: "0", width: "14", height: "24", fill: "url(#" + shineId + ")", "pointer-events": "none" })); + svg.appendChild(g); + } + + function tickNode(fill, size, cls, title, withShine) { + var a = uid("ga"), b = uid("gb"), f = uid("gf"); + var svg = svgEl("svg", { "class": cls, viewBox: "0 0 24 24", width: String(size), height: String(size), role: "img", "aria-label": title, "data-ga": "badge" }); + var defs = svgEl("defs"); + var g1 = svgEl("linearGradient", { id: a, x1: "12", y1: "1.5", x2: "12", y2: "22.5", gradientUnits: "userSpaceOnUse" }); + stop(g1, "0", "#fff", ".26"); stop(g1, ".45", "#fff", "0"); stop(g1, "1", "#000", ".18"); + var g2 = svgEl("linearGradient", { id: b, x1: "12", y1: "1.5", x2: "12", y2: "9", gradientUnits: "userSpaceOnUse" }); + stop(g2, "0", "#fff", ".48"); stop(g2, "1", "#fff", "0"); + var filter = svgEl("filter", { id: f, x: "-35%", y: "-35%", width: "170%", height: "170%", "color-interpolation-filters": "sRGB" }); + filter.appendChild(svgEl("feDropShadow", { dx: "0", dy: "1", stdDeviation: "1", "flood-color": "#000", "flood-opacity": ".28" })); + defs.appendChild(g1); defs.appendChild(g2); defs.appendChild(filter); + svg.appendChild(defs); + var g = svgEl("g", { filter: "url(#" + f + ")" }); + g.appendChild(path(BODY, { fill: fill })); + g.appendChild(path(BODY, { fill: "url(#" + a + ")" })); + g.appendChild(path(BODY, { fill: "url(#" + b + ")" })); + g.appendChild(path(BODY, { fill: "none", stroke: "#000", "stroke-opacity": ".28", "stroke-width": ".75" })); + g.appendChild(path(CHECK, { fill: "#fff" })); + svg.appendChild(g); + var t = svgEl("title"); t.textContent = title; svg.insertBefore(t, svg.firstChild); + if (withShine) addShine(svg, BODY); + return svg; + } + + function compassNode(size) { + var a = uid("wa"), f = uid("wf"), g = uid("wg"); + var svg = svgEl("svg", { "class": "ga-badge is-gold ico-founding ico-compass", viewBox: "0 0 24 24", width: String(size), height: String(size), role: "img", "aria-label": ALT.founding, "data-ga": "badge", "data-badge": "founding" }); + var defs = svgEl("defs"); + var gold = svgEl("linearGradient", { id: g, x1: "5", y1: "3", x2: "19", y2: "21", gradientUnits: "userSpaceOnUse" }); + stop(gold, "0", "var(--ga-gold-hi, #F6E3A6)"); stop(gold, ".45", "var(--ga-gold, #D4AE52)"); stop(gold, "1", "var(--ga-gold-lo, #9C7424)"); + var glass = svgEl("linearGradient", { id: a, x1: "6", y1: "4", x2: "18", y2: "18", gradientUnits: "userSpaceOnUse" }); + stop(glass, "0", "#fff", ".35"); stop(glass, ".55", "#fff", "0"); stop(glass, "1", "#000", ".18"); + var filter = svgEl("filter", { id: f, x: "-40%", y: "-40%", width: "180%", height: "180%", "color-interpolation-filters": "sRGB" }); + filter.appendChild(svgEl("feDropShadow", { dx: "0", dy: "1", stdDeviation: ".9", "flood-color": "#5A3F0A", "flood-opacity": ".35" })); + defs.appendChild(gold); defs.appendChild(glass); defs.appendChild(filter); + svg.appendChild(defs); + var body = svgEl("g", { filter: "url(#" + f + ")" }); + body.appendChild(path(COMPASS, { fill: "url(#" + g + ")" })); + body.appendChild(path(COMPASS, { fill: "url(#" + a + ")" })); + body.appendChild(path(COMPASS, { fill: "none", stroke: "var(--ga-gold-line, #5A3F0A)", "stroke-opacity": ".45", "stroke-width": ".55" })); + svg.appendChild(body); + var t = svgEl("title"); t.textContent = ALT.founding; svg.insertBefore(t, svg.firstChild); + addShine(svg, COMPASS); + return svg; + } + + function markNode(mark, size) { + var px = size || 16; + if (mark === "dfe") { var n = tickNode("var(--ga-dfe, #1D9BF0)", px, "ga-badge is-dfe", ALT.dfe, false); n.setAttribute("data-badge", "dfe"); return n; } + if (mark === "ato_gold") { var g = tickNode("var(--ga-gold, #F5B83D)", px, "ga-badge is-gold", ALT.ato_gold, true); g.setAttribute("data-badge", "ato_gold"); return g; } + if (mark === "founding") return compassNode(px); + return null; + } + + function markHtml(mark, size) { + var node = markNode(mark, size); + return node ? new XMLSerializer().serializeToString(node) : ""; + } + + /** HTML for one name line. size: 14 | 16 | 20. opts.displayName sits above the handle. */ + function nameLine(label, suffix, mark, size, opts) { + var px = size || 16, display = opts && opts.displayName && opts.displayName !== label + ? '' + esc(opts.displayName) + "" : ""; + var out = '' + esc(label); if (suffix) out += '' + esc(suffix) + ""; out += ""; - if (mark === "pro") out += ''; // slot only - else if (FILES[mark]) out += '' + ALT[mark] + ''; - return out; + if (mark === "pro") out += ''; + else if (mark && mark !== "dfe_unpaid") out += markHtml(mark, px); + var line = '' + out + ""; + return display ? '' + display + line + "" : line; + } + + /** Append a name line to `el` with textContent / SVG nodes only (never innerHTML). */ + function attachNameLine(el, parts) { + if (!el) return el; + var label = parts && parts.label != null ? String(parts.label) : ""; + var suffix = parts && parts.suffix; + var mark = parts && parts.mark; + var size = (parts && parts.size) || 16; + var displayName = parts && parts.displayName; + var root = el; + if (displayName && displayName !== label) { + root = document.createElement("span"); + root.className = "ga-who"; + var d = document.createElement("span"); + d.className = "ga-display"; + d.textContent = displayName; + root.appendChild(d); + el.appendChild(root); + } + var line = document.createElement("span"); + line.className = "ga-name-line"; + var name = document.createElement("span"); + name.className = "ga-name"; + name.setAttribute("data-ga", "name"); + name.appendChild(document.createTextNode(label)); + if (suffix) { + var suf = document.createElement("span"); + suf.className = "ga-suffix"; + suf.setAttribute("data-ga", "suffix"); + suf.textContent = suffix; + name.appendChild(suf); + } + line.appendChild(name); + if (mark === "pro") { + var slot = document.createElement("span"); + slot.className = "ga-badge ga-badge-pro"; + slot.setAttribute("data-ga", "badge"); + slot.setAttribute("data-badge", "pro"); + slot.setAttribute("aria-hidden", "true"); + line.appendChild(slot); + } else { + var badge = markNode(mark, size); + if (badge) line.appendChild(badge); + } + root.appendChild(line); + return el; } - window.GoAroundBadges = { nameLine: nameLine }; + + window.GoAroundBadges = { nameLine: nameLine, attachNameLine: attachNameLine, markNode: markNode }; })(); diff --git a/site/assets/badges/founding-compass-gold.svg b/site/assets/badges/founding-compass-gold.svg new file mode 100644 index 00000000..4ba9f076 --- /dev/null +++ b/site/assets/badges/founding-compass-gold.svg @@ -0,0 +1,22 @@ + diff --git a/site/ato/index.html b/site/ato/index.html index 7639a160..1f664b40 100644 --- a/site/ato/index.html +++ b/site/ato/index.html @@ -9,8 +9,10 @@ + + diff --git a/site/dfe/index.html b/site/dfe/index.html index 69a1ca4e..9826f76e 100644 --- a/site/dfe/index.html +++ b/site/dfe/index.html @@ -9,8 +9,10 @@ + + diff --git a/site/ga-directory.mjs b/site/ga-directory.mjs index 251e1dbb..3d61401e 100644 --- a/site/ga-directory.mjs +++ b/site/ga-directory.mjs @@ -12,13 +12,17 @@ export function schoolCards(schools, query = "") { if (!words.every((word) => search.includes(word))) return []; const anchor = typeof cert?.anchor === "string" ? `#${encodeURIComponent(cert.anchor)}` : ""; const score = school.rating?.score; - return [{ + const card = { name: school.name, href: `/ato/${school.slug}/${anchor}`, facts: [school.kind, cert?.number, CERTIFICATE_STATE.get(cert?.state)].filter(Boolean).join(" · "), location: [cert?.town, cert?.base].filter(Boolean).join(" · "), score: school.rating?.shown === true && typeof score === "string" && /^(?:[1-4]\.\d|5\.0)$/.test(score) ? `${score} out of 5` : "", - }]; + }; + // UI-04 (MT 20 Nov): School Name + gold tick, handle.official small beneath. + if (school.mark) card.mark = school.mark; + if (school.suffix === ".official") card.handle = `${school.label || school.handle || ""}.official`; + return [card]; }); }); } @@ -47,8 +51,17 @@ export function buildDirectory(root, api, create) { detail.className = "entry-feature"; if (item.href) detail.href = item.href; const heading = create("h2"); + heading.className = "ga-name-line"; heading.textContent = item.name; + if (item.mark && window.GoAroundBadges?.markNode) heading.append(window.GoAroundBadges.markNode(item.mark, 16)); + else if (item.mark) heading.setAttribute("data-badge", item.mark); detail.append(heading); + if (item.handle) { + const handle = create("p"); + handle.className = "ga-handle"; + handle.textContent = item.handle; + detail.append(handle); + } for (const value of [item.facts, item.location, item.score]) { if (!value) continue; const line = create("p"); @@ -107,7 +120,12 @@ export function buildDirectory(root, api, create) { return; } if (examiner) { - const items = rows.slice(0, 10).filter((row) => typeof row?.name === "string").map(({ name }) => ({ name })); + const items = rows.slice(0, 10).filter((row) => typeof row?.name === "string").map((row) => { + const item = { name: row.name }; + if (row.mark) item.mark = row.mark; + if (row.suffix === ".dfe" && row.label) item.handle = `${row.label}.dfe`; + return item; + }); list(items, items.length === 10 ? "Showing up to 10 matches. Use a more specific name to narrow your search." : items.length ? `${items.length} ${items.length === 1 ? "examiner" : "examiners"} found.` : "No examiners match that name."); } else { diff --git a/site/me/ato-member.js b/site/me/ato-member.js index 6e4a7e48..87cad09e 100644 --- a/site/me/ato-member.js +++ b/site/me/ato-member.js @@ -22,7 +22,18 @@ for (i = 2; i < arguments.length; i++) if (arguments[i] != null) e.appendChild(typeof arguments[i] === "string" ? document.createTextNode(arguments[i]) : arguments[i]); return e; } - function call(method, path, body) { + + function whoLine(node, who, fallback) { + var label = (who && who.label) || fallback; + if (window.GoAroundBadges && window.GoAroundBadges.attachNameLine) { + window.GoAroundBadges.attachNameLine(node, { label: label, suffix: who && who.suffix, mark: who && who.mark, size: 16, displayName: who && who.display_name }); + return node; + } + node.textContent = label + ((who && who.suffix) || ""); + return node; + } + + function call(method, path, body) { var init = { method: method, credentials: "same-origin", headers: { accept: "application/json" } }; if (body !== undefined) { init.headers["content-type"] = "application/json"; init.body = JSON.stringify(body); } return fetch(path, init).then(function (r) { return r.json().catch(function () { return {}; }).then(function (b) { return { ok: r.ok, status: r.status, body: b }; }); }) @@ -57,9 +68,10 @@ } function replyNode(p) { - var who = p.author || {}, name = who.kind === "school" ? (who.label || "ATO") + (who.suffix || "") : (who.label || "Member"); + var who = p.author || {}, strong = el("strong"); + whoLine(strong, who, who.kind === "school" ? "ATO" : "Member"); return el("div", { cls: "ob-reply is-" + (who.kind === "school" ? "own" : "other"), "data-id": p.id }, - el("strong", { text: name }), el("small", { text: (who.kind === "school" ? "Official reply · " : "") + (p.date || "") + (p.edited ? " · edited" : "") }), el("p", { text: p.text || "" }), p.privacy_redacted ? el("small", { text: "Private details removed by moderation." }) : null, + strong, el("small", { text: (who.kind === "school" ? "Official reply · " : "") + (p.date || "") + (p.edited ? " · edited" : "") }), el("p", { text: p.text || "" }), p.privacy_redacted ? el("small", { text: "Private details removed by moderation." }) : null, !p.mine && state.can.vote ? voteRow("reply", p.id, p.up) : null, state.can.report ? reportForm("reply", p.id) : null); } function voteRow(type, id, up) { @@ -95,7 +107,7 @@ var art = el("article", { cls: "ob-review" + (anon ? " is-anon" : ""), "data-id": r.id }); art.appendChild(el("div", { cls: "ob-rtop" + (anon ? " is-anon" : "") }, anon ? null : el("span", { cls: "ob-av", text: String(a.label || "M").slice(0, 2).toUpperCase() }), - el("div", { cls: "ob-who" }, el("h3", { text: a.label || "Member" }), (a.chips || []).length ? el("small", { text: a.chips.join(" · ") }) : null), + el("div", { cls: "ob-who" }, whoLine(el("h3"), a, "Member"), (a.chips || []).length ? el("small", { text: a.chips.join(" · ") }) : null), el("time", { text: r.date || "" }))); art.appendChild(el("div", { cls: "ob-rscore" }, stars(r.stars), r.edited ? el("span", { cls: "ob-edtag", text: "Edited " + r.edited }) : null, r.mine ? el("span", { cls: "ob-edtag", text: "Your review" }) : null)); var details = []; diff --git a/site/u/index.html b/site/u/index.html index d587bd0a..a045b5c0 100644 --- a/site/u/index.html +++ b/site/u/index.html @@ -6,6 +6,7 @@ Go Around · Pilot + diff --git a/site/u/profile.mjs b/site/u/profile.mjs index c7577c4c..bf2f7738 100644 --- a/site/u/profile.mjs +++ b/site/u/profile.mjs @@ -73,10 +73,20 @@ function renderProfile(root, data) { for (const el of root.querySelectorAll("[data-own]")) el.hidden = !data.own; const { identity } = data; - const label = identity.display_name || identity.username || "Member"; - if (window.GoAroundBadges) slot("name-line").innerHTML = window.GoAroundBadges.nameLine(label, identity.suffix, identity.badge, 20); - else slot("name-line").textContent = label; - slot("username").textContent = identity.username ? `@${identity.username}` : ""; + const dfe = identity.suffix === ".dfe"; + const label = dfe ? (identity.username || identity.display_name || "Member") + : (identity.display_name || identity.username || "Member"); + const nameSlot = slot("name-line"); + nameSlot.replaceChildren(); + if (window.GoAroundBadges?.attachNameLine) { + window.GoAroundBadges.attachNameLine(nameSlot, { + label, suffix: identity.suffix, mark: identity.badge, size: 20, + displayName: dfe ? identity.display_name : null, + }); + } else if (window.GoAroundBadges) nameSlot.innerHTML = window.GoAroundBadges.nameLine(label, identity.suffix, identity.badge, 20, { displayName: dfe ? identity.display_name : null }); + else nameSlot.textContent = label + (identity.suffix || ""); + // username.dfe already sits on the name line, so the @username slot stays empty for a DFE. + slot("username").textContent = dfe ? "" : (identity.username ? `@${identity.username}` : ""); slot("role").textContent = identity.role || ""; slot("role").hidden = !identity.role; diff --git a/tests/reviews/access.test.mjs b/tests/reviews/access.test.mjs index 6399c752..78d94cda 100644 --- a/tests/reviews/access.test.mjs +++ b/tests/reviews/access.test.mjs @@ -173,7 +173,7 @@ test("audit L1: every file in site/ is either on the hand-typed public allow-lis assert.deepEqual(stray, [], "public but not on the allow-list"); // 17 Nov 2026: 120 -> 130 for the /owner/ screen scripts (owner-money.js, owner-badges.js). /owner/ has its own lock // (Cloudflare Access + the owner passkey on every /api/admin call); its files are code only, never data. - assert.ok(pub.length < 138, `${pub.length} public files: the public part of the site should stay small`); + assert.ok(pub.length < 145, `${pub.length} public files: the public part of the site should stay small`); // 20 Nov 2026: + badge CSS, inline marks, gold compass // every /appdata/ file, every *-data.js, every data file outside the public folders is locked (as before) for (const p of files.filter((x) => x.startsWith("/appdata/") || /data[^/]*\.m?js$/i.test(x) || /\.(json|csv|pdf|zip|txt|xml)$/i.test(x))) { if (ALLOWED_PUBLIC_ROOT.has(p) || ALLOWED_PUBLIC_FOLDERS.some((d) => p.startsWith(d))) continue; @@ -281,7 +281,7 @@ test("MT final rule (12 Nov 2026): EVERY file in site/ answers a guest with a se assert.equal(r.cache, "private, no-store", p); blocked++; } - assert.ok(blocked > 4300 && open200 < 138, `${blocked} blocked, ${open200} open`); // 17 Nov 2026: + the /owner/ screen scripts + assert.ok(blocked > 4300 && open200 < 145, `${blocked} blocked, ${open200} open`); // 20 Nov 2026: + badge CSS, inline marks, gold compass for (const p of ["/ato/", "/ato/alpha-flight/", "/dfe", "/dfe/", "/", "/login/", "/plans/", "/legal/terms/", "/privacy.html", "/welcome/", "/locked/"]) assert.equal((await open(p)).status, 200, p); for (const p of ["/index.html", "/main.html", "/app.html", "/ad/FACT.html", "/c/app.html", "/calculator.html", "/status.html", "/logbook.html", "/pilot.html", "/library.html"]) diff --git a/tests/reviews/added_rules.test.mjs b/tests/reviews/added_rules.test.mjs index 25c39208..3aaf1c77 100644 --- a/tests/reviews/added_rules.test.mjs +++ b/tests/reviews/added_rules.test.mjs @@ -484,9 +484,8 @@ test("19 Nov: page extras open when a verified school first pays and close when const w = world(), mt = await w.as(w.admin()); await w.data.adminSetSetting(mt, "module_announcement", "1", "on"); const opId = w.schoolAccount("s-alpha"); - w.paySchool("s-alpha"); const body = { title: "Open day" }; - await refused(assert, w.data.submitSchoolPost(await w.as(opId), "announcement", body), "ATO-10", "paid_verified_required"); + await refused(assert, w.data.submitSchoolPost(await w.as(opId), "announcement", body), "B-17"); // claimed but not paying (ATO-10 is reached only when extras are the remaining gate) w.paySchool("s-alpha", { from: T0, to: T0 + 30 * DAY, paid: true }); const p = await w.data.submitSchoolPost(await w.as(opId), "announcement", body); await w.data.adminReviewSchoolPost(mt, p.id, true, "ok"); diff --git a/tests/reviews/admin.test.mjs b/tests/reviews/admin.test.mjs index f664b909..7d1813a3 100644 --- a/tests/reviews/admin.test.mjs +++ b/tests/reviews/admin.test.mjs @@ -372,7 +372,7 @@ test("SA-52 / SA-27 / SA-184: a gift shows its exact preview, is added after cur assert.equal((await w.as(m)).plan, "free"); const sg = await act("gift", "s-beta", { school: true, kind: "premium", days: 90 }); assert.equal(sg.status, 200); - assert.equal((await w.data.listSchoolsPublic()).schools.find((s) => s.slug === "beta-air").mark, "ato_gold"); // DEC-010 + assert.equal((await w.data.listSchoolsPublic()).schools.find((s) => s.slug === "beta-air").mark, null); // ATO-03 (MT 20 Nov): a gift on an unclaimed school does not get the gold tick }); test("12 Nov 01:37 (replaces Q118 / SA-23 add_offer): prices change on the Prices page only; add_offer is gone", async () => { diff --git a/tests/reviews/audit_handles.test.mjs b/tests/reviews/audit_handles.test.mjs new file mode 100644 index 00000000..547d4324 --- /dev/null +++ b/tests/reviews/audit_handles.test.mjs @@ -0,0 +1,187 @@ +// audit_handles.test.mjs — PROPOSED audit for MT's rule (20 Nov 2026, SAST): +// "Once a DFE or an ATO pays and is approved, the name shows as name.dfe (blue DFE tick) / school.official (gold tick while paying)." +// Drop into go-around-launch-11nov/tests/reviews/ and run: node --test tests/reviews/audit_handles.test.mjs +// Read-only audit: it changes no product code. Every test is one row of the state table in AUDIT-HANDLES.md. +// Tests marked DECIDED 20 Nov (MT) follow MT's answers of 20 Nov 2026, 22:52-22:54 SAST. No question is open. +import test from "node:test"; +import assert from "node:assert/strict"; +import { world, ALL5, DAY, T0 } from "./helpers/fixture.mjs"; + +const YEAR = 365 * DAY; +const pick = (x) => [x.label, x.suffix ?? null, x.mark ?? null]; + +// ---------------------------------------------------------------- helpers +function dfe(w, accountId, { until = T0 + YEAR, id = `dfe-${accountId}` } = {}) { + w.run("INSERT INTO dfes (id, name, source_date, account_id, verified_until) VALUES (?, ?, '2026-11-01', ?, ?)", id, `DFE ${accountId}`, accountId, until); + return id; +} +async function memberAsAuthor(w, accountId) { + await w.review(accountId); + const pub = await w.data.getSchoolPublic("alpha-flight"); + const row = w.get("SELECT display_name, username FROM accounts WHERE id = ?", accountId); + return pub.reviews.find((r) => r.author.kind !== "anonymous" && (r.author.label === row.display_name || r.author.label === row.username || r.author.display_name === row.display_name)).author; +} +async function pilotIdentity(w, accountId) { + const viewer = await w.as(w.member("pro")); + const u = w.get("SELECT username FROM accounts WHERE id = ?", accountId).username; + return (await w.data.getPilotPage(viewer, u)).identity; +} +const dirCard = async (w, slug) => (await w.data.listSchoolsPublic()).schools.find((s) => s.slug === slug); +const pageSchool = async (w, slug) => (await w.data.getSchoolPublic(slug)).school; +function paidSchool(w, schoolId, { from = T0 - DAY, to = T0 + 30 * DAY } = {}) { w.paySchool(schoolId, { from, to, paid: true }); } +function giftSchool(w, schoolId, { from = T0 - DAY, to = T0 + 30 * DAY } = {}) { + w.run(`INSERT INTO entitlements (id, school_id, kind, source, starts_at, ends_at, created_at) VALUES (?, ?, 'premium', 'gift', ?, ?, ?)`, `gift-${schoolId}-${from}`, schoolId, from, to, T0); +} + +// ================================================================= DFE (.dfe + blue tick) +test("DFE-01 unverified, unpaid: plain name, no .dfe, no tick", async () => { + const w = world(); const m = w.member("free"); + assert.deepEqual(pick(await memberAsAuthor(w, m)).slice(1), [null, null]); +}); +test("DFE-02 paid Pro, DFE claim still pending: no .dfe, no tick", async () => { + const w = world(); const m = w.member("pro"); + w.run("INSERT INTO dfes (id, name, source_date) VALUES ('d1', 'DFE x', '2026-11-01')"); + w.run("INSERT INTO dfe_claims (id, account_id, dfe_id, status, created_at) VALUES ('c1', ?, 'd1', 'pending', ?)", m, T0); + const a = await memberAsAuthor(w, m); + assert.deepEqual([a.suffix, a.mark === "dfe" || a.mark === "dfe_unpaid"], [null, false]); // the Pro slot ("pro") may stay +}); +test("DFE-03 DECIDED 20 Nov (MT) approved but NOT paying (Free): keeps name.dfe, NO blue tick", async () => { + const w = world(); const m = w.member("free"); dfe(w, m); + assert.deepEqual(pick(await memberAsAuthor(w, m)).slice(1), [".dfe", "dfe_unpaid"]); // dfe_unpaid = no tick drawn +}); +test("DFE-04 DECIDED 20 Nov (MT) approved, on Trial (not paid): same as DFE-03, name.dfe with no tick", async () => { + const w = world(); const m = w.member("trial"); dfe(w, m); + assert.deepEqual(pick(await memberAsAuthor(w, m)).slice(1), [".dfe", "dfe_unpaid"]); +}); +test("DFE-05 approved + paid Pro: .dfe + blue tick on reviews", async () => { + const w = world(); const m = w.member("pro"); dfe(w, m); + assert.deepEqual(pick(await memberAsAuthor(w, m)).slice(1), [".dfe", "dfe"]); +}); +test("DFE-06 approved + Founding: .dfe + blue tick (DFE wins over the compass)", async () => { + const w = world(); const m = w.member("founding"); dfe(w, m); + assert.deepEqual(pick(await memberAsAuthor(w, m)).slice(1), [".dfe", "dfe"]); +}); +test("DFE-07 DECIDED 20 Nov (MT) the handle text is the USERNAME: username.dfe (display name shown above it)", async () => { + const w = world(); const m = w.member("pro"); dfe(w, m); + const a = await memberAsAuthor(w, m); + assert.equal(a.label + a.suffix, w.get("SELECT username FROM accounts WHERE id = ?", m).username + ".dfe"); // code today: display name + .dfe +}); +test("DFE-08 pilot page shows the same .dfe + tick as reviews", async () => { + const w = world(); const m = w.member("pro"); dfe(w, m); + const id = await pilotIdentity(w, m); + assert.deepEqual([id.suffix, id.badge], [".dfe", "dfe"]); +}); +test("DFE-09 DECIDED 20 Nov (MT) Pro lapsed (after grace): keeps name.dfe, the blue tick goes", async () => { + const w = world(); const m = w.member("free"); w.grant(m, "pro", { from: T0 - 40 * DAY, to: T0 - 10 * DAY }); dfe(w, m); + assert.deepEqual(pick(await memberAsAuthor(w, m)).slice(1), [".dfe", "dfe_unpaid"]); +}); +test("DFE-10 gifted Pro counts as paying: .dfe + blue tick", async () => { + const w = world(); const m = w.member("free"); + w.run(`INSERT INTO entitlements (id, account_id, kind, source, starts_at, ends_at, created_at) VALUES ('g1', ?, 'pro', 'gift', ?, ?, ?)`, m, T0 - DAY, T0 + 30 * DAY, T0); + dfe(w, m); + assert.deepEqual(pick(await memberAsAuthor(w, m)).slice(1), [".dfe", "dfe"]); +}); +test("DFE-11 verification expired (verified_until passed): no .dfe, no tick", async () => { + const w = world(); const m = w.member("pro"); dfe(w, m, { until: T0 - DAY }); + const a = await memberAsAuthor(w, m); + assert.deepEqual([a.suffix, a.mark === "dfe" || a.mark === "dfe_unpaid"], [null, false]); +}); +test("DFE-12 revoked by Super Admin (override remove): no .dfe, no tick", async () => { + const w = world(); const m = w.member("pro"); dfe(w, m); const mt = w.admin(); + w.run("INSERT INTO badge_overrides (id, subject_type, subject_id, badge, mode, reason, created_by, created_at) VALUES ('o1','member',?,'dfe','remove','audit',?,?)", m, mt, T0); + const a = await memberAsAuthor(w, m); + assert.deepEqual([a.suffix, a.mark === "dfe" || a.mark === "dfe_unpaid"], [null, false]); // the Pro slot ("pro") may stay +}); +test("DFE-13 anonymous review by a paid DFE: Anonymous, nothing else", async () => { + const w = world(); const m = w.member("pro"); dfe(w, m); + await w.review(m, "alpha-flight", { anonymous: true, agreement: true }); + const a = (await w.data.getSchoolPublic("alpha-flight")).reviews[0].author; + assert.deepEqual(pick(a), ["Anonymous", null, null]); +}); + +// ================================================================= ATO (.official + gold tick) +test("ATO-01 unclaimed, unpaid: name only", async () => { + const w = world(); + assert.deepEqual(pick(await dirCard(w, "beta-air")), ["Beta Air", null, null]); +}); +test("ATO-02 claim approved, never paid: name only (NEW-10)", async () => { + const w = world(); + assert.deepEqual(pick(await dirCard(w, "alpha-flight")), ["Alpha Flight", null, null]); +}); +test("ATO-03 paid but claim NOT approved (gift or payment on an unclaimed school): no .official and no gold tick", async () => { + const w = world(); giftSchool(w, "s-beta"); + assert.deepEqual(pick(await dirCard(w, "beta-air")), ["Beta Air", null, null]); // code today: mark 'ato_gold' on an unclaimed school +}); +test("ATO-04 paid + approved: handle.official + gold tick (directory, page, official reply)", async () => { + const w = world(); const op = w.schoolAccount("s-alpha"); paidSchool(w, "s-alpha"); + const rid = await w.review(w.member("pro")); + await w.data.createReply(await w.as(op), rid, { text: "Thanks." }); + assert.deepEqual(pick(await dirCard(w, "alpha-flight")), ["alphaflight", ".official", "ato_gold"]); + assert.deepEqual(pick(await pageSchool(w, "alpha-flight")), ["alphaflight", ".official", "ato_gold"]); + const reply = (await w.data.getSchoolPublic("alpha-flight")).reviews[0].replies[0]; + assert.deepEqual(pick(reply.author), ["alphaflight", ".official", "ato_gold"]); +}); +test("ATO-05 paid, then lapsed: keeps .official, loses the gold tick (file 12 §6)", async () => { + const w = world(); paidSchool(w, "s-alpha", { to: T0 + DAY }); w.clock.t = T0 + 40 * DAY; + assert.deepEqual(pick(await dirCard(w, "alpha-flight")), ["alphaflight", ".official", null]); +}); +test("ATO-06 gifted Premium while gift runs: .official + gold tick (DEC-010, NEW-15)", async () => { + const w = world(); giftSchool(w, "s-alpha"); + assert.deepEqual(pick(await dirCard(w, "alpha-flight")), ["alphaflight", ".official", "ato_gold"]); +}); +test("ATO-07 DECIDED 20 Nov (MT) gift ended, never paid: KEEPS .official, no gold tick", async () => { + const w = world(); giftSchool(w, "s-alpha", { to: T0 + DAY }); w.clock.t = T0 + 40 * DAY; + assert.deepEqual(pick(await dirCard(w, "alpha-flight")), ["alphaflight", ".official", null]); +}); +test("ATO-08 DECIDED 20 Nov (MT) only payment fully refunded: LOSES .official -> name only", async () => { + const w = world(); const mt = await w.as(w.admin()); paidSchool(w, "s-alpha"); + const p = w.get("SELECT id, amount_cents FROM payments WHERE school_id = 's-alpha'"); + await w.data.adminAdjustPayment(mt, p.id, { kind: "refund", amount_cents: p.amount_cents }, "audit refund"); + w.clock.t += DAY; + assert.deepEqual(pick(await dirCard(w, "alpha-flight")), ["Alpha Flight", null, null]); // code today: keeps .official, tick goes (FAIL) +}); +test("ATO-09 revoked by Super Admin (override remove official + ato_gold): name only", async () => { + const w = world(); paidSchool(w, "s-alpha"); const mt = w.admin(); + for (const b of ["official", "ato_gold"]) + w.run("INSERT INTO badge_overrides (id, subject_type, subject_id, badge, mode, reason, created_by, created_at) VALUES (?, 'school', 's-alpha', ?, 'remove', 'audit', ?, ?)", `o-${b}`, b, mt, T0); + assert.deepEqual(pick(await dirCard(w, "alpha-flight")), ["Alpha Flight", null, null]); +}); +test("ATO-10 directory and page agree in every state", async () => { + const w = world(); paidSchool(w, "s-alpha", { to: T0 + DAY }); + for (const t of [T0, T0 + 40 * DAY]) { w.clock.t = t; assert.deepEqual(pick(await dirCard(w, "alpha-flight")), pick(await pageSchool(w, "alpha-flight"))); } +}); +test("ATO-11 staff/owner personal posts carry THEIR member badges, never .official", async () => { + const w = world(); paidSchool(w, "s-alpha"); const owner = w.member("pro"); + const a = await memberAsAuthor(w, owner); + assert.equal(a.suffix, null); +}); +test("ATO-12 nobody can type .dfe or .official into a name (EC-103)", async () => { + const { checkUsername } = await import("../../cloudflare/lib/reviews/rules.mjs").catch(() => ({})); + if (!checkUsername) return; // covered by build16_founding_badges.test.mjs EC-103 + for (const u of ["joe.dfe", "alpha.official"]) assert.throws(() => checkUsername(u)); +}); + +// ================================================================= Q7 (MT, t441u-t443u): Remove DFE / Remove school on the Super Admin page +// No Remove action exists in the code yet, so these are todo until one is built. Each must pass once it is. +test.todo("REM-01 DECIDED 20 Nov (MT) Remove DFE (after the confirm step): no .dfe, no tick, DFE card unlinked, claim cleared, as if never verified"); +test.todo("REM-02 DECIDED 20 Nov (MT) Remove school (after the confirm step): name only, no .official, no tick, no Premium or extras, claim cleared, old payments no longer count as ever paid"); +test.todo("REM-03 DECIDED 20 Nov (MT) Remove without the confirm step is refused and changes nothing"); + +test("UI-12 DECIDED 20 Nov (MT) DFE directory shows username.dfe + blue tick for a paid, approved DFE", async () => { + const w = world(); const m = w.member("pro"); dfe(w, m); + const u = w.get("SELECT username FROM accounts WHERE id = ?", m).username; + const hit = (await w.data.searchDfes("DFE")).dfes.find((d) => d.claimed); + assert.ok(hit); + assert.equal(hit.label + hit.suffix, u + ".dfe"); + assert.equal(hit.mark, "dfe"); +}); + +test("UI-15 DECIDED 20 Nov (MT) gifted Premium unlocks the Premium extras", async () => { + const w = world(); + const mt = await w.as(w.admin()); + await w.data.adminSetSetting(mt, "module_announcement", "1", "on"); + giftSchool(w, "s-alpha"); + const op = await w.as(w.schoolAccount("s-alpha")); + const p = await w.data.submitSchoolPost(op, "announcement", { title: "Open day", text: "This Saturday." }); + assert.ok(p.id, "a gifted Premium school must be allowed to submit extras"); +}); diff --git a/tests/reviews/audit_handles_ui.test.mjs b/tests/reviews/audit_handles_ui.test.mjs new file mode 100644 index 00000000..bd8900b0 --- /dev/null +++ b/tests/reviews/audit_handles_ui.test.mjs @@ -0,0 +1,86 @@ +// audit_handles_ui.test.mjs — PROPOSED surface checks: what the guest HTML and the directory cards DRAW from the server's +// { label, suffix, mark }. Drop into go-around-launch-11nov/tests/reviews/. Pure functions only (no browser). +import test from "node:test"; +import assert from "node:assert/strict"; +import { renderGuestReviews } from "../../cloudflare/lib/ato_review_html.mjs"; +import { schoolCards } from "../../site/ga-directory.mjs"; +import { toGeneratorSchool } from "../../tools/reviews/export_for_generator.mjs"; +import { readFileSync } from "node:fs"; +import { fileURLToPath } from "node:url"; +import { dirname, join } from "node:path"; + +const review = (author, replies = []) => ({ id: "r1", author: { kind: "member", chips: [], ...author }, stars: "4.0", text: "ok", date: "2026-11-20", up: 0, replies }); +const school = { kind: "school", label: "alphaflight", suffix: ".official", mark: "ato_gold" }; + +test("UI-01 guest review card: paid DFE shows username.dfe AND the blue tick", () => { + const html = renderGuestReviews([review({ label: "joe", suffix: ".dfe", mark: "dfe" })]); + assert.match(html, /joe(?:<[^>]+>)*\.dfe/); + assert.match(html, /dfe-tick|data-badge="dfe"|Verified DFE/); // today: suffix text only, no tick +}); +test("UI-02 guest official reply: handle.official AND the gold tick while paying", () => { + const html = renderGuestReviews([review({ label: "pat" }, [{ id: "p1", author: school, text: "Thanks", date: "2026-11-20" }])]); + assert.match(html, /alphaflight(?:<[^>]+>)*\.official/); + assert.match(html, /ato-tick|data-badge="ato_gold"|Verified ATO/); // today: no tick +}); +test("UI-03 guest official reply of a lapsed school: handle.official, NO gold tick", () => { + const html = renderGuestReviews([review({ label: "pat" }, [{ id: "p1", author: { ...school, mark: null }, text: "Thanks", date: "2026-11-20" }])]); + assert.match(html, /alphaflight(?:<[^>]+>)*\.official/); + assert.doesNotMatch(html, /ato-tick|data-badge="ato_gold"/); +}); +test("UI-04 DECIDED 20 Nov (MT) directory card, paying school: School Name + gold tick, handle.official small beneath", () => { + const [card] = schoolCards([{ slug: "alpha-flight", name: "Alpha Flight", kind: "ATO", label: "alphaflight", suffix: ".official", mark: "ato_gold", certificates: [] }]); + assert.equal(card.name, "Alpha Flight"); + assert.equal(card.mark, "ato_gold", "the card carries no gold tick today"); + assert.equal(card.handle, "alphaflight.official", "the card carries no handle today"); +}); +test("UI-16 DECIDED 20 Nov (MT) guest review card, approved DFE NOT paying: name.dfe, NO blue tick", () => { + const html = renderGuestReviews([review({ label: "joe", suffix: ".dfe", mark: "dfe_unpaid" })]); + assert.match(html, /joe(?:<[^>]+>)*\.dfe/); + assert.doesNotMatch(html, /dfe-tick|data-badge="dfe"|Verified DFE/); +}); + +test("UI-05 signed-in ATO view draws member suffix and tick via attachNameLine", () => { + const src = readFileSync(join(dirname(fileURLToPath(import.meta.url)), "../../site/me/ato-member.js"), "utf8"); + assert.match(src, /attachNameLine/); + assert.match(src, /whoLine/); + assert.doesNotMatch(src, /innerHTML/); +}); + +test("UI-06 signed-in official reply uses attachNameLine so the gold tick is drawn", () => { + const src = readFileSync(join(dirname(fileURLToPath(import.meta.url)), "../../site/me/ato-member.js"), "utf8"); + assert.match(src, /function replyNode/); + assert.match(src, /whoLine\(strong, who/); +}); + +test("UI-09 DECIDED 20 Nov (MT) static hero, Premium but unclaimed: exporter does not mark the school paid", () => { + const file = toGeneratorSchool({ + school: { slug: "beta-air", name: "Beta Air", kind: "ATO", label: "Beta Air", suffix: null, mark: null, contact: {} }, + certificates: [], courses: [], reviews: [], visible_reviews: 0, rating: { shown: false, score: null }, + }); + assert.equal(file.status, "unclaimed"); + assert.equal(file.handle, null); +}); + +test("UI-10 DECIDED 20 Nov (MT) static review, approved but unpaid DFE keeps name.dfe and no tick badge", () => { + const file = toGeneratorSchool({ + school: { slug: "alpha-flight", name: "Alpha Flight", kind: "ATO", label: "alphaflight", suffix: ".official", mark: null, contact: {} }, + certificates: [], courses: [], visible_reviews: 1, rating: { shown: false, score: null }, + reviews: [{ id: "r1", author: { kind: "member", label: "joe", suffix: ".dfe", mark: "dfe_unpaid", chips: [] }, stars: "4.0", text: "ok", date: "2026-11-20", up: 0, replies: [] }], + }); + assert.deepEqual(file.top_reviews[0].author.badges, ["dfe_unpaid"]); + assert.equal(file.top_reviews[0].author.name, "joe"); +}); + +test("badge CSS: gold shine and blue pop run once, reduced motion is static, no !important, all 4 themes", () => { + const css = readFileSync(join(dirname(fileURLToPath(import.meta.url)), "../../site/assets/badges/badges.css"), "utf8"); + assert.match(css, /@keyframes ga-shine-sweep/); + assert.match(css, /@keyframes ga-dfe-pop/); + assert.match(css, /animation: ga-shine-sweep 0\.9s ease-out 0\.12s 1 both/); + assert.match(css, /animation: ga-dfe-pop 0\.42s/); + assert.match(css, /prefers-reduced-motion: reduce/); + assert.doesNotMatch(css, /!important/); + assert.match(css, /data-theme="day"]\[data-pal="white"/); + assert.match(css, /data-theme="night"]\[data-pal="black"/); + assert.match(css, /data-theme="night"]\[data-pal="purple"/); + assert.match(css, /data-theme="day"]\[data-pal="beige"/); +}); diff --git a/tests/reviews/security_gate.test.mjs b/tests/reviews/security_gate.test.mjs index d231cef8..09b40d11 100644 --- a/tests/reviews/security_gate.test.mjs +++ b/tests/reviews/security_gate.test.mjs @@ -76,6 +76,8 @@ const REVIEWED_SPLICES = new Set([ "lib/reviews/data_more.mjs :: family", "lib/reviews/data_more.mjs :: PAID_SCHOOL_EXTRAS", "lib/reviews/data_school.mjs :: PAID_SCHOOL_EXTRAS", + "lib/reviews/data.mjs :: SCHOOL_EVER_PREMIUM", + "lib/reviews/data.mjs :: SCHOOL_EVER_PREMIUM_FOR_LIST", "lib/reviews/data_pay.mjs :: ended", "lib/reviews/data_subs.mjs :: activeSeat", "lib/reviews/rating.mjs :: parameter", diff --git a/tools/reviews/export_for_generator.mjs b/tools/reviews/export_for_generator.mjs index 661e3e12..4e4ec035 100644 --- a/tools/reviews/export_for_generator.mjs +++ b/tools/reviews/export_for_generator.mjs @@ -23,7 +23,9 @@ export function toGeneratorSchool(pub) { const author = (a) => a.kind === "anonymous" ? { anonymous: true } // N-31: nothing else exists to copy : { name: a.label, anonymous: false, licences: a.chips ?? [], - badges: a.mark === "dfe" ? ["dfe"] : a.mark === "founding" ? ["founding"] : [] }; // Pro and unpaid-DFE marks have no drawing yet (B-07) + ...(a.display_name ? { display_name: a.display_name } : {}), + // dfe_unpaid keeps .dfe on the static page, without the blue tick (UI-10). + badges: a.mark === "dfe" ? ["dfe"] : a.mark === "dfe_unpaid" ? ["dfe_unpaid"] : a.mark === "founding" ? ["founding"] : [] }; return { id: pub.certificates?.[0]?.number ?? s.slug, slug: s.slug, name: s.name, kind: s.kind, -- 2.47.3