mirror of https://github.com/LemmyNet/lemmy.git
make sure post wasn't deleted or removed.
parent
e30170c432
commit
ec9e3598d3
|
@ -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(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -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?;
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue