Skip to main content

max / makenotwork

Fix auto_hide audit trail: set removed_by to NULL for system-initiated removals The mod action log already records AutoHidePost with the triggering flagger. Setting removed_by to a specific user was misleading since no mod acted. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Author: Max J. <87768334+MaxJMath@users.noreply.github.com> · 2026-04-26 20:20 UTC
Commit: 321c73ec6ff405b8176656791a9814de9c84217c
Parent: 1be99fd
2 files changed, +4 insertions, -5 deletions
@@ -223,20 +223,19 @@ pub async fn mod_remove_post(
223 223 /// Atomically auto-hide a post if pending flag count meets the threshold.
224 224 /// Combines count check and removal in a single query to avoid race conditions.
225 225 /// Returns true if the post was actually removed.
226 + /// Sets removed_by to NULL (system action) — the mod log records the event.
226 227 #[tracing::instrument(skip_all)]
227 228 pub async fn auto_hide_if_threshold_met(
228 229 pool: &PgPool,
229 230 post_id: Uuid,
230 - removed_by_id: Uuid,
231 231 threshold: i32,
232 232 ) -> Result<bool, sqlx::Error> {
233 233 let result = sqlx::query(
234 - "UPDATE posts SET removed_by = $2, removed_at = now()
234 + "UPDATE posts SET removed_by = NULL, removed_at = now()
235 235 WHERE id = $1 AND removed_at IS NULL
236 - AND (SELECT COUNT(*) FROM post_flags WHERE post_id = $1 AND resolved_at IS NULL) >= $3",
236 + AND (SELECT COUNT(*) FROM post_flags WHERE post_id = $1 AND resolved_at IS NULL) >= $2",
237 237 )
238 238 .bind(post_id)
239 - .bind(removed_by_id)
240 239 .bind(threshold as i64)
241 240 .execute(pool)
242 241 .await?;
@@ -79,7 +79,7 @@ pub(super) async fn flag_post_handler(
79 79 && threshold > 0
80 80 {
81 81 match mt_db::mutations::auto_hide_if_threshold_met(
82 - &state.db, post_id, user.user_id, threshold,
82 + &state.db, post_id, threshold,
83 83 ).await {
84 84 Ok(true) => {
85 85 log_mod_action(