15.1 KiB · text History 147d2cc

recourse

A small axum web application scaffold with:

  • axum web stack with minijinja templates (embedded at build time, hot-reloaded from templates/ in dev)
  • sea-orm + Postgres with a migration crate (auto-migrates on boot)
  • Auth: Argon2 password hashing, cookie sessions, invite-only registration, email verification (mail through mail-prism), optional “Sign in with NEIAM” (OIDC), and per-device bearer tokens (hashed, 90-day sliding expiry) for the Android app and scripts
  • Tailwind + DaisyUI front-end with a theme switcher (just assets to build)
  • Prometheus metrics at /metrics, health check at /healthz
  • A Dockerfile (assets → cargo → debian-slim) and compose.yml (Postgres + web)

Quick start

just deps          # npm install (frontend deps)
just assets        # build CSS + JS + webfonts
just db-up         # start Postgres via podman compose; a fresh DB is migrated and gets demo content
just migrate       # apply migrations
just admin alice alice@example.com   # first (staff) account; prints its password
just serve         # run the web service on :3000

Sign in with the printed password. Further members join through invites (just invite, or the Invites page), or are created the same way.

Seed and demo data

  • just seed (manage seed) creates what any forum can keep: a category tree up to three levels deep (Development › Backend › Databases, Hobbies › Games › Board Games, …) with distinct colors, a members-only category (“Members Lounge”, any signed-in account) and a min-trust one (“Regulars’ Corner”, trust level 3+), the default reaction types if missing, and a few tags.
  • just seed-demo (manage seed --demo) adds development data: verified accounts demo-admin (staff, Leader), demo-leader, demo-regular, demo-member, demo-basic and demo-new (one per trust level), all with the password recourse-demo, and topics spread over the last six weeks with replies, an edited post, a soft-deleted post, reactions, bookmarks, tags and a pinned announcement; and moderation in use: staff-only Announcements, a read-only “Leaders’ Council” (Basic reads, Regulars post), a locked topic with a staff-moderated post whose original is hidden, a pending flag, and their moderation-log lines.

Both are idempotent: rows are matched by slug / key / username / topic title and only missing ones are created, so re-running changes nothing and never overwrites edits. just db-up runs seed --demo only when the database has no users yet.

Production never gets demo content. Demo accounts share a published password, so nothing automatic runs --demo: not the image, not compose, not AUTO_MIGRATE. manage seed --demo also refuses to run when PUBLIC_URL is https unless given --allow-public. Plain manage seed is safe in production (it only adds missing categories/reactions/tags); run it by hand if you want the starter categories.

Staff

Staff (category/reaction admin, moderation) is only ever granted on purpose: manage user create … --staff, or manage user set-staff <name> for an existing account. Registering — even as the very first account — never makes anyone staff.

Moderation

Staff have three panes (Flags / Users / Log, under the admin menu), each in Classic and Focus:

  • Posts: Moderate replaces a post with a note shown as “staff: …” and kept in the post’s history as a moderation revision. Staff can hide the earlier versions from everyone else (“hidden by staff”) and restore the body later. The author can’t edit a moderated post back.
  • Topics: lock (with an optional reason) and pin. A locked topic takes replies, reactions and edits only from staff.
  • Categories: besides who can read one (minimum trust), each has a rule for starting topics and one for replying: everyone who can read it, a minimum trust level, or staff only. That covers announcement forums (staff start topics, members reply) and read-only windows (TL1 reads, TL3 posts). A new subcategory starts with its parent’s rules; nothing is inherited after that.
  • Flags: members (MIN_TRUST_TO_FLAG, verified, not silenced) flag a post once for spam / abusive / off topic / other.
    • A post hides itself pending review when distinct flaggers ÷ readers ≥ FLAG_HIDE_RATIO and there are at least FLAG_HIDE_MIN_FLAGS of them, or once there are FLAG_HIDE_ENOUGH_FLAGS.
    • “Readers” are members whose read position in the topic is at or past the post (topic_reads), not counting its author: the people who could have seen it and chose not to flag.
    • The queue (/admin/flags) shows the ratio and its inputs, each flagger’s record (upheld ✓ / dismissed ✗), and the author at a glance. Every action is inline: dismiss, moderate, delete, lock, and silence, suspend or ignore flags for the author or a flagger.
  • People:
    • Silence: can read, can’t post, reply, react or flag.
    • Suspend: can’t sign in; sessions and app tokens are revoked.
    • Both take a reason and an optional end, and the person is shown both.
    • Flag shadowban: their flags are recorded and look normal to them, but don’t count and are kept apart in the queue.
    • From /admin/users/{id}, or manage user silence|unsilence|suspend|unsuspend|flag-shadowban|unflag-shadowban <name>.
  • Log: every staff action, from the web or the CLI, is in /admin/log (also per user).

Configuration (environment)

Var Default Meaning
APP_NAME recourse Display name in templates
DATABASE_URL postgres://recourse_user:recourse_password@localhost:5439/recourse Postgres connection
BIND_ADDRESS 0.0.0.0:3000 Listen address
SESSION_DURATION_HOURS 24 Cookie session lifetime
REGISTRATION_TOKEN_DURATION_DAYS 7 Default invite validity
AUTO_MIGRATE true Run migrations on boot
REGISTRATION_ENABLED false Allow /register without an invite link (token still required)
PUBLIC_URL http://localhost:<BIND port> Public origin: base of email-verification links, the default OIDC redirect URI and the API-token curl example. https:// also marks the session cookie Secure
MIN_TRUST_TO_CREATE_TAG 3 Trust level needed to mint new tags
MIN_TRUST_TO_FLAG 1 Trust level needed to flag a post (0–4)
FLAG_HIDE_RATIO 0.1 Auto-hide a post when distinct counted flaggers ÷ readers of it reaches this (0–1]; see Moderation
FLAG_HIDE_MIN_FLAGS 2 …and at least this many flaggers (one person never hides a post)
FLAG_HIDE_ENOUGH_FLAGS 10 …or this many, whatever the readership
MAIL_PRISM_URL / MAIL_PRISM_API_KEY (unset) Send mail through mail-prism. Unset (or blank): mail is only logged
MAIL_FROM_ADDRESS (the key’s application address) Must equal the mail-prism application address if set
MAIL_FROM_NAME APP_NAME From display name
EMAIL_VERIFICATION_TTL_HOURS 48 Lifetime of a verification link
REQUIRE_EMAIL_VERIFICATION true Unverified accounts can read but not post/reply/react/bookmark/tag
OIDC_ENABLED, OIDC_LOGIN_MODE, OIDC_* off “Sign in with NEIAM”; see below and the neiam-auth README
OIDC_PASSWORD_LOGIN true false hides and refuses password login (implied by OIDC_LOGIN_MODE=sso_strict)

Layouts: Classic and Focus

Two layouts for browsing: Classic (lists and tables) and Focus (full-screen tiles with a reader you step through). Pick the default under Profile → Layout. The Classic/Focus switch on a page is a temporary override: signed in, it lasts until the browser closes (a session cookie) and never changes the profile, and saving the profile clears it; signed out, it is remembered in a cookie for a year. Links between pages carry no layout, so nothing flips while you browse. ?view=classic|focus works in any URL (the old list / visual are accepted too).

In Focus:

  • Category /c/{slug}: the category fills the page. The categories beside it are squares on a rail (the current one has the accent border; on small screens the rail is a horizontal strip), and .. goes up a level, or to the home page from a top-level category. The category’s own topics are tiles: title, poster and top-replier avatars, replies, views, last activity, tags, reactions, and new / N unread for signed-in users. Each subcategory is a column of compact topic squares with a “Focus on …” link.
  • Home /: a tile per top-level category with its subcategories and latest topics. Tags /tags: a tile per tag with its latest topics.
  • Tag, search, bookmarks, reactions and notifications: their topics as tiles. Tags get a rail of other tags. Bookmarks, reactions and notifications add lines to each tile saying what was bookmarked, how many reactions, or which notifications; notifications are grouped by topic.
  • Reader: on any of those pages, &topic=<id> opens a topic over the page with a filmstrip of that page’s list. ← / → (or k / j) step through it, Escape or a click outside closes it, and each step is a URL, so the back button works.
  • Topic /t/{id}: the same page at full screen. Posts are centred at reading width, with the category rail on one side and a filmstrip of the category’s topics below; ← / → step and Escape goes back to the category. The reply form, editing, history, tag editing, watch and moderation work as on the Classic page.

Visibility, min-trust, unverified/anonymous permissions, views and read tracking work the same in both layouts: the reader and the Focus topic page count a view and mark the topic read exactly as the Classic topic page does. Admin, auth, profile and the new-topic/edit forms are Classic only. See src/handlers/focus.rs (modelled on pin_flip’s focus mode and shared pages, and cartosnap’s shared-trip stepping).

Android app and API

android/ is the phone client (Kotlin + Compose): browse in Classic or Focus (the profile’s Layout), read, reply, start topics, react, bookmark, watch, tags, search, notifications, profile. Pair it from Devices in the account menu, which shows a QR of recourse://pair?base=…&token=… once; the same page renames and revokes devices. Build with just apk (it finds a JDK 17–21 even when the system java is 25); see android/README.md.

It talks to /api/v1 (docs/api.md), bearer tokens only, with the web’s visibility, trust, verification, view and read rules — the API calls the same code (src/actions.rs for writes). just test-db runs the API tests against a scratch database; just fixtures refreshes the responses the app’s contract test decodes. The plan, and what came out differently, is docs/android.md.

Email verification

New accounts (registration through an invite) start unverified: they can read everything but can’t post, reply, react, bookmark or create tags until they follow the link mailed to them. A banner says so, with a “Resend link” button (also on the profile; at most one link per 10 minutes). Links are single-use, expire after EMAIL_VERIFICATION_TTL_HOURS, and a new one replaces the previous one; only a SHA-256 of each token is stored. Accounts that existed before verification was added were marked verified by the migration; accounts made with manage user create start verified, as do accounts signing in through an OIDC provider with OIDC_TRUST_EMAIL=true that vouches for the address.

Mail goes through mail-prism when MAIL_PRISM_URL and MAIL_PRISM_API_KEY are set. The templates live in this repo under mail_prism/ and the webservice pushes them to mail-prism on startup (PUT /api/v1/templates); each verification mail carries an idempotency_key per token, so a retry never sends twice. The client crate is vendored in crates/mail-prism-client (the mail-prism repo is private; see its VENDORED.md).

Without mail-prism (development) the app runs normally and writes each message, link included, to its log at INFO (outbound mail (log transport …)). manage user verify-email <name> skips the link; manage user resend-verification <name> prints a fresh one; manage email test <to> checks the mail-prism setup.

Sign in with NEIAM

neiam-auth v0.4.0 (git dependency, pinned to the tag, sea-orm feature for sea-orm 1.1), wired as in the neiam-htmx template. Off by default: until OIDC_ENABLED=true there is no button and /auth/oidc/* returns 404 (except /auth/oidc/health). The oidc_identities migration always runs.

OIDC_ENABLED=true
OIDC_LOGIN_MODE=mixed                   # local | mixed (default) | sso | sso_strict
OIDC_ISSUER=https://auth.neiam.org
OIDC_CLIENT_ID=recourse
OIDC_CLIENT_SECRET=...                  # or OIDC_CLIENT_SECRET_FILE
OIDC_REDIRECT_URI=https://<host>/auth/oidc/neiam/callback   # default: ${PUBLIC_URL}/auth/oidc/neiam/callback
OIDC_SCOPES="openid profile email groups"
OIDC_GROUPS_CLAIM=groups
OIDC_TRUST_EMAIL=true                   # LDAP mail is admin-set
OIDC_LABEL="Sign in with NEIAM"
OIDC_LOGOUT_URL=https://auth.neiam.org/logout
# OIDC_PROVISION=invite_only            # default; `auto` creates accounts on first login
# OIDC_PROVISION_GROUPS=forum           # invite_only, but members of these groups get an account

Linking (src/auth/oidc.rs): an existing (iss, sub) link; “Link NEIAM account” on the profile; a single active account with the same verified email (with OIDC_TRUST_EMAIL); or a new, passwordless account — only through an invite (/register?token=… shows “Sign up with NEIAM”; in sso_strict the invite link goes straight there) or PROVISION=auto / PROVISION_GROUPS, keeping registration invite-only by default. A taken username or email is never taken over, and accounts created this way are never staff. In sso_strict, password login and local registration are refused.

Binaries

  • recourse — the web service
  • manage — admin CLI:
    • manage user create <name> --email E [--staff] [--password-stdin] — no invite needed; without --password-stdin a strong password is generated and printed once
    • manage user list | set-staff <name> [--revoke] | set-trust <name> <0-4> | activate <name> | deactivate <name> | delete <name> --yes
    • manage user verify-email <name> | resend-verification <name>
    • manage user silence|suspend <name> [--reason R] [--hours N | --days N] [--by STAFF], unsilence|unsuspend <name>, flag-shadowban|unflag-shadowban <name> [--reason R] — logged as cli (and the --by account) in the moderation log
    • manage invite create [--email E] [--days N] | list | show <token>
    • manage email test <to> — send a test message through mail-prism (or report it isn’t configured)
    • manage seed [--demo [--allow-public]] — baseline categories/reactions/tags; --demo adds demo users and content
    • Justfile shortcuts: just manage …, just admin <name> <email>, just invite [days], just staff <name>, just trust <name> <level>, just seed, just seed-demo