Dont allow creating reports for deleted / removed items.

auto_resolve_reports_1
Dessalines 2024-01-25 10:24:42 -05:00
parent e3511e3e26
commit 946a21752f
3 changed files with 24 additions and 2 deletions

View File

@ -5,7 +5,11 @@ use lemmy_api_common::{
comment::{CommentReportResponse, CreateCommentReport},
context::LemmyContext,
send_activity::{ActivityChannel, SendActivityData},
utils::{check_community_user_action, send_new_report_email_to_admins},
utils::{
check_comment_deleted_or_removed,
check_community_user_action,
send_new_report_email_to_admins,
},
};
use lemmy_db_schema::{
source::{
@ -40,6 +44,9 @@ pub async fn create_comment_report(
)
.await?;
// Don't allow creating reports for removed / deleted comments
check_comment_deleted_or_removed(&comment_view.comment)?;
let report_form = CommentReportForm {
creator_id: person_id,
comment_id,

View File

@ -5,7 +5,11 @@ use lemmy_api_common::{
context::LemmyContext,
post::{CreatePostReport, PostReportResponse},
send_activity::{ActivityChannel, SendActivityData},
utils::{check_community_user_action, send_new_report_email_to_admins},
utils::{
check_community_user_action,
check_post_deleted_or_removed,
send_new_report_email_to_admins,
},
};
use lemmy_db_schema::{
source::{
@ -40,6 +44,9 @@ pub async fn create_post_report(
)
.await?;
// Don't allow creating reports for removed / deleted posts
check_post_deleted_or_removed(&post_view.post)?;
let report_form = PostReportForm {
creator_id: person_id,
post_id,

View File

@ -233,6 +233,14 @@ pub fn check_post_deleted_or_removed(post: &Post) -> Result<(), LemmyError> {
}
}
pub fn check_comment_deleted_or_removed(comment: &Comment) -> Result<(), LemmyError> {
if comment.deleted || comment.removed {
Err(LemmyErrorType::Deleted)?
} else {
Ok(())
}
}
/// Throws an error if a recipient has blocked a person.
#[tracing::instrument(skip_all)]
pub async fn check_person_block(