]> Untitled Git - lemmy.git/commitdiff
Dont include community in comment `to` field (fixes #1446)
authorFelix Ableitner <me@nutomic.com>
Tue, 23 Feb 2021 18:00:47 +0000 (19:00 +0100)
committerFelix Ableitner <me@nutomic.com>
Tue, 23 Feb 2021 18:00:47 +0000 (19:00 +0100)
crates/apub/src/inbox/community_inbox.rs
crates/apub/src/objects/comment.rs
crates/apub/src/objects/mod.rs
crates/apub/src/objects/post.rs

index 45e7ab43cc2bfce4de833323770098a47934b2ba..f9056a770b2777c10e68660e25728da1a5f09348 100644 (file)
@@ -120,7 +120,7 @@ pub(crate) async fn community_receive_message(
     User_::read_from_apub_id(&conn, &actor_id.into())
   })
   .await??;
-  check_community_or_site_ban(&user, &to_community, context.pool()).await?;
+  check_community_or_site_ban(&user, to_community.id, context.pool()).await?;
 
   let any_base = activity.clone().into_any_base()?;
   let actor_url = actor.actor_id();
@@ -261,14 +261,13 @@ async fn handle_undo_follow(
 
 pub(crate) async fn check_community_or_site_ban(
   user: &User_,
-  community: &Community,
+  community_id: i32,
   pool: &DbPool,
 ) -> Result<(), LemmyError> {
   if user.banned {
     return Err(anyhow!("User is banned from site").into());
   }
   let user_id = user.id;
-  let community_id = community.id;
   let is_banned = move |conn: &'_ _| CommunityUserBanView::get(conn, user_id, community_id).is_ok();
   if blocking(pool, is_banned).await? {
     return Err(anyhow!("User is banned from community").into());
index beebe833269fb52e26645cf146db45b3f8909b5d..8452f3787304676b9a68591171b62ce7c201cf5d 100644 (file)
@@ -24,7 +24,6 @@ use anyhow::{anyhow, Context};
 use lemmy_db_queries::{Crud, DbPool};
 use lemmy_db_schema::source::{
   comment::{Comment, CommentForm},
-  community::Community,
   post::Post,
   user::User_,
 };
@@ -50,9 +49,6 @@ impl ToApub for Comment {
     let post_id = self.post_id;
     let post = blocking(pool, move |conn| Post::read(conn, post_id)).await??;
 
-    let community_id = post.community_id;
-    let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
-
     // Add a vector containing some important info to the "in_reply_to" field
     // [post_ap_id, Option(parent_comment_ap_id)]
     let mut in_reply_to_vec = vec![post.ap_id.into_inner()];
@@ -68,7 +64,7 @@ impl ToApub for Comment {
       .set_many_contexts(lemmy_context()?)
       .set_id(self.ap_id.to_owned().into_inner())
       .set_published(convert_datetime(self.published))
-      .set_many_tos(vec![community.actor_id.into_inner(), public()])
+      .set_to(public())
       .set_many_in_reply_tos(in_reply_to_vec)
       .set_attributed_to(creator.actor_id.into_inner());
 
@@ -104,13 +100,13 @@ impl FromApub for Comment {
     expected_domain: Url,
     request_counter: &mut i32,
   ) -> Result<Comment, LemmyError> {
-    check_object_for_community_or_site_ban(note, context, request_counter).await?;
-
     let comment: Comment =
       get_object_from_apub(note, context, expected_domain, request_counter).await?;
 
     let post_id = comment.post_id;
     let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
+    check_object_for_community_or_site_ban(note, post.community_id, context, request_counter)
+      .await?;
     if post.locked {
       // This is not very efficient because a comment gets inserted just to be deleted right
       // afterwards, but it seems to be the easiest way to implement it.
index bf0ac24cbd14c2028b94cb7bdae93f08d4a37260..79b9ad405ef6bd5f8002a8d3bde7c10995d38465 100644 (file)
@@ -207,6 +207,7 @@ where
 
 pub(in crate::objects) async fn check_object_for_community_or_site_ban<T, Kind>(
   object: &T,
+  community_id: i32,
   context: &LemmyContext,
   request_counter: &mut i32,
 ) -> Result<(), LemmyError>
@@ -219,8 +220,7 @@ where
     .as_single_xsd_any_uri()
     .context(location_info!())?;
   let user = get_or_fetch_and_upsert_user(user_id, context, request_counter).await?;
-  let community = get_to_community(object, context, request_counter).await?;
-  check_community_or_site_ban(&user, &community, context.pool()).await
+  check_community_or_site_ban(&user, community_id, context.pool()).await
 }
 
 pub(in crate::objects) async fn get_to_community<T, Kind>(
index d3d9dfb8bf7d34544fb411eae2516af4e1d13be7..2cac67ea494d0156f87fd84297e6d7b679b340bd 100644 (file)
@@ -118,8 +118,10 @@ impl FromApub for Post {
     expected_domain: Url,
     request_counter: &mut i32,
   ) -> Result<Post, LemmyError> {
-    check_object_for_community_or_site_ban(page, context, request_counter).await?;
-    get_object_from_apub(page, context, expected_domain, request_counter).await
+    let post: Post = get_object_from_apub(page, context, expected_domain, request_counter).await?;
+    check_object_for_community_or_site_ban(page, post.community_id, context, request_counter)
+      .await?;
+    Ok(post)
   }
 }