Finishing up combined report table.

This commit is contained in:
Dessalines 2024-11-26 16:53:01 -05:00
parent 39b3ec2473
commit 1ff8ae0641
31 changed files with 541 additions and 349 deletions

View file

@ -33,13 +33,11 @@ use std::io::Cursor;
use totp_rs::{Secret, TOTP}; use totp_rs::{Secret, TOTP};
pub mod comment; pub mod comment;
pub mod comment_report;
pub mod community; pub mod community;
pub mod local_user; pub mod local_user;
pub mod post; pub mod post;
pub mod post_report;
pub mod private_message; pub mod private_message;
pub mod private_message_report; pub mod reports;
pub mod site; pub mod site;
pub mod sitemap; pub mod sitemap;

View file

@ -2,8 +2,8 @@ use crate::check_report_reason;
use activitypub_federation::config::Data; use activitypub_federation::config::Data;
use actix_web::web::Json; use actix_web::web::Json;
use lemmy_api_common::{ use lemmy_api_common::{
comment::{CommentReportResponse, CreateCommentReport},
context::LemmyContext, context::LemmyContext,
reports::comment::{CommentReportResponse, CreateCommentReport},
send_activity::{ActivityChannel, SendActivityData}, send_activity::{ActivityChannel, SendActivityData},
utils::{ utils::{
check_comment_deleted_or_removed, check_comment_deleted_or_removed,

View file

@ -1,7 +1,7 @@
use actix_web::web::{Data, Json, Query}; use actix_web::web::{Data, Json, Query};
use lemmy_api_common::{ use lemmy_api_common::{
comment::{ListCommentReports, ListCommentReportsResponse},
context::LemmyContext, context::LemmyContext,
reports::comment::{ListCommentReports, ListCommentReportsResponse},
utils::check_community_mod_of_any_or_admin_action, utils::check_community_mod_of_any_or_admin_action,
}; };
use lemmy_db_views::{comment_report_view::CommentReportQuery, structs::LocalUserView}; use lemmy_db_views::{comment_report_view::CommentReportQuery, structs::LocalUserView};

View file

@ -1,7 +1,7 @@
use actix_web::web::{Data, Json}; use actix_web::web::{Data, Json};
use lemmy_api_common::{ use lemmy_api_common::{
comment::{CommentReportResponse, ResolveCommentReport},
context::LemmyContext, context::LemmyContext,
reports::comment::{CommentReportResponse, ResolveCommentReport},
utils::check_community_mod_action, utils::check_community_mod_action,
}; };
use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable}; use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable};

View file

@ -0,0 +1,4 @@
pub mod comment_report;
pub mod post_report;
pub mod private_message_report;
pub mod report_combined;

View file

@ -3,7 +3,7 @@ use activitypub_federation::config::Data;
use actix_web::web::Json; use actix_web::web::Json;
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
post::{CreatePostReport, PostReportResponse}, reports::post::{CreatePostReport, PostReportResponse},
send_activity::{ActivityChannel, SendActivityData}, send_activity::{ActivityChannel, SendActivityData},
utils::{ utils::{
check_community_user_action, check_community_user_action,

View file

@ -1,7 +1,7 @@
use actix_web::web::{Data, Json, Query}; use actix_web::web::{Data, Json, Query};
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
post::{ListPostReports, ListPostReportsResponse}, reports::post::{ListPostReports, ListPostReportsResponse},
utils::check_community_mod_of_any_or_admin_action, utils::check_community_mod_of_any_or_admin_action,
}; };
use lemmy_db_views::{post_report_view::PostReportQuery, structs::LocalUserView}; use lemmy_db_views::{post_report_view::PostReportQuery, structs::LocalUserView};

View file

@ -1,7 +1,7 @@
use actix_web::web::{Data, Json}; use actix_web::web::{Data, Json};
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
post::{PostReportResponse, ResolvePostReport}, reports::post::{PostReportResponse, ResolvePostReport},
utils::check_community_mod_action, utils::check_community_mod_action,
}; };
use lemmy_db_schema::{source::post_report::PostReport, traits::Reportable}; use lemmy_db_schema::{source::post_report::PostReport, traits::Reportable};

View file

@ -2,7 +2,7 @@ use crate::check_report_reason;
use actix_web::web::{Data, Json}; use actix_web::web::{Data, Json};
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
private_message::{CreatePrivateMessageReport, PrivateMessageReportResponse}, reports::private_message::{CreatePrivateMessageReport, PrivateMessageReportResponse},
utils::send_new_report_email_to_admins, utils::send_new_report_email_to_admins,
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{

View file

@ -1,7 +1,7 @@
use actix_web::web::{Data, Json, Query}; use actix_web::web::{Data, Json, Query};
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
private_message::{ListPrivateMessageReports, ListPrivateMessageReportsResponse}, reports::private_message::{ListPrivateMessageReports, ListPrivateMessageReportsResponse},
utils::is_admin, utils::is_admin,
}; };
use lemmy_db_views::{ use lemmy_db_views::{

View file

@ -1,7 +1,7 @@
use actix_web::web::{Data, Json}; use actix_web::web::{Data, Json};
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
private_message::{PrivateMessageReportResponse, ResolvePrivateMessageReport}, reports::private_message::{PrivateMessageReportResponse, ResolvePrivateMessageReport},
utils::is_admin, utils::is_admin,
}; };
use lemmy_db_schema::{source::private_message_report::PrivateMessageReport, traits::Reportable}; use lemmy_db_schema::{source::private_message_report::PrivateMessageReport, traits::Reportable};

View file

@ -0,0 +1,35 @@
use actix_web::web::{Data, Json, Query};
use lemmy_api_common::{
context::LemmyContext,
reports::combined::{ListReports, ListReportsResponse},
utils::check_community_mod_of_any_or_admin_action,
};
use lemmy_db_views::{report_combined_view::ReportCombinedQuery, structs::LocalUserView};
use lemmy_utils::error::LemmyResult;
/// Lists reports for a community if an id is supplied
/// or returns all reports for communities a user moderates
#[tracing::instrument(skip(context))]
pub async fn list_reports(
data: Query<ListReports>,
context: Data<LemmyContext>,
local_user_view: LocalUserView,
) -> LemmyResult<Json<ListReportsResponse>> {
let community_id = data.community_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?;
let page = data.page;
let limit = data.limit;
let reports = ReportCombinedQuery {
community_id,
unresolved_only,
page,
limit,
}
.list(&mut context.pool(), &local_user_view)
.await?;
Ok(Json(ListReportsResponse { reports }))
}

View file

@ -0,0 +1 @@
pub mod list;

View file

@ -1,9 +1,9 @@
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::{CommentId, CommentReportId, CommunityId, LanguageId, LocalUserId, PostId}, newtypes::{CommentId, CommunityId, LanguageId, LocalUserId, PostId},
CommentSortType, CommentSortType,
ListingType, ListingType,
}; };
use lemmy_db_views::structs::{CommentReportView, CommentView, VoteView}; use lemmy_db_views::structs::{CommentView, VoteView};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
#[cfg(feature = "full")] #[cfg(feature = "full")]
@ -146,60 +146,6 @@ pub struct GetCommentsResponse {
pub comments: Vec<CommentView>, pub comments: Vec<CommentView>,
} }
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Report a comment.
pub struct CreateCommentReport {
pub comment_id: CommentId,
pub reason: String,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The comment report response.
pub struct CommentReportResponse {
pub comment_report_view: CommentReportView,
}
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Resolve a comment report (only doable by mods).
pub struct ResolveCommentReport {
pub report_id: CommentReportId,
pub resolved: bool,
}
#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// List comment reports.
pub struct ListCommentReports {
#[cfg_attr(feature = "full", ts(optional))]
pub comment_id: Option<CommentId>,
#[cfg_attr(feature = "full", ts(optional))]
pub page: Option<i64>,
#[cfg_attr(feature = "full", ts(optional))]
pub limit: Option<i64>,
/// Only shows the unresolved reports
#[cfg_attr(feature = "full", ts(optional))]
pub unresolved_only: Option<bool>,
/// if no community is given, it returns reports for all communities moderated by the auth user
#[cfg_attr(feature = "full", ts(optional))]
pub community_id: Option<CommunityId>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The comment report list response.
pub struct ListCommentReportsResponse {
pub comment_reports: Vec<CommentReportView>,
}
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)] #[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS))]

View file

@ -11,6 +11,7 @@ pub mod oauth_provider;
pub mod person; pub mod person;
pub mod post; pub mod post;
pub mod private_message; pub mod private_message;
pub mod reports;
#[cfg(feature = "full")] #[cfg(feature = "full")]
pub mod request; pub mod request;
#[cfg(feature = "full")] #[cfg(feature = "full")]

View file

