Cooldown: read-only for 1h to 90 days with a reason, from the queue, the user page and manage user cooldown

e0979f3 · gmorell · 2026-12-03 02:55

20 files +180 -62
Message
{commit_body(@commit)}

Files changed

modified README.md
+8 −5
@@ -89,12 +89,15 @@ Classic and Focus:
89 89 Every action is inline: dismiss, moderate, delete, lock, and silence,
90 90 suspend or ignore flags for the author or a flagger.
91 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.
92 + - *Cooldown:* read-only (can read, can't post, reply, react or flag) for
93 + 1h / 1d / 3d / 7d / 30d / 90d or a custom length, never more than 90
94 + days, always with a reason. They see "Read-only until …: reason". It
95 + ends by itself: the end is compared with the clock, so no job runs.
96 + - *Suspend:* can't sign in; sessions and app tokens are revoked. Takes a
97 + reason and an optional end, both shown on the sign-in page.
95 98 - *Flag shadowban:* their flags are recorded and look normal to them, but
96 99 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>`.
100 + - From the flag queue, `/admin/users/{id}`, or `manage user cooldown|end-cooldown|suspend|unsuspend|flag-shadowban|unflag-shadowban <name>`.
98 101 - **Log:** every staff action, from the web or the CLI, is in
99 102 `/admin/log` (also per user).
100 103
@@ -248,7 +251,7 @@ never taken over, and accounts created this way are never staff. In
248 251 - `manage user create <name> --email E [--staff] [--password-stdin]` — no invite needed; without `--password-stdin` a strong password is generated and printed once
249 252 - `manage user list | set-staff <name> [--revoke] | set-trust <name> <0-4> | activate <name> | deactivate <name> | delete <name> --yes`
250 253 - `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
254 + - `manage user cooldown <name> <12h|5d|2w> --reason R [--by STAFF]` (≤ 90 days), `suspend <name> [--reason R] [--hours N | --days N] [--by STAFF]`, `end-cooldown|unsuspend <name>`, `flag-shadowban|unflag-shadowban <name> [--reason R]` — logged as `cli` (and the `--by` account) in the moderation log
252 255 - `manage invite create [--email E] [--days N] | list | show <token>`
253 256 - `manage email test <to>` — send a test message through mail-prism (or report it isn't configured)
254 257 - `manage seed [--demo [--allow-public]]` — baseline categories/reactions/tags; `--demo` adds demo users and content
modified docs/api.md
+4 −3
@@ -59,7 +59,7 @@ The older `GET /api/profile` (cookie or bearer) is unchanged.
59 59 |---|---|
60 60 | 400 | `bad_request` (unreadable JSON or a malformed id; `details.reason`) |
61 61 | 401 | `unauthorized` |
62 −| 403 | `unverified`, `silenced`, `locked` (topic locked by staff), `staff_only` / `trust_level` (the category's posting rule, or the trust needed to flag), `own_post` (flagging your own), `moderated` / `hidden` (a post staff moderated or that is hidden pending review), `not_author` (tags) |
62 +| 403 | `unverified`, `silenced` (a cooldown: read-only), `locked` (topic locked by staff), `staff_only` / `trust_level` (the category's posting rule, or the trust needed to flag), `own_post` (flagging your own), `moderated` / `hidden` (a post staff moderated or that is hidden pending review), `not_author` (tags) |
63 63 | 409 | `already_flagged` |
64 64 | 404 | `not_found` |
65 65 | 410 | `removed` (a deleted topic, for non-staff) |
@@ -122,8 +122,9 @@ moderated, hidden, can_react, can_flag, flagged}`.
122 122 - `hidden: true` means flagged past the threshold and waiting for staff:
123 123 `cooked` is empty unless you wrote it.
124 124 - `flagged` means you flagged it (`can_flag` is then false).
125 −- `/me`'s `user.silenced` is `{until, reason, message}` or null; `may_write`
126 − is false while it lasts. A suspended account's token is revoked and any
125 +- `/me`'s `user.silenced` is a cooldown in force, `{until, reason, message}`
126 + (message: "Read-only until …: reason"), or null; `user.read_only_until` is
127 + the same end, flat. `may_write` is false while it lasts. A suspended account's token is revoked and any
127 128 request is 401.
128 129 - Staff moderation (moderate, hide, lock, the flag queue, sanctions) is
129 130 web-only.
modified src/api/views.rs
+4 −1
@@ -51,8 +51,10 @@ pub struct Me {
51 51 /// site requires one) and no silence. Categories and locks add their own
52 52 /// rules (`can_create_topic`, `can_reply`).
53 53 pub may_write: bool,
54 − /// A silence in force: the app shows it as a banner.
54 + /// A cooldown (read-only) in force: the app shows it as a banner.
55 55 pub silenced: Option<SanctionView>,
56 + /// The same cooldown's end, flat: read-only until then.
57 + pub read_only_until: Option<DateTime<Utc>>,
56 58 /// New tags (not just existing ones) on a topic.
57 59 pub may_create_tags: bool,
58 60 /// `classic` or `focus`: the profile's Layout.
@@ -76,6 +78,7 @@ impl Me {
76 78 trust_name: crate::trust::tier_name(u.trust_level),
77 79 email_verified: u.email_verified_at.is_some(),
78 80 may_write: crate::actions::can_write(state, u),
81 + read_only_until: crate::policy::silence(u).and_then(|s| s.until),
79 82 silenced: crate::policy::silence(u).map(|s| SanctionView {
80 83 message: crate::policy::silence_message(&s),
81 84 until: s.until,
modified src/bin/manage.rs
+39 −10
@@ -10,8 +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]
13 +//! manage user cooldown <username> <12h|5d|2w> --reason R [--by STAFF] (read-only, ≤ 90 days)
14 +//! manage user suspend <username> [--reason R] [--hours N | --days N] [--by STAFF]
15 +//! manage user end-cooldown|unsuspend <username> [--by STAFF]
15 16 //! manage user flag-shadowban|unflag-shadowban <username> [--reason R] [--by STAFF]
16 17 //! manage invite create [--email E] [--days N] [--created-by UUID]
17 18 //! manage invite list
@@ -106,12 +107,15 @@ enum UserCmd {
106 107 Activate { username: String },
107 108 /// Deactivate an account and drop its sessions
108 109 Deactivate { username: String },
109 − /// Silence: can read, can't post, reply, react or flag. Logged.
110 − Silence(SanctionArgs),
110 + /// Cooldown: read-only (can't post, reply, react or flag) for a while,
111 + /// at most 90 days. Logged.
112 + #[command(alias = "silence")]
113 + Cooldown(CooldownArgs),
111 114 /// Suspend: can't sign in; signed out of every session and device. Logged.
112 115 Suspend(SanctionArgs),
113 − /// Lift a silence
114 − Unsilence(LiftArgs),
116 + /// End a cooldown early
117 + #[command(alias = "unsilence")]
118 + EndCooldown(LiftArgs),
115 119 /// Lift a suspension
116 120 Unsuspend(LiftArgs),
117 121 /// Ignore this user's flags (they aren't told). Logged.
@@ -145,6 +149,18 @@ struct SanctionArgs {
145 149 by: Option<String>,
146 150 }
147 151
152 +#[derive(clap::Args)]
153 +struct CooldownArgs {
154 + username: String,
155 + /// How long: 12h, 5d, 2w (at most 90 days)
156 + duration: String,
157 + /// Shown to them (required)
158 + #[arg(long)]
159 + reason: String,
160 + #[arg(long)]
161 + by: Option<String>,
162 +}
163 +
148 164 #[derive(clap::Args)]
149 165 struct LiftArgs {
150 166 username: String,
@@ -333,9 +349,9 @@ async fn run_user(db: &DatabaseConnection, config: &Config, cmd: UserCmd) -> Res
333 349 auth::deactivate_user(db, user.id).await?;
334 350 println!("{username} deactivated (sessions dropped).");
335 351 }
336 − UserCmd::Silence(a) => sanction_cmd(db, a, Sanction::Silence).await?,
352 + UserCmd::Cooldown(a) => cooldown_cmd(db, a).await?,
337 353 UserCmd::Suspend(a) => sanction_cmd(db, a, Sanction::Suspend).await?,
338 − UserCmd::Unsilence(a) => lift_cmd(db, a, Sanction::Silence).await?,
354 + UserCmd::EndCooldown(a) => lift_cmd(db, a, Sanction::Silence).await?,
339 355 UserCmd::Unsuspend(a) => lift_cmd(db, a, Sanction::Suspend).await?,
340 356 UserCmd::FlagShadowban(a) => shadow_cmd(db, a, true).await?,
341 357 UserCmd::UnflagShadowban(a) => shadow_cmd(db, a, false).await?,
@@ -389,7 +405,7 @@ async fn sanction_cmd(db: &DatabaseConnection, a: SanctionArgs, kind: Sanction)
389 405 let u = moderation::sanction(db, Actor::cli(by.as_ref()), target.id, kind, a.reason.as_deref(), until)
390 406 .await
391 407 .map_err(action_err)?;
392 − let what = if kind == Sanction::Silence { "silenced" } else { "suspended (sessions and device tokens revoked)" };
408 + let what = if kind == Sanction::Silence { "read-only" } else { "suspended (sessions and device tokens revoked)" };
393 409 match until {
394 410 Some(t) => println!("{} {what} until {}.", u.username, t.format("%Y-%m-%d %H:%M UTC")),
395 411 None => println!("{} {what} until lifted.", u.username),
@@ -397,11 +413,24 @@ async fn sanction_cmd(db: &DatabaseConnection, a: SanctionArgs, kind: Sanction)
397 413 Ok(())
398 414 }
399 415
416 +async fn cooldown_cmd(db: &DatabaseConnection, a: CooldownArgs) -> Result<(), DynErr> {
417 + let target = find_user(db, &a.username).await?;
418 + let by = by_user(db, &a.by).await?;
419 + let length = recourse::handlers::moderation::parse_length(&a.duration)
420 + .ok_or_else(|| format!("{}: a number then h, d or w (e.g. 12h, 5d, 2w)", a.duration))?;
421 + let until = chrono::Utc::now() + length;
422 + let u = moderation::sanction(db, Actor::cli(by.as_ref()), target.id, Sanction::Silence, Some(&a.reason), Some(until))
423 + .await
424 + .map_err(action_err)?;
425 + println!("{} is read-only until {}.", u.username, until.format("%Y-%m-%d %H:%M UTC"));
426 + Ok(())
427 +}
428 +
400 429 async fn lift_cmd(db: &DatabaseConnection, a: LiftArgs, kind: Sanction) -> Result<(), DynErr> {
401 430 let target = find_user(db, &a.username).await?;
402 431 let by = by_user(db, &a.by).await?;
403 432 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" });
433 + println!("{} is no longer {}.", u.username, if kind == Sanction::Silence { "read-only" } else { "suspended" });
405 434 Ok(())
406 435 }
407 436
modified src/handlers/moderation.rs
+62 −22
@@ -180,7 +180,7 @@ async fn queue_item(state: &AppState, post: posts::Model) -> Result<QueueItem, S
180 180 author: author.as_ref().map(|u| u.username.clone()).unwrap_or_else(|| "unknown".into()),
181 181 author_id: post.user_id,
182 182 author_staff: author.as_ref().is_some_and(|u| u.is_staff),
183 − author_silenced: author.as_ref().and_then(policy::silence).map(|s| format!("silenced{}", s.until_text())),
183 + author_silenced: author.as_ref().and_then(policy::silence).map(|s| format!("read-only{}", s.until_text())),
184 184 author_suspended: author.as_ref().and_then(policy::suspension).map(|s| format!("suspended{}", s.until_text())),
185 185 author_trust: author.as_ref().map(|u| u.trust_level).unwrap_or(0),
186 186 author_age: author.as_ref().map(|u| rel(u.created_at)).unwrap_or_default(),
@@ -269,7 +269,7 @@ pub async fn flags_page(
269 269 filter => filter,
270 270 nav => "flags",
271 271 threshold => context! { ratio_pct => format!("{:.0}%", t.ratio * 100.0), min_flags => t.min_flags, enough_flags => t.enough_flags },
272 − durations => DURATIONS,
272 + durations => DURATIONS, cooldowns => COOLDOWNS,
273 273 },
274 274 )?;
275 275 Ok(view.respond(page))
@@ -288,7 +288,7 @@ async fn queue_response(state: &AppState, post_id: Uuid, mode: Option<&str>, res
288 288 Ok(render(
289 289 state,
290 290 if focus { "admin/_flag_card.html" } else { "admin/_flag_row.html" },
291 − context! { item => item, mode => if focus { "focus" } else { "classic" }, durations => DURATIONS },
291 + context! { item => item, mode => if focus { "focus" } else { "classic" }, durations => DURATIONS, cooldowns => COOLDOWNS },
292 292 )?
293 293 .into_response())
294 294 }
@@ -363,23 +363,52 @@ pub async fn flags_lock(
363 363
364 364 /// The sanction lengths offered (`duration` field): label, hours (0 =
365 365 /// until lifted).
366 +/// Suspension lengths.
366 367 pub const DURATIONS: [(&str, &str); 6] =
367 368 [("1h", "1 hour"), ("24h", "1 day"), ("72h", "3 days"), ("168h", "1 week"), ("720h", "30 days"), ("", "Until lifted")];
368 369
369 −/// "24h" → 24 hours from now; blank → None (until lifted).
370 +/// Cooldown (read-only) presets: always timed, at most 90 days
371 +/// (`policy::MAX_COOLDOWN_DAYS`, enforced in `moderation::sanction`), plus
372 +/// `custom` (the form's `custom` field, e.g. `5d`, `12h`, `2w`).
373 +pub const COOLDOWNS: [(&str, &str); 7] = [
374 + ("1h", "1 hour"),
375 + ("24h", "1 day"),
376 + ("72h", "3 days"),
377 + ("168h", "7 days"),
378 + ("720h", "30 days"),
379 + ("2160h", "90 days"),
380 + ("custom", "Custom…"),
381 +];
382 +
383 +/// A length: `<n>h`, `<n>d` or `<n>w`.
384 +pub fn parse_length(v: &str) -> Option<Duration> {
385 + let v = v.trim();
386 + if v.len() < 2 {
387 + return None;
388 + }
389 + let (n, unit) = v.split_at(v.len() - 1);
390 + let n: i64 = n.trim().parse().ok().filter(|n| *n > 0)?;
391 + match unit {
392 + "h" => Some(Duration::hours(n)),
393 + "d" => Some(Duration::days(n)),
394 + "w" => Some(Duration::weeks(n)),
395 + _ => None,
396 + }
397 +}
398 +
399 +/// "24h" → 24 hours from now; blank → None (until lifted); `custom` takes
400 +/// the custom field.
370 401 pub fn parse_duration(s: Option<&str>) -> Result<Option<chrono::DateTime<Utc>>, StatusCode> {
402 + parse_choice(s, None)
403 +}
404 +
405 +fn parse_choice(s: Option<&str>, custom: Option<&str>) -> Result<Option<chrono::DateTime<Utc>>, StatusCode> {
371 406 match s.map(str::trim) {
372 407 None | Some("") => Ok(None),
373 − Some(v) => {
374 − let (n, unit) = v.split_at(v.len() - 1);
375 − let n: i64 = n.parse().map_err(|_| StatusCode::BAD_REQUEST)?;
376 − let d = match unit {
377 − "h" => Duration::hours(n),
378 − "d" => Duration::days(n),
379 − _ => return Err(StatusCode::BAD_REQUEST),
380 − };
381 − Ok(Some(Utc::now() + d))
408 + Some("custom") => {
409 + parse_length(custom.unwrap_or_default()).map(|d| Some(Utc::now() + d)).ok_or(StatusCode::BAD_REQUEST)
382 410 }
411 + Some(v) => parse_length(v).map(|d| Some(Utc::now() + d)).ok_or(StatusCode::BAD_REQUEST),
383 412 }
384 413 }
385 414
@@ -412,7 +441,7 @@ async fn user_row(state: &AppState, u: users::Model) -> Result<UserRow, StatusCo
412 441 .map_err(ise("count upheld"))?;
413 442 let reason = |r: &Option<String>| r.as_ref().map(|r| format!(": {r}")).unwrap_or_default();
414 443 Ok(UserRow {
415 − silenced: policy::silence(&u).map(|s| format!("Silenced{}{}", s.until_text(), reason(&s.reason))),
444 + silenced: policy::silence(&u).map(|s| format!("Read-only{}{}", s.until_text(), reason(&s.reason))),
416 445 suspended: policy::suspension(&u).map(|s| format!("Suspended{}{}", s.until_text(), reason(&s.reason))),
417 446 flags_ignored: u.flags_ignored_at.is_some(),
418 447 id: u.id,
@@ -461,7 +490,7 @@ pub async fn users_page(
461 490 nav => "users",
462 491 q => search,
463 492 mode => view.mode.as_str(),
464 − durations => DURATIONS,
493 + durations => DURATIONS, cooldowns => COOLDOWNS,
465 494 },
466 495 )?;
467 496 Ok(view.respond(page))
@@ -530,7 +559,7 @@ pub async fn user_page(
530 559 nav => "users",
531 560 // The card's actions answer with a card.
532 561 mode => "focus",
533 − durations => DURATIONS,
562 + durations => DURATIONS, cooldowns => COOLDOWNS,
534 563 })?;
535 564 Ok(view.respond(page))
536 565 }
@@ -540,6 +569,8 @@ pub struct SanctionForm {
540 569 pub reason: Option<String>,
541 570 /// See [`DURATIONS`].
542 571 pub duration: Option<String>,
572 + /// With `duration=custom`: `<n>h`, `<n>d` or `<n>w`.
573 + pub custom: Option<String>,
543 574 /// `classic` / `focus`: which fragment to answer with.
544 575 pub mode: Option<String>,
545 576 /// Acting from the queue: answer with this post's queue item.
@@ -560,7 +591,7 @@ async fn user_response(state: &AppState, user_id: Uuid, f: &SanctionForm) -> Res
560 591 Ok(render(
561 592 state,
562 593 if focus { "admin/_user_card.html" } else { "admin/_user_row.html" },
563 − context! { u => row, mode => if focus { "focus" } else { "classic" }, durations => DURATIONS },
594 + context! { u => row, mode => if focus { "focus" } else { "classic" }, durations => DURATIONS, cooldowns => COOLDOWNS },
564 595 )?
565 596 .into_response())
566 597 }
@@ -578,13 +609,14 @@ pub async fn user_action(
578 609 let actor = Actor::web(&user.user);
579 610 let reason = f.reason.as_deref();
580 611 match action.as_str() {
581 − "silence" => {
582 − moderation::sanction(db, actor, id, Sanction::Silence, reason, parse_duration(f.duration.as_deref())?).await?;
612 + "silence" | "cooldown" => {
613 + let until = parse_choice(f.duration.as_deref(), f.custom.as_deref())?;
614 + moderation::sanction(db, actor, id, Sanction::Silence, reason, until).await?;
583 615 }
584 616 "suspend" => {
585 617 moderation::sanction(db, actor, id, Sanction::Suspend, reason, parse_duration(f.duration.as_deref())?).await?;
586 618 }
587 − "unsilence" => {
619 + "unsilence" | "end-cooldown" => {
588 620 moderation::lift(db, actor, id, Sanction::Silence).await?;
589 621 }
590 622 "unsuspend" => {
@@ -636,8 +668,8 @@ pub fn action_label(a: &str) -> &'static str {
636 668 "restore_post_body" => "Restored post body",
637 669 "auto_hide" => "Auto-hid post",
638 670 "dismiss_flags" => "Dismissed flags",
639 − "silence_user" => "Silenced",
640 − "unsilence_user" => "Lifted silence",
671 + "silence_user" => "Cooldown (read-only)",
672 + "unsilence_user" => "Ended cooldown",
641 673 "suspend_user" => "Suspended",
642 674 "unsuspend_user" => "Lifted suspension",
643 675 "flag_shadowban" => "Ignored flags",
@@ -747,5 +779,13 @@ mod tests {
747 779 for (v, _) in DURATIONS {
748 780 assert!(parse_duration(Some(v)).is_ok());
749 781 }
782 + for (v, _) in COOLDOWNS.iter().filter(|(v, _)| *v != "custom") {
783 + let end = parse_duration(Some(v)).unwrap().unwrap();
784 + assert!(end <= Utc::now() + Duration::days(crate::policy::MAX_COOLDOWN_DAYS));
785 + }
786 + let two_weeks = parse_choice(Some("custom"), Some("2w")).unwrap().unwrap();
787 + assert!((two_weeks - Utc::now() - Duration::days(14)).num_seconds().abs() < 5);
788 + assert!(parse_choice(Some("custom"), Some("")).is_err());
789 + assert!(parse_choice(Some("custom"), Some("-3d")).is_err());
750 790 }
751 791 }
modified src/moderation.rs
+18 −0

Click to load diff…

modified src/policy.rs
+6 −2

Click to load diff…

modified templates/admin/_author_glance.html
+1 −1

Click to load diff…

modified templates/admin/_flag_actions.html
+3 −3

Click to load diff…

modified templates/admin/_sanction_form.html
+9 −7

Click to load diff…

modified templates/admin/_user_actions.html
+3 −3

Click to load diff…

modified tests/moderation_db.rs
+23 −5

Click to load diff…

Parents: 147d2cc