From 52155c74cb82f3252937e0fb799af079b0b9e2ce Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 5 Mar 2024 05:31:40 -0500 Subject: [PATCH] View report history for a post or comment. Fixes #4190 (#4492) --- crates/api/src/comment_report/list.rs | 2 ++ crates/api/src/post_report/list.rs | 2 ++ crates/api_common/src/comment.rs | 1 + crates/api_common/src/post.rs | 1 + crates/db_views/src/comment_report_view.rs | 7 ++++++- crates/db_views/src/post_report_view.rs | 7 ++++++- 6 files changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/api/src/comment_report/list.rs b/crates/api/src/comment_report/list.rs index e30a7ba84..f1577a77f 100644 --- a/crates/api/src/comment_report/list.rs +++ b/crates/api/src/comment_report/list.rs @@ -16,6 +16,7 @@ pub async fn list_comment_reports( local_user_view: LocalUserView, ) -> Result, LemmyError> { let community_id = data.community_id; + let comment_id = data.comment_id; let unresolved_only = data.unresolved_only.unwrap_or_default(); check_community_mod_of_any_or_admin_action(&local_user_view, &mut context.pool()).await?; @@ -24,6 +25,7 @@ pub async fn list_comment_reports( let limit = data.limit; let comment_reports = CommentReportQuery { community_id, + comment_id, unresolved_only, page, limit, diff --git a/crates/api/src/post_report/list.rs b/crates/api/src/post_report/list.rs index cce88a2e3..1f1aa9653 100644 --- a/crates/api/src/post_report/list.rs +++ b/crates/api/src/post_report/list.rs @@ -16,6 +16,7 @@ pub async fn list_post_reports( local_user_view: LocalUserView, ) -> Result, LemmyError> { let community_id = data.community_id; + let post_id = data.post_id; let unresolved_only = data.unresolved_only.unwrap_or_default(); check_community_mod_of_any_or_admin_action(&local_user_view, &mut context.pool()).await?; @@ -24,6 +25,7 @@ pub async fn list_post_reports( let limit = data.limit; let post_reports = PostReportQuery { community_id, + post_id, unresolved_only, page, limit, diff --git a/crates/api_common/src/comment.rs b/crates/api_common/src/comment.rs index d2be07c17..48800cf8d 100644 --- a/crates/api_common/src/comment.rs +++ b/crates/api_common/src/comment.rs @@ -161,6 +161,7 @@ pub struct ResolveCommentReport { #[cfg_attr(feature = "full", ts(export))] /// List comment reports. pub struct ListCommentReports { + pub comment_id: Option, pub page: Option, pub limit: Option, /// Only shows the unresolved reports diff --git a/crates/api_common/src/post.rs b/crates/api_common/src/post.rs index 69d1258e3..2cce24149 100644 --- a/crates/api_common/src/post.rs +++ b/crates/api_common/src/post.rs @@ -229,6 +229,7 @@ pub struct ListPostReports { pub unresolved_only: Option, /// if no community is given, it returns reports for all communities moderated by the auth user pub community_id: Option, + pub post_id: Option, } #[derive(Debug, Serialize, Deserialize, Clone)] diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index 05d95a756..6f3322b39 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -12,7 +12,7 @@ use diesel::{ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ aliases, - newtypes::{CommentReportId, CommunityId, PersonId}, + newtypes::{CommentId, CommentReportId, CommunityId, PersonId}, schema::{ comment, comment_aggregates, @@ -95,6 +95,10 @@ fn queries<'a>() -> Queries< query = query.filter(post::community_id.eq(community_id)); } + if let Some(comment_id) = options.comment_id { + query = query.filter(comment_report::comment_id.eq(comment_id)); + } + // If viewing all reports, order by newest, but if viewing unresolved only, show the oldest first (FIFO) if options.unresolved_only { query = query @@ -186,6 +190,7 @@ impl CommentReportView { #[derive(Default)] pub struct CommentReportQuery { pub community_id: Option, + pub comment_id: Option, pub page: Option, pub limit: Option, pub unresolved_only: bool, diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index b7c5df6a9..ddd12d226 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -11,7 +11,7 @@ use diesel::{ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ aliases, - newtypes::{CommunityId, PersonId, PostReportId}, + newtypes::{CommunityId, PersonId, PostId, PostReportId}, schema::{ community, community_moderator, @@ -83,6 +83,10 @@ fn queries<'a>() -> Queries< query = query.filter(post::community_id.eq(community_id)); } + if let Some(post_id) = options.post_id { + query = query.filter(post::id.eq(post_id)); + } + // If viewing all reports, order by newest, but if viewing unresolved only, show the oldest first (FIFO) if options.unresolved_only { query = query @@ -171,6 +175,7 @@ impl PostReportView { #[derive(Default)] pub struct PostReportQuery { pub community_id: Option, + pub post_id: Option, pub page: Option, pub limit: Option, pub unresolved_only: bool,