Move check for locked post into Comment::from_apub()
This commit is contained in:
parent
9629f8140b
commit
6cf4e39406
|
@ -3,7 +3,7 @@ use activitystreams::{
|
||||||
activity::{ActorAndObjectRefExt, Create, Dislike, Like, Remove, Update},
|
activity::{ActorAndObjectRefExt, Create, Dislike, Like, Remove, Update},
|
||||||
base::ExtendsExt,
|
base::ExtendsExt,
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, Context};
|
use anyhow::Context;
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
comment::{Comment, CommentLike, CommentLikeForm},
|
comment::{Comment, CommentLike, CommentLikeForm},
|
||||||
comment_view::CommentView,
|
comment_view::CommentView,
|
||||||
|
@ -23,14 +23,10 @@ pub(crate) async fn receive_create_comment(
|
||||||
let note = NoteExt::from_any_base(create.object().to_owned().one().context(location_info!())?)?
|
let note = NoteExt::from_any_base(create.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
// TODO: need to do the check for locked post before calling this
|
|
||||||
let comment = Comment::from_apub(¬e, context, Some(user.actor_id()?), request_counter).await?;
|
let comment = Comment::from_apub(¬e, context, Some(user.actor_id()?), request_counter).await?;
|
||||||
|
|
||||||
let post_id = comment.post_id;
|
let post_id = comment.post_id;
|
||||||
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
|
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
|
||||||
if post.locked {
|
|
||||||
return Err(anyhow!("Post is locked").into());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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,
|
||||||
|
|
|
@ -20,7 +20,7 @@ use activitystreams::{
|
||||||
object::{kind::NoteType, ApObject, Note, Tombstone},
|
object::{kind::NoteType, ApObject, Note, Tombstone},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
use anyhow::Context;
|
use anyhow::{anyhow, Context};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
comment::{Comment, CommentForm},
|
comment::{Comment, CommentForm},
|
||||||
community::Community,
|
community::Community,
|
||||||
|
@ -114,6 +114,12 @@ impl FromApub for Comment {
|
||||||
} else {
|
} else {
|
||||||
let comment_form =
|
let comment_form =
|
||||||
CommentForm::from_apub(note, context, expected_domain, request_counter).await?;
|
CommentForm::from_apub(note, context, expected_domain, request_counter).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 New Issue