neiam
/recourse
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
manage user silence/suspend/flag-shadowban (and their reversals), logged; README: moderation
147d2cc · gmorell · 2026-12-03 02:53
Files changed
modified
README.md
+48
−1
@@ -35,7 +35,10 @@ Sign in with the printed password. Further members join through invites
| 35 | 35 | `demo-member`, `demo-basic` and `demo-new` (one per trust level), **all with |
| 36 | 36 | the password `recourse-demo`**, and topics spread over the last six weeks |
| 37 | 37 | with replies, an edited post, a soft-deleted post, reactions, bookmarks, |
| 38 | − tags and a pinned announcement. | |
| 38 | + tags and a pinned announcement; and moderation in use: staff-only | |
| 39 | + Announcements, a read-only "Leaders' Council" (Basic reads, Regulars post), | |
| 40 | + a locked topic with a staff-moderated post whose original is hidden, a | |
| 41 | + pending flag, and their moderation-log lines. | |
| 39 | 42 | |
| 40 | 43 | Both are idempotent: rows are matched by slug / key / username / topic title |
| 41 | 44 | and only missing ones are created, so re-running changes nothing and never |
@@ -56,6 +59,45 @@ Staff (category/reaction admin, moderation) is only ever granted on purpose:
| 56 | 59 | existing account. Registering — even as the very first account — never makes |
| 57 | 60 | anyone staff. |
| 58 | 61 | |
| 62 | +### Moderation | |
| 63 | + | |
| 64 | +Staff have three panes (Flags / Users / Log, under the admin menu), each in | |
| 65 | +Classic and Focus: | |
| 66 | + | |
| 67 | +- **Posts:** *Moderate* replaces a post with a note shown as "staff: …" and | |
| 68 | + kept in the post's history as a moderation revision. Staff can hide the | |
| 69 | + earlier versions from everyone else ("hidden by staff") and restore the | |
| 70 | + body later. The author can't edit a moderated post back. | |
| 71 | +- **Topics:** lock (with an optional reason) and pin. A locked topic takes | |
| 72 | + replies, reactions and edits only from staff. | |
| 73 | +- **Categories:** besides who can *read* one (minimum trust), each has a | |
| 74 | + rule for starting topics and one for replying: everyone who can read it, | |
| 75 | + a minimum trust level, or staff only. That covers announcement forums | |
| 76 | + (staff start topics, members reply) and read-only windows (TL1 reads, TL3 | |
| 77 | + posts). A new subcategory starts with its parent's rules; nothing is | |
| 78 | + inherited after that. | |
| 79 | +- **Flags:** members (`MIN_TRUST_TO_FLAG`, verified, not silenced) flag a | |
| 80 | + post once for spam / abusive / off topic / other. | |
| 81 | + - A post hides itself pending review when distinct flaggers ÷ readers ≥ | |
| 82 | + `FLAG_HIDE_RATIO` and there are at least `FLAG_HIDE_MIN_FLAGS` of them, | |
| 83 | + or once there are `FLAG_HIDE_ENOUGH_FLAGS`. | |
| 84 | + - "Readers" are members whose read position in the topic is at or past | |
| 85 | + the post (`topic_reads`), not counting its author: the people who could | |
| 86 | + have seen it and chose not to flag. | |
| 87 | + - The queue (`/admin/flags`) shows the ratio and its inputs, each | |
| 88 | + flagger's record (upheld ✓ / dismissed ✗), and the author at a glance. | |
| 89 | + Every action is inline: dismiss, moderate, delete, lock, and silence, | |
| 90 | + suspend or ignore flags for the author or a flagger. | |
| 91 | +- **People:** | |
| 92 | + - *Silence:* can read, can't post, reply, react or flag. | |
| 93 | + - *Suspend:* can't sign in; sessions and app tokens are revoked. | |
| 94 | + - Both take a reason and an optional end, and the person is shown both. | |
| 95 | + - *Flag shadowban:* their flags are recorded and look normal to them, but | |
| 96 | + don't count and are kept apart in the queue. | |
| 97 | + - From `/admin/users/{id}`, or `manage user silence|unsilence|suspend|unsuspend|flag-shadowban|unflag-shadowban <name>`. | |
| 98 | +- **Log:** every staff action, from the web or the CLI, is in | |
| 99 | + `/admin/log` (also per user). | |
| 100 | + | |
| 59 | 101 | ## Configuration (environment) |
| 60 | 102 | |
| 61 | 103 | | Var | Default | Meaning | |
@@ -69,6 +111,10 @@ anyone staff.
| 69 | 111 | | `REGISTRATION_ENABLED` | `false` | Allow `/register` without an invite link (token still required) | |
| 70 | 112 | | `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` | |
| 71 | 113 | | `MIN_TRUST_TO_CREATE_TAG` | `3` | Trust level needed to mint new tags | |
| 114 | +| `MIN_TRUST_TO_FLAG` | `1` | Trust level needed to flag a post (0–4) | | |
| 115 | +| `FLAG_HIDE_RATIO` | `0.1` | Auto-hide a post when distinct counted flaggers ÷ readers of it reaches this (0–1]; see Moderation | | |
| 116 | +| `FLAG_HIDE_MIN_FLAGS` | `2` | …and at least this many flaggers (one person never hides a post) | | |
| 117 | +| `FLAG_HIDE_ENOUGH_FLAGS` | `10` | …or this many, whatever the readership | | |
| 72 | 118 | | `MAIL_PRISM_URL` / `MAIL_PRISM_API_KEY` | _(unset)_ | Send mail through mail-prism. Unset (or blank): mail is only logged | |
| 73 | 119 | | `MAIL_FROM_ADDRESS` | _(the key's application address)_ | Must equal the mail-prism application address if set | |
| 74 | 120 | | `MAIL_FROM_NAME` | `APP_NAME` | From display name | |
@@ -202,6 +248,7 @@ never taken over, and accounts created this way are never staff. In
| 202 | 248 | - `manage user create <name> --email E [--staff] [--password-stdin]` — no invite needed; without `--password-stdin` a strong password is generated and printed once |
| 203 | 249 | - `manage user list | set-staff <name> [--revoke] | set-trust <name> <0-4> | activate <name> | deactivate <name> | delete <name> --yes` |
| 204 | 250 | - `manage user verify-email <name> | resend-verification <name>` |
| 251 | + - `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 | |
| 205 | 252 | - `manage invite create [--email E] [--days N] | list | show <token>` |
| 206 | 253 | - `manage email test <to>` — send a test message through mail-prism (or report it isn't configured) |
| 207 | 254 | - `manage seed [--demo [--allow-public]]` — baseline categories/reactions/tags; `--demo` adds demo users and content |
modified
src/bin/manage.rs
+128
−2
@@ -10,6 +10,9 @@
| 10 | 10 | //! manage user set-staff <username> [--revoke] |
| 11 | 11 | //! manage user activate|deactivate <username> |
| 12 | 12 | //! manage user delete <username> --yes |
| 13 | +//! manage user silence|suspend <username> [--reason R] [--hours N | --days N] [--by STAFF] | |
| 14 | +//! manage user unsilence|unsuspend <username> [--by STAFF] | |
| 15 | +//! manage user flag-shadowban|unflag-shadowban <username> [--reason R] [--by STAFF] | |
| 13 | 16 | //! manage invite create [--email E] [--days N] [--created-by UUID] |
| 14 | 17 | //! manage invite list |
| 15 | 18 | //! manage invite show <token> |
@@ -103,6 +106,18 @@ enum UserCmd {
| 103 | 106 | Activate { username: String }, |
| 104 | 107 | /// Deactivate an account and drop its sessions |
| 105 | 108 | Deactivate { username: String }, |
| 109 | + /// Silence: can read, can't post, reply, react or flag. Logged. | |
| 110 | + Silence(SanctionArgs), | |
| 111 | + /// Suspend: can't sign in; signed out of every session and device. Logged. | |
| 112 | + Suspend(SanctionArgs), | |
| 113 | + /// Lift a silence | |
| 114 | + Unsilence(LiftArgs), | |
| 115 | + /// Lift a suspension | |
| 116 | + Unsuspend(LiftArgs), | |
| 117 | + /// Ignore this user's flags (they aren't told). Logged. | |
| 118 | + FlagShadowban(ShadowArgs), | |
| 119 | + /// Count this user's flags again | |
| 120 | + UnflagShadowban(ShadowArgs), | |
| 106 | 121 | /// Permanently delete a user and all their content (topics, posts, …) |
| 107 | 122 | Delete { |
| 108 | 123 | username: String, |
@@ -112,6 +127,40 @@ enum UserCmd {
| 112 | 127 | }, |
| 113 | 128 | } |
| 114 | 129 | |
| 130 | +#[derive(clap::Args)] | |
| 131 | +struct SanctionArgs { | |
| 132 | + username: String, | |
| 133 | + /// Shown to them | |
| 134 | + #[arg(long)] | |
| 135 | + reason: Option<String>, | |
| 136 | + /// Ends after this many hours (default: until lifted) | |
| 137 | + #[arg(long, conflicts_with = "days")] | |
| 138 | + hours: Option<i64>, | |
| 139 | + /// Ends after this many days (default: until lifted) | |
| 140 | + #[arg(long)] | |
| 141 | + days: Option<i64>, | |
| 142 | + /// The staff account to record in the moderation log (default: the | |
| 143 | + /// operator, logged as CLI) | |
| 144 | + #[arg(long)] | |
| 145 | + by: Option<String>, | |
| 146 | +} | |
| 147 | + | |
| 148 | +#[derive(clap::Args)] | |
| 149 | +struct LiftArgs { | |
| 150 | + username: String, | |
| 151 | + #[arg(long)] | |
| 152 | + by: Option<String>, | |
| 153 | +} | |
| 154 | + | |
| 155 | +#[derive(clap::Args)] | |
| 156 | +struct ShadowArgs { | |
| 157 | + username: String, | |
| 158 | + #[arg(long)] | |
| 159 | + reason: Option<String>, | |
| 160 | + #[arg(long)] | |
| 161 | + by: Option<String>, | |
| 162 | +} | |
| 163 | + | |
| 115 | 164 | #[derive(Subcommand)] |
| 116 | 165 | enum InviteCmd { |
| 117 | 166 | /// Create a new invite (registration token) |
@@ -203,15 +252,26 @@ async fn run_user(db: &DatabaseConnection, config: &Config, cmd: UserCmd) -> Res
| 203 | 252 | println!("No users."); |
| 204 | 253 | return Ok(()); |
| 205 | 254 | } |
| 206 | − println!("{:<20} {:<28} {:<7} {:<7} {:<10}", "Username", "Email", "Staff", "Active", "Trust"); | |
| 255 | + println!("{:<20} {:<28} {:<7} {:<7} {:<12} Status", "Username", "Email", "Staff", "Active", "Trust"); | |
| 207 | 256 | for u in rows { |
| 257 | + let mut status = Vec::new(); | |
| 258 | + if let Some(s) = recourse::policy::suspension(&u) { | |
| 259 | + status.push(format!("suspended{}", s.until_text())); | |
| 260 | + } | |
| 261 | + if let Some(s) = recourse::policy::silence(&u) { | |
| 262 | + status.push(format!("silenced{}", s.until_text())); | |
| 263 | + } | |
| 264 | + if u.flags_ignored_at.is_some() { | |
| 265 | + status.push("flags ignored".into()); | |
| 266 | + } | |
| 208 | 267 | println!( |
| 209 | − "{:<20} {:<28} {:<7} {:<7} {:<10}", | |
| 268 | + "{:<20} {:<28} {:<7} {:<7} {:<12} {}", | |
| 210 | 269 | u.username, |
| 211 | 270 | u.email, |
| 212 | 271 | if u.is_staff { "yes" } else { "no" }, |
| 213 | 272 | if u.is_active { "yes" } else { "no" }, |
| 214 | 273 | format!("{} ({})", u.trust_level, recourse::trust::tier_name(u.trust_level)), |
| 274 | + status.join(", "), | |
| 215 | 275 | ); |
| 216 | 276 | } |
| 217 | 277 | } |
@@ -273,6 +333,12 @@ async fn run_user(db: &DatabaseConnection, config: &Config, cmd: UserCmd) -> Res
| 273 | 333 | auth::deactivate_user(db, user.id).await?; |
| 274 | 334 | println!("{username} deactivated (sessions dropped)."); |
| 275 | 335 | } |
| 336 | + UserCmd::Silence(a) => sanction_cmd(db, a, Sanction::Silence).await?, | |
| 337 | + UserCmd::Suspend(a) => sanction_cmd(db, a, Sanction::Suspend).await?, | |
| 338 | + UserCmd::Unsilence(a) => lift_cmd(db, a, Sanction::Silence).await?, | |
| 339 | + UserCmd::Unsuspend(a) => lift_cmd(db, a, Sanction::Suspend).await?, | |
| 340 | + UserCmd::FlagShadowban(a) => shadow_cmd(db, a, true).await?, | |
| 341 | + UserCmd::UnflagShadowban(a) => shadow_cmd(db, a, false).await?, | |
| 276 | 342 | UserCmd::Delete { username, yes } => { |
| 277 | 343 | let user = find_user(db, &username).await?; |
| 278 | 344 | if !yes { |
@@ -289,6 +355,66 @@ async fn run_user(db: &DatabaseConnection, config: &Config, cmd: UserCmd) -> Res
| 289 | 355 | Ok(()) |
| 290 | 356 | } |
| 291 | 357 | |
| 358 | +// ---------------------------------------------------------------------------- | |
| 359 | +// moderation (crate::moderation, logged with source `cli`) | |
| 360 | +// ---------------------------------------------------------------------------- | |
| 361 | + | |
| 362 | +use recourse::moderation::{self, Actor, Sanction}; | |
| 363 | + | |
| 364 | +async fn by_user(db: &DatabaseConnection, by: &Option<String>) -> Result<Option<users::Model>, DynErr> { | |
| 365 | + match by { | |
| 366 | + None => Ok(None), | |
| 367 | + Some(name) => { | |
| 368 | + let u = find_user(db, name).await?; | |
| 369 | + if !u.is_staff { | |
| 370 | + return Err(format!("--by {name}: not a staff account").into()); | |
| 371 | + } | |
| 372 | + Ok(Some(u)) | |
| 373 | + } | |
| 374 | + } | |
| 375 | +} | |
| 376 | + | |
| 377 | +fn action_err(e: recourse::actions::ActionError) -> DynErr { | |
| 378 | + e.message().into() | |
| 379 | +} | |
| 380 | + | |
| 381 | +async fn sanction_cmd(db: &DatabaseConnection, a: SanctionArgs, kind: Sanction) -> Result<(), DynErr> { | |
| 382 | + let target = find_user(db, &a.username).await?; | |
| 383 | + let by = by_user(db, &a.by).await?; | |
| 384 | + let until = match (a.hours, a.days) { | |
| 385 | + (Some(h), _) => Some(chrono::Utc::now() + chrono::Duration::hours(h)), | |
| 386 | + (_, Some(d)) => Some(chrono::Utc::now() + chrono::Duration::days(d)), | |
| 387 | + _ => None, | |
| 388 | + }; | |
| 389 | + let u = moderation::sanction(db, Actor::cli(by.as_ref()), target.id, kind, a.reason.as_deref(), until) | |
| 390 | + .await | |
| 391 | + .map_err(action_err)?; | |
| 392 | + let what = if kind == Sanction::Silence { "silenced" } else { "suspended (sessions and device tokens revoked)" }; | |
| 393 | + match until { | |
| 394 | + Some(t) => println!("{} {what} until {}.", u.username, t.format("%Y-%m-%d %H:%M UTC")), | |
| 395 | + None => println!("{} {what} until lifted.", u.username), | |
| 396 | + } | |
| 397 | + Ok(()) | |
| 398 | +} | |
| 399 | + | |
| 400 | +async fn lift_cmd(db: &DatabaseConnection, a: LiftArgs, kind: Sanction) -> Result<(), DynErr> { | |
| 401 | + let target = find_user(db, &a.username).await?; | |
| 402 | + let by = by_user(db, &a.by).await?; | |
| 403 | + let u = moderation::lift(db, Actor::cli(by.as_ref()), target.id, kind).await.map_err(action_err)?; | |
| 404 | + println!("{} is no longer {}.", u.username, if kind == Sanction::Silence { "silenced" } else { "suspended" }); | |
| 405 | + Ok(()) | |
| 406 | +} | |
| 407 | + | |
| 408 | +async fn shadow_cmd(db: &DatabaseConnection, a: ShadowArgs, on: bool) -> Result<(), DynErr> { | |
| 409 | + let target = find_user(db, &a.username).await?; | |
| 410 | + let by = by_user(db, &a.by).await?; | |
| 411 | + let u = moderation::set_flags_ignored(db, Actor::cli(by.as_ref()), target.id, on, a.reason.as_deref()) | |
| 412 | + .await | |
| 413 | + .map_err(action_err)?; | |
| 414 | + println!("{}'s flags are {}.", u.username, if on { "now ignored" } else { "counted again" }); | |
| 415 | + Ok(()) | |
| 416 | +} | |
| 417 | + | |
| 292 | 418 | // ---------------------------------------------------------------------------- |
| 293 | 419 | // invites |
| 294 | 420 | // ---------------------------------------------------------------------------- |
Parents: 3d71adc