From 6cf4e39406b3bce863ec114a7a2355d204facd23 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 1 Dec 2020 17:41:01 +0100 Subject: [PATCH] Move check for locked post into Comment::from_apub() --- lemmy_apub/src/activities/receive/comment.rs | 6 +----- lemmy_apub/src/objects/comment.rs | 8 +++++++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lemmy_apub/src/activities/receive/comment.rs b/lemmy_apub/src/activities/receive/comment.rs index 6f6a22da..da29a3b7 100644 --- a/lemmy_apub/src/activities/receive/comment.rs +++ b/lemmy_apub/src/activities/receive/comment.rs @@ -3,7 +3,7 @@ use activitystreams::{ activity::{ActorAndObjectRefExt, Create, Dislike, Like, Remove, Update}, base::ExtendsExt, }; -use anyhow::{anyhow, Context}; +use anyhow::Context; use lemmy_db::{ comment::{Comment, CommentLike, CommentLikeForm}, 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!())?)? .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 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()); - } // Note: // Although mentions could be gotten from the post tags (they are included there), or the ccs, diff --git a/lemmy_apub/src/objects/comment.rs b/lemmy_apub/src/objects/comment.rs index b92411e7..1454a738 100644 --- a/lemmy_apub/src/objects/comment.rs +++ b/lemmy_apub/src/objects/comment.rs @@ -20,7 +20,7 @@ use activitystreams::{ object::{kind::NoteType, ApObject, Note, Tombstone}, prelude::*, }; -use anyhow::Context; +use anyhow::{anyhow, Context}; use lemmy_db::{ comment::{Comment, CommentForm}, community::Community, @@ -114,6 +114,12 @@ impl FromApub for Comment { } else { let comment_form = 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| { Comment::upsert(conn, &comment_form) })