Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/api/src/comment_report/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub async fn list_comment_reports(
local_user_view: LocalUserView,
) -> Result<Json<ListCommentReportsResponse>, 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?;
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions crates/api/src/post_report/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub async fn list_post_reports(
local_user_view: LocalUserView,
) -> Result<Json<ListPostReportsResponse>, 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?;
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions crates/api_common/src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ pub struct ResolveCommentReport {
#[cfg_attr(feature = "full", ts(export))]
/// List comment reports.
pub struct ListCommentReports {
pub comment_id: Option<CommentId>,
pub page: Option<i64>,
pub limit: Option<i64>,
/// Only shows the unresolved reports
Expand Down
1 change: 1 addition & 0 deletions crates/api_common/src/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ pub struct ListPostReports {
pub unresolved_only: Option<bool>,
/// if no community is given, it returns reports for all communities moderated by the auth user
pub community_id: Option<CommunityId>,
pub post_id: Option<PostId>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down
7 changes: 6 additions & 1 deletion crates/db_views/src/comment_report_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -186,6 +190,7 @@ impl CommentReportView {
#[derive(Default)]
pub struct CommentReportQuery {
pub community_id: Option<CommunityId>,
pub comment_id: Option<CommentId>,
pub page: Option<i64>,
pub limit: Option<i64>,
pub unresolved_only: bool,
Expand Down
7 changes: 6 additions & 1 deletion crates/db_views/src/post_report_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -171,6 +175,7 @@ impl PostReportView {
#[derive(Default)]
pub struct PostReportQuery {
pub community_id: Option<CommunityId>,
pub post_id: Option<PostId>,
pub page: Option<i64>,
pub limit: Option<i64>,
pub unresolved_only: bool,
Expand Down