mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-15 00:43:59 +00:00
Enforce post lock in federation inbox
This commit is contained in:
parent
8803e7834f
commit
3b4c3ec074
2 changed files with 13 additions and 4 deletions
|
@ -9,7 +9,7 @@ use activitystreams::{
|
||||||
base::ExtendsExt,
|
base::ExtendsExt,
|
||||||
object::Note,
|
object::Note,
|
||||||
};
|
};
|
||||||
use anyhow::Context;
|
use anyhow::{anyhow, Context};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
|
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
|
||||||
comment_view::CommentView,
|
comment_view::CommentView,
|
||||||
|
@ -33,12 +33,15 @@ pub(crate) async fn receive_create_comment(
|
||||||
let comment =
|
let comment =
|
||||||
CommentForm::from_apub(¬e, context, Some(user.actor_id()?), request_counter).await?;
|
CommentForm::from_apub(¬e, context, Some(user.actor_id()?), request_counter).await?;
|
||||||
|
|
||||||
|
let post_id = comment.post_id;
|
||||||
|
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
|
||||||
|
if post.locked {
|
||||||
|
return Err(anyhow!("Post is locked").into());
|
||||||
|
}
|
||||||
|
|
||||||
let inserted_comment =
|
let inserted_comment =
|
||||||
blocking(context.pool(), move |conn| Comment::upsert(conn, &comment)).await??;
|
blocking(context.pool(), move |conn| Comment::upsert(conn, &comment)).await??;
|
||||||
|
|
||||||
let post_id = inserted_comment.post_id;
|
|
||||||
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
|
|
||||||
|
|
||||||
// Note:
|
// Note:
|
||||||
// Although mentions could be gotten from the post tags (they are included there), or the ccs,
|
// Although mentions could be gotten from the post tags (they are included there), or the ccs,
|
||||||
// Its much easier to scrape them from the comment body, since the API has to do that
|
// Its much easier to scrape them from the comment body, since the API has to do that
|
||||||
|
|
|
@ -497,6 +497,12 @@ pub(crate) async fn get_or_fetch_and_insert_comment(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
let post_id = comment_form.post_id;
|
||||||
|
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
|
||||||
|
if post.locked {
|
||||||
|
return Err(anyhow!("Post is locked").into());
|
||||||
|
}
|
||||||
|
|
||||||
let comment = blocking(context.pool(), move |conn| {
|
let comment = blocking(context.pool(), move |conn| {
|
||||||
Comment::upsert(conn, &comment_form)
|
Comment::upsert(conn, &comment_form)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue