From a6b652985f40cf022d6c522415c36fad13bc663d Mon Sep 17 00:00:00 2001 From: aur-build Date: Wed, 18 Nov 2026 08:06:39 +0000 Subject: =?UTF-8?q?http:=20the=20review=20surface=20=E2=80=94=20server-ren?= =?UTF-8?q?dered,=20no=20JavaScript=20required=20(=C2=A712,=20=C2=A713)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tiny_http, thread-per-connection, askama templates. Every §13 surface is server-rendered HTML that works with scripts switched off: Inbox, review detail with the full panel set, Builds, Attention, Index, Subscriptions, Ops/audit, Settings. The parts that are easy to get wrong: - Handlers read through thread-local READ-ONLY connections. They cannot take the write lock even by accident, so a slow page render never blocks the build pipeline's writer. tests/http.rs asserts this by trying to write through a read connection and requiring failure. - Every POST requires a CSRF token derived from the session id. Logout drops the session, which invalidates every form still open in a browser. - Approve carries identity_hash AND diff_digest (§7.1a). If either has moved, the approval is refused with 409 and the page re-renders the review AS IT IS NOW — never a silent retarget onto the newer state. - Bulk approve refuses high-risk items unless each one is individually confirmed by id. Bulk is per-item, never 'approve everything forever'. - Reject requires a note; it is re-openable, not a deletion. - Optional password gate; anonymous visitors are redirected to /login. Also: the index page states the pacman conf snippet including 'SigLevel = Required DatabaseOptional', because a repo consumers ignore the signature is a repo that gets MITM'd. --- src/http/render.rs | 373 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 373 insertions(+) create mode 100644 src/http/render.rs (limited to 'src/http/render.rs') diff --git a/src/http/render.rs b/src/http/render.rs new file mode 100644 index 0000000..2fad5c8 --- /dev/null +++ b/src/http/render.rs @@ -0,0 +1,373 @@ +//! Template contexts (§12, §13). +//! +//! Askama compiles every template into Rust at build time, so a missing field +//! is a compile error rather than a blank page at 2am. Contexts are built from +//! live DB state; nothing here writes. + +use askama::Template; + +/// Everything the shared chrome needs. Embedded in each page context because +/// askama inheritance passes the whole struct down. +#[derive(Debug, Clone)] +pub struct Page { + pub title: String, + pub flash: String, + pub has_flash: bool, + pub flash_err: bool, + pub csrf: String, + pub pending: i64, + pub running: i64, + pub attention: i64, + pub nav_reviews: &'static str, + pub nav_builds: &'static str, + pub nav_attention: &'static str, + pub nav_packages: &'static str, + pub nav_subscriptions: &'static str, + pub nav_audit: &'static str, + pub nav_settings: &'static str, + /// True when a password gate is configured, so the chrome offers a logout. + pub gated: bool, +} + +impl Page { + pub fn new(title: &str, csrf: String) -> Self { + Self { + title: title.into(), + flash: String::new(), + has_flash: false, + flash_err: false, + csrf, + pending: 0, + running: 0, + attention: 0, + nav_reviews: "", + nav_builds: "", + nav_attention: "", + nav_packages: "", + nav_subscriptions: "", + nav_audit: "", + nav_settings: "", + gated: false, + } + } + pub fn flash(mut self, msg: String, err: bool) -> Self { + self.flash = msg; + self.has_flash = true; + self.flash_err = err; + self + } +} + +#[derive(Template)] +#[template(path = "login.html")] +pub struct Login { + pub page: Page, + pub error: String, +} + +#[derive(Template)] +#[template(path = "error.html")] +pub struct ErrorPage { + pub page: Page, + pub status: String, + pub message: String, + pub detail: String, +} + +#[derive(Template)] +#[template(path = "dashboard.html")] +pub struct Dashboard { + pub page: Page, + pub subscriptions: i64, + pub index_count: i64, + pub pending_reviews: i64, + pub running_builds: i64, + pub attention: i64, + pub publishes: Vec, +} + +#[derive(Debug, Clone)] +pub struct PublishRow { + pub name: String, + pub version: String, + pub published_at: String, + pub aur_commit: String, + pub aur_commit_short: String, +} + +#[derive(Template)] +#[template(path = "reviews.html")] +pub struct ReviewsPage { + pub page: Page, + pub rows: Vec, +} + +#[derive(Debug, Clone)] +pub struct ReviewRow { + pub id: i64, + pub pkgbase: String, + pub version: String, + pub kind: String, + pub risk: String, + pub signals: Vec, + pub age: String, + pub revision: i64, +} + +#[derive(Template)] +#[template(path = "review.html")] +pub struct ReviewDetail { + pub page: Page, + pub c: ReviewHead, + pub base_version: String, + pub has_base: bool, + pub panels: Vec, + /// First introductions show the whole recipe instead of a diff (§7.1b). + pub recipe: String, + pub srcinfo: String, + pub has_srcinfo: bool, + pub sources_resolved: String, + pub deps_resolved: String, +} + +#[derive(Debug, Clone)] +pub struct ReviewHead { + pub id: i64, + pub pkgbase: String, + pub version: String, + pub kind: String, + pub is_first: bool, + pub risk: String, + pub signals: Vec, + pub missing_deps: Vec, + pub revision: i64, + pub aur_commit: String, + pub aur_commit_short: String, + pub identity_hash: String, + pub diff_digest: String, +} + +#[derive(Debug, Clone)] +pub struct Panel { + pub title: String, + pub body: String, + pub empty: bool, + pub empty_note: String, +} + +impl Panel { + pub fn new(title: &str, body: String) -> Self { + Self { + title: title.into(), + empty: body.trim().is_empty(), + empty_note: "no change".into(), + body, + } + } +} + +#[derive(Template)] +#[template(path = "subscriptions.html")] +pub struct Subscriptions { + pub page: Page, + pub rows: Vec, +} + +#[derive(Debug, Clone)] +pub struct SubRow { + pub name: String, + pub state: String, + pub maintainer: String, + pub last_checked: String, + pub next_check: String, + pub last_error: String, + pub has_error: bool, + pub pending: i64, + pub pause_label: &'static str, +} + +#[derive(Template)] +#[template(path = "attention.html")] +pub struct Attention { + pub page: Page, + pub empty: bool, + pub notices: Vec, + pub outdated: Vec, + pub missing: Vec, + pub downgrades: Vec, + pub blocked: Vec, +} + +#[derive(Debug, Clone)] +pub struct NoticeRow { + pub id: i64, + pub pkgbase: String, + pub kind: String, + pub severity: String, + pub detail: String, + pub created_at: String, +} + +#[derive(Debug, Clone)] +pub struct StaleRow { + pub pkgbase: String, + pub built_with: String, + pub now: String, +} + +#[derive(Debug, Clone)] +pub struct BlockedRow { + pub id: String, + pub id_short: String, + pub pkgbase: String, + pub blocked_on: Vec, +} + +#[derive(Template)] +#[template(path = "packages.html")] +pub struct Packages { + pub page: Page, + pub repo: String, + pub rows: Vec, + pub snippet: String, +} + +#[derive(Debug, Clone)] +pub struct IndexRow { + pub name: String, + pub version: String, + pub arch: String, + pub size: String, + pub published_at: String, +} + +#[derive(Template)] +#[template(path = "package.html")] +pub struct PackageDetail { + pub page: Page, + pub name: String, + pub summary: String, + pub can_withdraw: bool, + pub stale: Vec, + pub deps_in: Vec, + pub deps_out: Vec, + pub timeline: Vec, + pub builds: Vec, +} + +#[derive(Debug, Clone)] +pub struct TimelineRow { + pub version: String, + pub state: String, + pub aur_commit: String, + pub aur_commit_short: String, + pub published_at: String, + pub approver: String, +} + +#[derive(Template)] +#[template(path = "builds.html")] +pub struct Builds { + pub page: Page, + pub rows: Vec, + pub recent: Vec, +} + +#[derive(Debug, Clone)] +pub struct BuildLite { + pub id: String, + pub id_short: String, + pub kind: String, + pub state: String, + pub step: String, +} + +#[derive(Debug, Clone)] +pub struct BuildRow { + pub id: String, + pub id_short: String, + pub pkgbase: String, + pub version: String, + pub kind: String, + pub state: String, + pub step: String, + pub lease: String, + pub cancel: bool, + pub error: String, +} + +#[derive(Template)] +#[template(path = "build.html")] +pub struct BuildDetail { + pub page: Page, + pub id: String, + pub id_short: String, + pub pkgbase: String, + pub version: String, + pub kind: String, + pub state: String, + pub error: String, + pub blocked_on: Vec, + pub steps: Vec, + pub log: String, + pub log_lines: usize, + pub log_truncated: bool, +} + +#[derive(Debug, Clone)] +pub struct StepRow { + pub step: String, + pub status: String, + pub attempt: i64, + pub digest: String, + pub cls: String, + pub error: String, +} + +#[derive(Template)] +#[template(path = "audit.html")] +pub struct Audit { + pub page: Page, + pub rows: Vec, +} + +#[derive(Debug, Clone)] +pub struct AuditRow { + pub at: String, + pub actor_kind: String, + pub actor: String, + pub action: String, + pub entity: String, + pub entity_id: String, + pub detail: String, +} + +#[derive(Template)] +#[template(path = "settings.html")] +pub struct Settings { + pub page: Page, + pub rows: Vec, + pub repo: String, +} + +#[derive(Debug, Clone)] +pub struct SettingRow { + pub key: String, + pub value: String, +} + +/// Vendored static assets. htmx arrives in P3; until then this serves the +/// favicon and refuses everything else rather than walking the filesystem. +pub fn static_asset(name: &str) -> crate::http::Res { + use crate::http::Res; + match name { + "htmx.min.js" => Res::text(404, "htmx is vendored in P3\n".into()), + "app.css" => { + let s = std::include_str!("../../static/app.css"); + let mut r = Res::text(200, s.to_string()); + r.content_type = "text/css".into(); + r + } + _ => Res::text(404, "not found\n".into()), + } +} -- cgit v1.2.3