make sure post wasn't deleted or removed.

dont_allow_posts_to_deleted_or_removed_communities
Dessalines 2021-10-13 21:57:20 -04:00
parent e30170c432
commit ec9e3598d3
3 changed files with 14 additions and 2 deletions

View File

@ -363,9 +363,17 @@ pub async fn check_community_deleted_or_removed(
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let community = blocking(pool, move |conn| Community::read(conn, community_id)) let community = blocking(pool, move |conn| Community::read(conn, community_id))
.await? .await?
.map_err(|_| ApiError::err("couldnt_find_community"))?; .map_err(|e| ApiError::err("couldnt_find_community", e))?;
if community.deleted || community.removed { if community.deleted || community.removed {
Err(ApiError::err("deleted").into()) Err(ApiError::err_plain("deleted").into())
} else {
Ok(())
}
}
pub fn check_post_deleted_or_removed(post: &Post) -> Result<(), LemmyError> {
if post.deleted || post.removed {
Err(ApiError::err_plain("deleted").into())
} else { } else {
Ok(()) Ok(())
} }

View File

@ -5,6 +5,7 @@ use lemmy_api_common::{
check_community_ban, check_community_ban,
check_community_deleted_or_removed, check_community_deleted_or_removed,
check_person_block, check_person_block,
check_post_deleted_or_removed,
comment::*, comment::*,
get_local_user_view_from_jwt, get_local_user_view_from_jwt,
get_post, get_post,
@ -58,6 +59,7 @@ impl PerformCrud for CreateComment {
check_community_ban(local_user_view.person.id, community_id, context.pool()).await?; check_community_ban(local_user_view.person.id, community_id, context.pool()).await?;
check_community_deleted_or_removed(community_id, context.pool()).await?; check_community_deleted_or_removed(community_id, context.pool()).await?;
check_post_deleted_or_removed(&post)?;
check_person_block(local_user_view.person.id, post.creator_id, context.pool()).await?; check_person_block(local_user_view.person.id, post.creator_id, context.pool()).await?;

View File

@ -4,6 +4,7 @@ use lemmy_api_common::{
blocking, blocking,
check_community_ban, check_community_ban,
check_community_deleted_or_removed, check_community_deleted_or_removed,
check_post_deleted_or_removed,
comment::*, comment::*,
get_local_user_view_from_jwt, get_local_user_view_from_jwt,
send_local_notifs, send_local_notifs,
@ -50,6 +51,7 @@ impl PerformCrud for EditComment {
) )
.await?; .await?;
check_community_deleted_or_removed(orig_comment.community.id, context.pool()).await?; check_community_deleted_or_removed(orig_comment.community.id, context.pool()).await?;
check_post_deleted_or_removed(&orig_comment.post)?;
// Verify that only the creator can edit // Verify that only the creator can edit
if local_user_view.person.id != orig_comment.creator.id { if local_user_view.person.id != orig_comment.creator.id {