diff --git a/lemmy_apub/src/inbox/community_inbox.rs b/lemmy_apub/src/inbox/community_inbox.rs index 6acdfa0d..ad6eaffb 100644 --- a/lemmy_apub/src/inbox/community_inbox.rs +++ b/lemmy_apub/src/inbox/community_inbox.rs @@ -259,7 +259,7 @@ async fn handle_undo_follow( Ok(()) } -async fn check_community_or_site_ban( +pub(crate) async fn check_community_or_site_ban( user: &User_, community: &Community, pool: &DbPool, diff --git a/lemmy_apub/src/objects/comment.rs b/lemmy_apub/src/objects/comment.rs index 6d293394..9ff63cbd 100644 --- a/lemmy_apub/src/objects/comment.rs +++ b/lemmy_apub/src/objects/comment.rs @@ -7,6 +7,7 @@ use crate::{ }, objects::{ check_object_domain, + check_object_for_community_or_site_ban, create_tombstone, get_object_from_apub, get_source_markdown_value, @@ -101,6 +102,8 @@ impl FromApub for Comment { expected_domain: Option, request_counter: &mut i32, ) -> Result { + 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?; diff --git a/lemmy_apub/src/objects/mod.rs b/lemmy_apub/src/objects/mod.rs index 6a017505..f7db59c7 100644 --- a/lemmy_apub/src/objects/mod.rs +++ b/lemmy_apub/src/objects/mod.rs @@ -1,4 +1,8 @@ -use crate::check_is_apub_id_valid; +use crate::{ + check_is_apub_id_valid, + fetcher::{get_or_fetch_and_upsert_community, get_or_fetch_and_upsert_user}, + inbox::community_inbox::check_community_or_site_ban, +}; use activitystreams::{ base::{AsBase, BaseExt, ExtendsExt}, markers::Base, @@ -205,3 +209,26 @@ where Ok(to) } } + +pub(in crate::objects) async fn check_object_for_community_or_site_ban( + object: &T, + context: &LemmyContext, + request_counter: &mut i32, +) -> Result<(), LemmyError> +where + T: ObjectExt, +{ + let user_id = object + .attributed_to() + .context(location_info!())? + .as_single_xsd_any_uri() + .context(location_info!())?; + let user = get_or_fetch_and_upsert_user(user_id, context, request_counter).await?; + let community_id = object + .to() + .context(location_info!())? + .as_single_xsd_any_uri() + .context(location_info!())?; + let community = get_or_fetch_and_upsert_community(community_id, context, request_counter).await?; + check_community_or_site_ban(&user, &community, context.pool()).await +} diff --git a/lemmy_apub/src/objects/post.rs b/lemmy_apub/src/objects/post.rs index 9c68c1c9..3ca8650d 100644 --- a/lemmy_apub/src/objects/post.rs +++ b/lemmy_apub/src/objects/post.rs @@ -3,6 +3,7 @@ use crate::{ fetcher::{get_or_fetch_and_upsert_community, get_or_fetch_and_upsert_user}, objects::{ check_object_domain, + check_object_for_community_or_site_ban, create_tombstone, get_object_from_apub, get_source_markdown_value, @@ -112,6 +113,7 @@ impl FromApub for Post { expected_domain: Option, request_counter: &mut i32, ) -> Result { + check_object_for_community_or_site_ban(page, context, request_counter).await?; get_object_from_apub(page, context, expected_domain, request_counter).await } }