View report history for a post or comment. Fixes #4190 (#4492)

This commit is contained in:
Dessalines 2024-03-05 05:31:40 -05:00 committed by GitHub
parent 36ad1868b3
commit 52155c74cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 18 additions and 2 deletions

View file

@ -16,6 +16,7 @@ pub async fn list_comment_reports(
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<ListCommentReportsResponse>, LemmyError> { ) -> Result<Json<ListCommentReportsResponse>, LemmyError> {
let community_id = data.community_id; let community_id = data.community_id;
let comment_id = data.comment_id;
let unresolved_only = data.unresolved_only.unwrap_or_default(); let unresolved_only = data.unresolved_only.unwrap_or_default();
check_community_mod_of_any_or_admin_action(&local_user_view, &mut context.pool()).await?; 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 limit = data.limit;
let comment_reports = CommentReportQuery { let comment_reports = CommentReportQuery {
community_id, community_id,
comment_id,
unresolved_only, unresolved_only,
page, page,
limit, limit,

View file

@ -16,6 +16,7 @@ pub async fn list_post_reports(
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<ListPostReportsResponse>, LemmyError> { ) -> Result<Json<ListPostReportsResponse>, LemmyError> {
let community_id = data.community_id; let community_id = data.community_id;
let post_id = data.post_id;
let unresolved_only = data.unresolved_only.unwrap_or_default(); let unresolved_only = data.unresolved_only.unwrap_or_default();
check_community_mod_of_any_or_admin_action(&local_user_view, &mut context.pool()).await?; 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 limit = data.limit;
let post_reports = PostReportQuery { let post_reports = PostReportQuery {
community_id, community_id,
post_id,
unresolved_only, unresolved_only,
page, page,
limit, limit,

View file

@ -161,6 +161,7 @@ pub struct ResolveCommentReport {
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// List comment reports. /// List comment reports.
pub struct ListCommentReports { pub struct ListCommentReports {
pub comment_id: Option<CommentId>,
pub page: Option<i64>, pub page: Option<i64>,
pub limit: Option<i64>, pub limit: Option<i64>,
/// Only shows the unresolved reports /// Only shows the unresolved reports

View file

@ -229,6 +229,7 @@ pub struct ListPostReports {
pub unresolved_only: Option<bool>, pub unresolved_only: Option<bool>,
/// if no community is given, it returns reports for all communities moderated by the auth user /// if no community is given, it returns reports for all communities moderated by the auth user
pub community_id: Option<CommunityId>, pub community_id: Option<CommunityId>,
pub post_id: Option<PostId>,
} }
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]

View file

@ -12,7 +12,7 @@ use diesel::{
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
aliases, aliases,
newtypes::{CommentReportId, CommunityId, PersonId}, newtypes::{CommentId, CommentReportId, CommunityId, PersonId},
schema::{ schema::{
comment, comment,
comment_aggregates, comment_aggregates,
@ -95,6 +95,10 @@ fn queries<'a>() -> Queries<
query = query.filter(post::community_id.eq(community_id)); 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 viewing all reports, order by newest, but if viewing unresolved only, show the oldest first (FIFO)
if options.unresolved_only { if options.unresolved_only {
query = query query = query
@ -186,6 +190,7 @@ impl CommentReportView {
#[derive(Default)] #[derive(Default)]
pub struct CommentReportQuery { pub struct CommentReportQuery {
pub community_id: Option<CommunityId>, pub community_id: Option<CommunityId>,
pub comment_id: Option<CommentId>,
pub page: Option<i64>, pub page: Option<i64>,
pub limit: Option<i64>, pub limit: Option<i64>,
pub unresolved_only: bool, pub unresolved_only: bool,

View file

@ -11,7 +11,7 @@ use diesel::{
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
aliases, aliases,
newtypes::{CommunityId, PersonId, PostReportId}, newtypes::{CommunityId, PersonId, PostId, PostReportId},
schema::{ schema::{
community, community,
community_moderator, community_moderator,
@ -83,6 +83,10 @@ fn queries<'a>() -> Queries<
query = query.filter(post::community_id.eq(community_id)); 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 viewing all reports, order by newest, but if viewing unresolved only, show the oldest first (FIFO)
if options.unresolved_only { if options.unresolved_only {
query = query query = query
@ -171,6 +175,7 @@ impl PostReportView {
#[derive(Default)] #[derive(Default)]
pub struct PostReportQuery { pub struct PostReportQuery {
pub community_id: Option<CommunityId>, pub community_id: Option<CommunityId>,
pub post_id: Option<PostId>,
pub page: Option<i64>, pub page: Option<i64>,
pub limit: Option<i64>, pub limit: Option<i64>,
pub unresolved_only: bool, pub unresolved_only: bool,