From 65da4e7dbd7a857256981f6753751f203041bd1d Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 4 Mar 2024 11:42:25 -0500 Subject: [PATCH] View mod history for a post or comment. Fixes #4162 (#4491) --- crates/api/src/site/mod_log.rs | 5 +++++ crates/api_common/src/site.rs | 2 ++ crates/db_views_moderator/src/mod_feature_post_view.rs | 4 ++++ crates/db_views_moderator/src/mod_lock_post_view.rs | 4 ++++ crates/db_views_moderator/src/mod_remove_comment_view.rs | 4 ++++ crates/db_views_moderator/src/mod_remove_post_view.rs | 4 ++++ crates/db_views_moderator/src/structs.rs | 4 +++- 7 files changed, 26 insertions(+), 1 deletion(-) diff --git a/crates/api/src/site/mod_log.rs b/crates/api/src/site/mod_log.rs index e54d13731..1a4148d89 100644 --- a/crates/api/src/site/mod_log.rs +++ b/crates/api/src/site/mod_log.rs @@ -55,10 +55,15 @@ pub async fn get_mod_log( data.mod_person_id }; let other_person_id = data.other_person_id; + let post_id = data.post_id; + let comment_id = data.comment_id; + let params = ModlogListParams { community_id, mod_person_id, other_person_id, + post_id, + comment_id, page: data.page, limit: data.limit, hide_modlog_names, diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index 912fbd343..bed81c2e4 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -118,6 +118,8 @@ pub struct GetModlog { pub limit: Option, pub type_: Option, pub other_person_id: Option, + pub post_id: Option, + pub comment_id: Option, } #[derive(Debug, Serialize, Deserialize, Clone)] diff --git a/crates/db_views_moderator/src/mod_feature_post_view.rs b/crates/db_views_moderator/src/mod_feature_post_view.rs index 324816178..1bf83688d 100644 --- a/crates/db_views_moderator/src/mod_feature_post_view.rs +++ b/crates/db_views_moderator/src/mod_feature_post_view.rs @@ -51,6 +51,10 @@ impl ModFeaturePostView { query = query.filter(person_alias_1.field(person::id).eq(other_person_id)); }; + if let Some(post_id) = params.post_id { + query = query.filter(post::id.eq(post_id)); + } + let (limit, offset) = limit_and_offset(params.page, params.limit)?; query diff --git a/crates/db_views_moderator/src/mod_lock_post_view.rs b/crates/db_views_moderator/src/mod_lock_post_view.rs index 7351b4f29..6f7e83ec7 100644 --- a/crates/db_views_moderator/src/mod_lock_post_view.rs +++ b/crates/db_views_moderator/src/mod_lock_post_view.rs @@ -52,6 +52,10 @@ impl ModLockPostView { query = query.filter(person_alias_1.field(person::id).eq(other_person_id)); }; + if let Some(post_id) = params.post_id { + query = query.filter(post::id.eq(post_id)); + } + let (limit, offset) = limit_and_offset(params.page, params.limit)?; query diff --git a/crates/db_views_moderator/src/mod_remove_comment_view.rs b/crates/db_views_moderator/src/mod_remove_comment_view.rs index 9b8a71a7b..e7d695a5c 100644 --- a/crates/db_views_moderator/src/mod_remove_comment_view.rs +++ b/crates/db_views_moderator/src/mod_remove_comment_view.rs @@ -54,6 +54,10 @@ impl ModRemoveCommentView { query = query.filter(person_alias_1.field(person::id).eq(other_person_id)); }; + if let Some(comment_id) = params.comment_id { + query = query.filter(comment::id.eq(comment_id)); + } + let (limit, offset) = limit_and_offset(params.page, params.limit)?; query diff --git a/crates/db_views_moderator/src/mod_remove_post_view.rs b/crates/db_views_moderator/src/mod_remove_post_view.rs index 60469088c..fb0b3e6c1 100644 --- a/crates/db_views_moderator/src/mod_remove_post_view.rs +++ b/crates/db_views_moderator/src/mod_remove_post_view.rs @@ -52,6 +52,10 @@ impl ModRemovePostView { query = query.filter(person_alias_1.field(person::id).eq(other_person_id)); }; + if let Some(post_id) = params.post_id { + query = query.filter(post::id.eq(post_id)); + } + let (limit, offset) = limit_and_offset(params.page, params.limit)?; query diff --git a/crates/db_views_moderator/src/structs.rs b/crates/db_views_moderator/src/structs.rs index 2335e7721..10ad78942 100644 --- a/crates/db_views_moderator/src/structs.rs +++ b/crates/db_views_moderator/src/structs.rs @@ -1,7 +1,7 @@ #[cfg(feature = "full")] use diesel::Queryable; use lemmy_db_schema::{ - newtypes::{CommunityId, PersonId}, + newtypes::{CommentId, CommunityId, PersonId, PostId}, source::{ comment::Comment, community::Community, @@ -228,6 +228,8 @@ pub struct ModlogListParams { pub community_id: Option, pub mod_person_id: Option, pub other_person_id: Option, + pub post_id: Option, + pub comment_id: Option, pub page: Option, pub limit: Option, pub hide_modlog_names: bool,