@ -1,10 +1,10 @@
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::{CommentId, CommunityId, DbUrl, LanguageId, PostId, PostReportId}, newtypes::{CommentId, CommunityId, DbUrl, LanguageId, PostId},
ListingType, ListingType,
PostFeatureType, PostFeatureType,
PostSortType, PostSortType,
}; };
use lemmy_db_views::structs::{PaginationCursor, PostReportView, PostView, VoteView}; use lemmy_db_views::structs::{PaginationCursor, PostView, VoteView};
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView}; use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
@ -247,61 +247,6 @@ pub struct SavePost {
pub save: bool, pub save: bool,
} }
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Create a post report.
pub struct CreatePostReport {
pub post_id: PostId,
pub reason: String,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The post report response.
pub struct PostReportResponse {
pub post_report_view: PostReportView,
}
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Resolve a post report (mods only).
pub struct ResolvePostReport {
pub report_id: PostReportId,
pub resolved: bool,
}
#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// List post reports.
pub struct ListPostReports {
#[cfg_attr(feature = "full", ts(optional))]
pub page: Option<i64>,
#[cfg_attr(feature = "full", ts(optional))]
pub limit: Option<i64>,
/// Only shows the unresolved reports
#[cfg_attr(feature = "full", ts(optional))]
pub unresolved_only: Option<bool>,
// TODO make into tagged enum at some point
/// if no community is given, it returns reports for all communities moderated by the auth user
#[cfg_attr(feature = "full", ts(optional))]
pub community_id: Option<CommunityId>,
#[cfg_attr(feature = "full", ts(optional))]
pub post_id: Option<PostId>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The post reports response.
pub struct ListPostReportsResponse {
pub post_reports: Vec<PostReportView>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]

View file

@ -1,5 +1,5 @@
use lemmy_db_schema::newtypes::{PersonId, PrivateMessageId, PrivateMessageReportId}; use lemmy_db_schema::newtypes::{PersonId, PrivateMessageId};
use lemmy_db_views::structs::{PrivateMessageReportView, PrivateMessageView}; use lemmy_db_views::structs::PrivateMessageView;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
#[cfg(feature = "full")] #[cfg(feature = "full")]
@ -72,53 +72,3 @@ pub struct PrivateMessagesResponse {
pub struct PrivateMessageResponse { pub struct PrivateMessageResponse {
pub private_message_view: PrivateMessageView, pub private_message_view: PrivateMessageView,
} }
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Create a report for a private message.
pub struct CreatePrivateMessageReport {
pub private_message_id: PrivateMessageId,
pub reason: String,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// A private message report response.
pub struct PrivateMessageReportResponse {
pub private_message_report_view: PrivateMessageReportView,
}
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Resolve a private message report.
pub struct ResolvePrivateMessageReport {
pub report_id: PrivateMessageReportId,
pub resolved: bool,
}
#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// List private message reports.
// TODO , perhaps GetReports should be a tagged enum list too.
pub struct ListPrivateMessageReports {
#[cfg_attr(feature = "full", ts(optional))]
pub page: Option<i64>,
#[cfg_attr(feature = "full", ts(optional))]
pub limit: Option<i64>,
/// Only shows the unresolved reports
#[cfg_attr(feature = "full", ts(optional))]
pub unresolved_only: Option<bool>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The response for list private message reports.
pub struct ListPrivateMessageReportsResponse {
pub private_message_reports: Vec<PrivateMessageReportView>,
}

View file

@ -0,0 +1,32 @@
use lemmy_db_schema::newtypes::CommunityId;
use lemmy_db_views::structs::ReportCombinedView;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
#[cfg(feature = "full")]
use ts_rs::TS;
#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// List reports.
pub struct ListReports {
#[cfg_attr(feature = "full", ts(optional))]
pub page: Option<i64>,
#[cfg_attr(feature = "full", ts(optional))]
pub limit: Option<i64>,
/// Only shows the unresolved reports
#[cfg_attr(feature = "full", ts(optional))]
pub unresolved_only: Option<bool>,
/// if no community is given, it returns reports for all communities moderated by the auth user
#[cfg_attr(feature = "full", ts(optional))]
pub community_id: Option<CommunityId>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The post reports response.
pub struct ListReportsResponse {
pub reports: Vec<ReportCombinedView>,
}

View file

@ -0,0 +1,60 @@
use lemmy_db_schema::newtypes::{CommentId, CommentReportId, CommunityId};
use lemmy_db_views::structs::CommentReportView;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
#[cfg(feature = "full")]
use ts_rs::TS;
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Report a comment.
pub struct CreateCommentReport {
pub comment_id: CommentId,
pub reason: String,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The comment report response.
pub struct CommentReportResponse {
pub comment_report_view: CommentReportView,
}
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Resolve a comment report (only doable by mods).
pub struct ResolveCommentReport {
pub report_id: CommentReportId,
pub resolved: bool,
}
#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// List comment reports.
pub struct ListCommentReports {
#[cfg_attr(feature = "full", ts(optional))]
pub comment_id: Option<CommentId>,
#[cfg_attr(feature = "full", ts(optional))]
pub page: Option<i64>,
#[cfg_attr(feature = "full", ts(optional))]
pub limit: Option<i64>,
/// Only shows the unresolved reports
#[cfg_attr(feature = "full", ts(optional))]
pub unresolved_only: Option<bool>,
/// if no community is given, it returns reports for all communities moderated by the auth user
#[cfg_attr(feature = "full", ts(optional))]
pub community_id: Option<CommunityId>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The comment report list response.
pub struct ListCommentReportsResponse {
pub comment_reports: Vec<CommentReportView>,
}

View file

@ -0,0 +1,4 @@
pub mod combined;
pub mod comment;
pub mod post;
pub mod private_message;

View file

@ -0,0 +1,61 @@
use lemmy_db_schema::newtypes::{CommunityId, PostId, PostReportId};
use lemmy_db_views::structs::PostReportView;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
#[cfg(feature = "full")]
use ts_rs::TS;
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Create a post report.
pub struct CreatePostReport {
pub post_id: PostId,
pub reason: String,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The post report response.
pub struct PostReportResponse {
pub post_report_view: PostReportView,
}
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Resolve a post report (mods only).
pub struct ResolvePostReport {
pub report_id: PostReportId,
pub resolved: bool,
}
#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// List post reports.
pub struct ListPostReports {
#[cfg_attr(feature = "full", ts(optional))]
pub page: Option<i64>,
#[cfg_attr(feature = "full", ts(optional))]
pub limit: Option<i64>,
/// Only shows the unresolved reports
#[cfg_attr(feature = "full", ts(optional))]
pub unresolved_only: Option<bool>,
// TODO make into tagged enum at some point
/// if no community is given, it returns reports for all communities moderated by the auth user
#[cfg_attr(feature = "full", ts(optional))]
pub community_id: Option<CommunityId>,
#[cfg_attr(feature = "full", ts(optional))]
pub post_id: Option<PostId>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The post reports response.
pub struct ListPostReportsResponse {
pub post_reports: Vec<PostReportView>,
}

View file

@ -0,0 +1,56 @@
use lemmy_db_schema::newtypes::{PrivateMessageId, PrivateMessageReportId};
use lemmy_db_views::structs::PrivateMessageReportView;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
#[cfg(feature = "full")]
use ts_rs::TS;
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Create a report for a private message.
pub struct CreatePrivateMessageReport {
pub private_message_id: PrivateMessageId,
pub reason: String,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// A private message report response.
pub struct PrivateMessageReportResponse {
pub private_message_report_view: PrivateMessageReportView,
}
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Resolve a private message report.
pub struct ResolvePrivateMessageReport {
pub report_id: PrivateMessageReportId,
pub resolved: bool,
}
#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// List private message reports.
// TODO , perhaps GetReports should be a tagged enum list too.
pub struct ListPrivateMessageReports {
#[cfg_attr(feature = "full", ts(optional))]
pub page: Option<i64>,
#[cfg_attr(feature = "full", ts(optional))]
pub limit: Option<i64>,
/// Only shows the unresolved reports
#[cfg_attr(feature = "full", ts(optional))]
pub unresolved_only: Option<bool>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The response for list private message reports.
pub struct ListPrivateMessageReportsResponse {
pub private_message_reports: Vec<PrivateMessageReportView>,
}

View file

@ -862,6 +862,7 @@ diesel::table! {
published -> Timestamptz, published -> Timestamptz,
post_report_id -> Nullable<Int4>, post_report_id -> Nullable<Int4>,
comment_report_id -> Nullable<Int4>, comment_report_id -> Nullable<Int4>,
private_message_report_id -> Nullable<Int4>,
} }
} }
@ -1017,6 +1018,7 @@ diesel::joinable!(registration_application -> local_user (local_user_id));
diesel::joinable!(registration_application -> person (admin_id)); diesel::joinable!(registration_application -> person (admin_id));
diesel::joinable!(report_combined -> comment_report (comment_report_id)); diesel::joinable!(report_combined -> comment_report (comment_report_id));
diesel::joinable!(report_combined -> post_report (post_report_id)); diesel::joinable!(report_combined -> post_report (post_report_id));
diesel::joinable!(report_combined -> private_message_report (private_message_report_id));
diesel::joinable!(site -> instance (instance_id)); diesel::joinable!(site -> instance (instance_id));
diesel::joinable!(site_aggregates -> site (site_id)); diesel::joinable!(site_aggregates -> site (site_id));
diesel::joinable!(site_language -> language (language_id)); diesel::joinable!(site_language -> language (language_id));

View file

@ -1,11 +1,12 @@
use crate::structs::{ use crate::structs::{
CommentReportView,
LocalUserView, LocalUserView,
PostOrCommentReportViewTemp,
PostReportView, PostReportView,
PrivateMessageReportView,
ReportCombinedView, ReportCombinedView,
ReportCombinedViewInternal,
}; };
use diesel::{ use diesel::{
pg::Pg,
result::Error, result::Error,
BoolExpressionMethods, BoolExpressionMethods,
ExpressionMethods, ExpressionMethods,
@ -16,8 +17,11 @@ use diesel::{
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
aliases::{self, creator_community_actions}, aliases::{self, creator_community_actions},
newtypes::{CommunityId, PersonId, PostReportId}, newtypes::{CommunityId, PersonId},
schema::{ schema::{
comment,
comment_actions,
comment_aggregates,
comment_report, comment_report,
community, community,
community_actions, community_actions,
@ -28,25 +32,17 @@ use lemmy_db_schema::{
post_actions, post_actions,
post_aggregates, post_aggregates,
post_report, post_report,
private_message,
private_message_report,
report_combined, report_combined,
}, },
source::community::CommunityFollower, source::community::CommunityFollower,
utils::{ utils::{actions, actions_alias, functions::coalesce, get_conn, limit_and_offset, DbPool},
actions,
actions_alias,
functions::coalesce,
get_conn,
limit_and_offset,
DbConn,
DbPool,
ListFn,
Queries,
ReadFn,
},
}; };
use lemmy_utils::error::LemmyResult; use lemmy_utils::error::LemmyResult;
impl ReportCombinedView { // TODO fix
impl ReportCombinedViewInternal {
/// returns the current unresolved report count for the communities you mod /// returns the current unresolved report count for the communities you mod
pub async fn get_report_count( pub async fn get_report_count(
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
@ -96,140 +92,239 @@ pub struct ReportCombinedQuery {
pub unresolved_only: bool, pub unresolved_only: bool,
} }
// TODO need to add private message
impl ReportCombinedQuery { impl ReportCombinedQuery {
pub async fn list( pub async fn list(
self, self,
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
user: &LocalUserView, user: &LocalUserView,
) -> LemmyResult<Vec<PostOrCommentReportViewTemp>> { ) -> LemmyResult<Vec<ReportCombinedView>> {
let options = self; let options = self;
let my_person_id = user.local_user.person_id;
let item_creator = aliases::person1.field(person::id);
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
// Notes: since the post_report_id and comment_report_id are optional columns,
// many joins must use an OR condition.
// For example, the report creator must be the person table joined to either:
// - post_report.creator_id
// - comment_report.creator_id
let mut query = report_combined::table let mut query = report_combined::table
.left_join(post_report::table) .left_join(post_report::table)
.left_join(comment_report::table) .left_join(comment_report::table)
// .inner_join(post::table) .left_join(private_message_report::table)
// .inner_join(community::table.on(post::community_id.eq(community::id))) // The report creator
.left_join( .inner_join(
person::table.on( person::table.on(
post_report::creator_id post_report::creator_id
.eq(person::id) .eq(person::id)
.or(comment_report::creator_id.eq(person::id)), .or(comment_report::creator_id.eq(person::id))
.or(private_message_report::creator_id.eq(person::id)),
), ),
) )
// .inner_join(aliases::person1.on(post::creator_id.eq(aliases::person1.field(person::id)))) // The comment
// .left_join(actions_alias( .left_join(comment::table.on(comment_report::comment_id.eq(comment::id)))
// creator_community_actions, // The private message
// post::creator_id, .left_join(
// post::community_id, private_message::table
// )) .on(private_message_report::private_message_id.eq(private_message::id)),
// .left_join(actions( )
// community_actions::table, // The post
// Some(my_person_id), .left_join(
// post::community_id, post::table.on(
// )) post_report::post_id
// .left_join( .eq(post::id)
// local_user::table.on( .or(comment::post_id.eq(post::id)),
// post::creator_id ),
// .eq(local_user::person_id) )
// .and(local_user::admin.eq(true)), // The item creator
// ), // You can now use aliases::person1.field(person::id) / item_creator for all the item actions
// ) .inner_join(
// .left_join(actions(post_actions::table, Some(my_person_id), post::id)) aliases::person1.on(
// .left_join(actions( post::creator_id
// person_actions::table, .eq(item_creator)
// Some(my_person_id), .or(comment::creator_id.eq(item_creator))
// post::creator_id, .or(private_message::creator_id.eq(item_creator)),
// )) ),
// .inner_join(post_aggregates::table.on(post_report::post_id.eq(post_aggregates::post_id))) )
// .left_join( // The community
// aliases::person2 .left_join(community::table.on(post::community_id.eq(community::id)))
// .on(post_report::resolver_id.eq(aliases::person2.field(person::id).nullable())), .left_join(actions_alias(
// ) creator_community_actions,
item_creator,
post::community_id,
))
.left_join(
local_user::table.on(
item_creator
.eq(local_user::person_id)
.and(local_user::admin.eq(true)),
),
)
.left_join(actions(
community_actions::table,
Some(my_person_id),
post::community_id,
))
.left_join(actions(post_actions::table, Some(my_person_id), post::id))
.left_join(actions(
person_actions::table,
Some(my_person_id),
item_creator,
))
.left_join(post_aggregates::table.on(post_report::post_id.eq(post_aggregates::post_id)))
.left_join(
comment_aggregates::table.on(comment_report::comment_id.eq(comment_aggregates::comment_id)),
)
.left_join(aliases::person2.on(item_creator.eq(aliases::person2.field(person::id))))
.left_join(actions(
comment_actions::table,
Some(my_person_id),
comment_report::comment_id,
))
.select(( .select((
// Post-specific
post_report::all_columns.nullable(), post_report::all_columns.nullable(),
post::all_columns.nullable(),
post_aggregates::all_columns.nullable(),
coalesce(
post_aggregates::comments.nullable() - post_actions::read_comments_amount.nullable(),
post_aggregates::comments,
)
.nullable(),
post_actions::saved.nullable().is_not_null(),
post_actions::read.nullable().is_not_null(),
post_actions::hidden.nullable().is_not_null(),
post_actions::like_score.nullable(),
// Comment-specific
comment_report::all_columns.nullable(), comment_report::all_columns.nullable(),
// post::all_columns, comment::all_columns.nullable(),
// community::all_columns, comment_aggregates::all_columns.nullable(),
person::all_columns.nullable(), comment_actions::saved.nullable().is_not_null(),
// aliases::person1.fields(person::all_columns), comment_actions::like_score.nullable(),
// creator_community_actions // Private-message-specific
// .field(community_actions::received_ban) private_message_report::all_columns.nullable(),
// .nullable() private_message::all_columns.nullable(),
// .is_not_null(), // Shared
// creator_community_actions person::all_columns,
// .field(community_actions::became_moderator) aliases::person1.fields(person::all_columns),
// .nullable() community::all_columns.nullable(),
// .is_not_null(), CommunityFollower::select_subscribed_type(),
// local_user::admin.nullable().is_not_null(), aliases::person2.fields(person::all_columns.nullable()),
// CommunityFollower::select_subscribed_type(), local_user::admin.nullable().is_not_null(),
// post_actions::saved.nullable().is_not_null(), creator_community_actions
// post_actions::read.nullable().is_not_null(), .field(community_actions::received_ban)
// post_actions::hidden.nullable().is_not_null(), .nullable()
// person_actions::blocked.nullable().is_not_null(), .is_not_null(),
// post_actions::like_score.nullable(), creator_community_actions
// coalesce( .field(community_actions::became_moderator)
// post_aggregates::comments.nullable() - post_actions::read_comments_amount.nullable(), .nullable()
// post_aggregates::comments, .is_not_null(),
// ), person_actions::blocked.nullable().is_not_null(),
// post_aggregates::all_columns,
// aliases::person2.fields(person::all_columns.nullable()),
)) ))
.into_boxed(); .into_boxed();
// if let Some(community_id) = options.community_id { if let Some(community_id) = options.community_id {
// query = query.filter(post::community_id.eq(community_id)); query = query.filter(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 // If viewing all reports, order by newest, but if viewing unresolved only, show the oldest
// first (FIFO) // first (FIFO)
// if options.unresolved_only { if options.unresolved_only {
// query = query query = query
// .filter(post_report::resolved.eq(false)) .filter(post_report::resolved.eq(false))
// .order_by(post_report::published.asc()); .or_filter(comment_report::resolved.eq(false))
// } else { .or_filter(private_message_report::resolved.eq(false))
// query = query.order_by(post_report::published.desc()); .order_by(report_combined::published.asc());
// } } else {
query = query.order_by(report_combined::published.desc());
}
// If its not an admin, get only the ones you mod // If its not an admin, get only the ones you mod
// if !user.local_user.admin { if !user.local_user.admin {
// query = query.filter(community_actions::became_moderator.is_not_null()); query = query.filter(community_actions::became_moderator.is_not_null());
// } }
let (limit, offset) = limit_and_offset(options.page, options.limit)?; let (limit, offset) = limit_and_offset(options.page, options.limit)?;
query = query.limit(limit).offset(offset); query = query.limit(limit).offset(offset);
let res = query.load::<ReportCombinedView>(conn).await?; let res = query.load::<ReportCombinedViewInternal>(conn).await?;
let out = res
.iter() // Map the query results to the enum
.filter_map(map_to_post_or_comment_view_tmp) let out = res.into_iter().filter_map(map_to_enum).collect();
.collect();
Ok(out) Ok(out)
} }
} }
fn map_to_post_or_comment_view_tmp( /// Maps the combined DB row to an enum
view: &ReportCombinedView, fn map_to_enum(view: ReportCombinedViewInternal) -> Option<ReportCombinedView> {
) -> Option<PostOrCommentReportViewTemp> { // Use for a short alias
// If it has post_report, you know the other fields are defined let v = view;
if let (Some(post_report), Some(post_creator)) = (view.post_report.clone(), view.creator.clone())
{ if let (Some(post_report), Some(post), Some(community), Some(unread_comments), Some(counts)) = (
Some(PostOrCommentReportViewTemp::Post { v.post_report,
v.post.clone(),
v.community.clone(),
v.post_unread_comments,
v.post_counts,
) {
Some(ReportCombinedView::Post(PostReportView {
post_report, post_report,
post_creator, post,
}) community,
} else if let (Some(comment_report), Some(comment_creator)) = unread_comments,
(view.comment_report.clone(), view.creator.clone()) counts,
{ creator: v.report_creator,
Some(PostOrCommentReportViewTemp::Comment { post_creator: v.item_creator,
creator_banned_from_community: v.item_creator_banned_from_community,
creator_is_moderator: v.item_creator_is_moderator,
creator_is_admin: v.item_creator_is_admin,
creator_blocked: v.item_creator_blocked,
subscribed: v.subscribed,
saved: v.post_saved,
read: v.post_read,
hidden: v.post_hidden,
my_vote: v.my_post_vote,
resolver: v.resolver,
}))
} else if let (Some(comment_report), Some(comment), Some(counts), Some(post), Some(community)) = (
v.comment_report,
v.comment,
v.comment_counts,
v.post.clone(),
v.community.clone(),
) {
Some(ReportCombinedView::Comment(CommentReportView {
comment_report, comment_report,
comment_creator, comment,
}) counts,
post,
community,
creator: v.report_creator,
comment_creator: v.item_creator,
creator_banned_from_community: v.item_creator_banned_from_community,
creator_is_moderator: v.item_creator_is_moderator,
creator_is_admin: v.item_creator_is_admin,
creator_blocked: v.item_creator_blocked,
subscribed: v.subscribed,
saved: v.comment_saved,
my_vote: v.my_comment_vote,
resolver: v.resolver,
}))
} else if let (Some(private_message_report), Some(private_message)) =
(v.private_message_report, v.private_message)
{
Some(ReportCombinedView::PrivateMessage(
PrivateMessageReportView {
private_message_report,
private_message,
creator: v.report_creator,
private_message_creator: v.item_creator,
resolver: v.resolver,
},
))
} else { } else {
None None
} }

View file

@ -237,56 +237,47 @@ pub struct LocalImageView {
pub local_image: LocalImage, pub local_image: LocalImage,
pub person: Person, pub person: Person,
} }
#[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS, Queryable))] #[cfg_attr(feature = "full", derive(Queryable))]
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] #[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
// TODO TS shouldn't be necessary here, since this shouldn't be used externally
#[cfg_attr(feature = "full", ts(export))]
/// A combined report view /// A combined report view
pub struct ReportCombinedView { pub struct ReportCombinedViewInternal {
// Post-specific // Post-specific
pub post_report: Option<PostReport>, pub post_report: Option<PostReport>,
// pub post_creator: Person, pub post: Option<Post>,
// pub unread_comments: i64, pub post_counts: Option<PostAggregates>,
// pub post_counts: PostAggregates, pub post_unread_comments: Option<i64>,
// #[cfg_attr(feature = "full", ts(optional))] pub post_saved: bool,
// pub resolver: Option<Person>, pub post_read: bool,
pub post_hidden: bool,
pub my_post_vote: Option<i16>,
// Comment-specific // Comment-specific
pub comment_report: Option<CommentReport>, pub comment_report: Option<CommentReport>,
// pub comment_creator: Person, pub comment: Option<Comment>,
// pub comment: Comment, pub comment_counts: Option<CommentAggregates>,
// pub comment_counts: CommentAggregates, pub comment_saved: bool,
// Shared pub my_comment_vote: Option<i16>,
// pub post: Post, // Private-message-specific
// pub community: Community, pub private_message_report: Option<PrivateMessageReport>,
// pub creator: Person, pub private_message: Option<PrivateMessage>,
// pub creator_banned_from_community: bool, // // Shared
// pub creator_is_moderator: bool, pub report_creator: Person,
// pub creator_is_admin: bool, pub item_creator: Person,
// pub subscribed: SubscribedType, pub community: Option<Community>,
// pub saved: bool, pub subscribed: SubscribedType,
// pub read: bool, pub resolver: Option<Person>,
// pub hidden: bool, pub item_creator_is_admin: bool,
// pub creator_blocked: bool, pub item_creator_banned_from_community: bool,
// #[cfg_attr(feature = "full", ts(optional))] pub item_creator_is_moderator: bool,
// pub my_vote: Option<i16>, pub item_creator_blocked: bool,
// ---
pub creator: Option<Person>,
} }
pub enum PostOrCommentReportView { #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
pub enum ReportCombinedView {
Post(PostReportView), Post(PostReportView),
Comment(CommentReportView), Comment(CommentReportView),
} PrivateMessage(PrivateMessageReportView),
pub enum PostOrCommentReportViewTemp {
Post {
post_report: PostReport,
post_creator: Person,
},
Comment {
comment_report: CommentReport,
comment_creator: Person,
},
} }

View file

@ -1 +1,2 @@
DROP TABLE report_combined; DROP TABLE report_combined;

View file

@ -1,14 +1,13 @@
CREATE TABLE report_combined ( CREATE TABLE report_combined (
id serial PRIMARY KEY, id serial PRIMARY KEY,
published timestamptz not null, published timestamptz NOT NULL,
post_report_id int REFERENCES post_report ON UPDATE CASCADE ON DELETE CASCADE, post_report_id int REFERENCES post_report ON UPDATE CASCADE ON DELETE CASCADE,
comment_report_id int REFERENCES comment_report ON UPDATE CASCADE ON DELETE CASCADE, comment_report_id int REFERENCES comment_report ON UPDATE CASCADE ON DELETE CASCADE,
UNIQUE (post_report_id, comment_report_id) private_message_report_id int REFERENCES private_message_report ON UPDATE CASCADE ON DELETE CASCADE,
UNIQUE (post_report_id, comment_report_id, private_message_report_id)
); );
CREATE INDEX idx_report_combined_published on report_combined (published desc); CREATE INDEX idx_report_combined_published ON report_combined (published DESC);
-- TODO do history update -- TODO do history update
-- TODO do triggers in replaceable schema -- TODO do triggers in replaceable schema

View file

@ -6,11 +6,6 @@ use lemmy_api::{
list_comment_likes::list_comment_likes, list_comment_likes::list_comment_likes,
save::save_comment, save::save_comment,
}, },
comment_report::{
create::create_comment_report,
list::list_comment_reports,
resolve::resolve_comment_report,
},
community::{ community::{
add_mod::add_mod_to_community, add_mod::add_mod_to_community,
ban::ban_from_community, ban::ban_from_community,
@ -64,17 +59,25 @@ use lemmy_api::{
mark_read::mark_post_as_read, mark_read::mark_post_as_read,
save::save_post, save::save_post,
}, },
private_message::mark_read::mark_pm_as_read,
reports::{
comment_report::{
create::create_comment_report,
list::list_comment_reports,
resolve::resolve_comment_report,
},
post_report::{ post_report::{
create::create_post_report, create::create_post_report,
list::list_post_reports, list::list_post_reports,
resolve::resolve_post_report, resolve::resolve_post_report,
}, },
private_message::mark_read::mark_pm_as_read,
private_message_report::{ private_message_report::{
create::create_pm_report, create::create_pm_report,
list::list_pm_reports, list::list_pm_reports,
resolve::resolve_pm_report, resolve::resolve_pm_report,
}, },
report_combined::list::list_reports,
},
site::{ site::{
block::block_instance, block::block_instance,
federated_instances::get_federated_instances, federated_instances::get_federated_instances,
@ -248,6 +251,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
.route("/like", web::post().to(like_post)) .route("/like", web::post().to(like_post))
.route("/like/list", web::get().to(list_post_likes)) .route("/like/list", web::get().to(list_post_likes))
.route("/save", web::put().to(save_post)) .route("/save", web::put().to(save_post))
// TODO should these be moved into the new report heading?
.route("/report", web::post().to(create_post_report)) .route("/report", web::post().to(create_post_report))
.route("/report/resolve", web::put().to(resolve_post_report)) .route("/report/resolve", web::put().to(resolve_post_report))
.route("/report/list", web::get().to(list_post_reports)) .route("/report/list", web::get().to(list_post_reports))
@ -274,10 +278,16 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
.route("/like/list", web::get().to(list_comment_likes)) .route("/like/list", web::get().to(list_comment_likes))
.route("/save", web::put().to(save_comment)) .route("/save", web::put().to(save_comment))
.route("/list", web::get().to(list_comments)) .route("/list", web::get().to(list_comments))
// TODO should these be moved into the new report heading?
.route("/report", web::post().to(create_comment_report)) .route("/report", web::post().to(create_comment_report))
.route("/report/resolve", web::put().to(resolve_comment_report)) .route("/report/resolve", web::put().to(resolve_comment_report))
.route("/report/list", web::get().to(list_comment_reports)), .route("/report/list", web::get().to(list_comment_reports)),
) )
.service(
web::scope("report")
.wrap(rate_limit.message())
.route("/list", web::get().to(list_reports)),
)
// Private Message // Private Message
.service( .service(
web::scope("/private_message") web::scope("/private_message")
@ -287,6 +297,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
.route("", web::put().to(update_private_message)) .route("", web::put().to(update_private_message))
.route("/delete", web::post().to(delete_private_message)) .route("/delete", web::post().to(delete_private_message))
.route("/mark_as_read", web::post().to(mark_pm_as_read)) .route("/mark_as_read", web::post().to(mark_pm_as_read))
// TODO should these be moved into the new report heading?
.route("/report", web::post().to(create_pm_report)) .route("/report", web::post().to(create_pm_report))
.route("/report/resolve", web::put().to(resolve_pm_report)) .route("/report/resolve", web::put().to(resolve_pm_report))
.route("/report/list", web::get().to(list_pm_reports)), .route("/report/list", web::get().to(list_pm_reports)),