diff --git a/crates/api/src/comment_report/create.rs b/crates/api/src/comment_report/create.rs index 51f972b57..f8075460f 100644 --- a/crates/api/src/comment_report/create.rs +++ b/crates/api/src/comment_report/create.rs @@ -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, diff --git a/crates/api/src/post_report/create.rs b/crates/api/src/post_report/create.rs index 0840cfee4..cda283af1 100644 --- a/crates/api/src/post_report/create.rs +++ b/crates/api/src/post_report/create.rs @@ -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, diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index 55df7a6ec..85821a834 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -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(