]> Untitled Git - lemmy.git/commitdiff
Split lemmy_apub crate into two parts apub and apub_receive
authorFelix Ableitner <me@nutomic.com>
Tue, 30 Mar 2021 20:23:50 +0000 (22:23 +0200)
committerFelix Ableitner <me@nutomic.com>
Tue, 30 Mar 2021 20:29:16 +0000 (22:29 +0200)
35 files changed:
Cargo.lock
Cargo.toml
crates/api_crud/Cargo.toml
crates/apub/src/activities/mod.rs
crates/apub/src/extensions/context.rs
crates/apub/src/extensions/mod.rs
crates/apub/src/extensions/signatures.rs
crates/apub/src/fetcher/community.rs
crates/apub/src/fetcher/mod.rs
crates/apub/src/fetcher/objects.rs
crates/apub/src/fetcher/person.rs
crates/apub/src/lib.rs
crates/apub/src/objects/mod.rs
crates/apub_receive/Cargo.toml [new file with mode: 0644]
crates/apub_receive/src/activities/mod.rs [new file with mode: 0644]
crates/apub_receive/src/activities/receive/comment.rs [moved from crates/apub/src/activities/receive/comment.rs with 98% similarity]
crates/apub_receive/src/activities/receive/comment_undo.rs [moved from crates/apub/src/activities/receive/comment_undo.rs with 100% similarity]
crates/apub_receive/src/activities/receive/community.rs [moved from crates/apub/src/activities/receive/community.rs with 100% similarity]
crates/apub_receive/src/activities/receive/mod.rs [moved from crates/apub/src/activities/receive/mod.rs with 97% similarity]
crates/apub_receive/src/activities/receive/post.rs [moved from crates/apub/src/activities/receive/post.rs with 99% similarity]
crates/apub_receive/src/activities/receive/post_undo.rs [moved from crates/apub/src/activities/receive/post_undo.rs with 100% similarity]
crates/apub_receive/src/activities/receive/private_message.rs [moved from crates/apub/src/activities/receive/private_message.rs with 98% similarity]
crates/apub_receive/src/http/comment.rs [moved from crates/apub/src/http/comment.rs with 90% similarity]
crates/apub_receive/src/http/community.rs [moved from crates/apub/src/http/community.rs with 98% similarity]
crates/apub_receive/src/http/mod.rs [moved from crates/apub/src/http/mod.rs with 97% similarity]
crates/apub_receive/src/http/person.rs [moved from crates/apub/src/http/person.rs with 93% similarity]
crates/apub_receive/src/http/post.rs [moved from crates/apub/src/http/post.rs with 89% similarity]
crates/apub_receive/src/inbox/community_inbox.rs [moved from crates/apub/src/inbox/community_inbox.rs with 91% similarity]
crates/apub_receive/src/inbox/mod.rs [moved from crates/apub/src/inbox/mod.rs with 86% similarity]
crates/apub_receive/src/inbox/person_inbox.rs [moved from crates/apub/src/inbox/person_inbox.rs with 99% similarity]
crates/apub_receive/src/inbox/receive_for_community.rs [moved from crates/apub/src/inbox/receive_for_community.rs with 99% similarity]
crates/apub_receive/src/inbox/shared_inbox.rs [moved from crates/apub/src/inbox/shared_inbox.rs with 91% similarity]
crates/apub_receive/src/lib.rs [new file with mode: 0644]
crates/apub_receive/src/routes.rs [moved from crates/apub/src/routes.rs with 98% similarity]
src/main.rs

index 004b31d042d28415618f1282abbcff3cbb550a8d..b5c654131e02908915841305d32e2a76a4fa577e 100644 (file)
@@ -1802,7 +1802,6 @@ dependencies = [
  "background-jobs",
  "base64 0.13.0",
  "bcrypt",
- "captcha",
  "chrono",
  "diesel",
  "futures",
@@ -1881,6 +1880,50 @@ dependencies = [
  "uuid",
 ]
 
+[[package]]
+name = "lemmy_apub_receive"
+version = "0.1.0"
+dependencies = [
+ "activitystreams",
+ "activitystreams-ext",
+ "actix",
+ "actix-rt",
+ "actix-web",
+ "anyhow",
+ "async-trait",
+ "awc",
+ "backtrace",
+ "base64 0.13.0",
+ "bcrypt",
+ "chrono",
+ "diesel",
+ "futures",
+ "http",
+ "http-signature-normalization-actix",
+ "http-signature-normalization-reqwest",
+ "itertools",
+ "lemmy_api_common",
+ "lemmy_apub",
+ "lemmy_db_queries",
+ "lemmy_db_schema",
+ "lemmy_db_views",
+ "lemmy_db_views_actor",
+ "lemmy_utils",
+ "lemmy_websocket",
+ "log",
+ "openssl",
+ "percent-encoding",
+ "rand 0.8.3",
+ "serde",
+ "serde_json",
+ "sha2",
+ "strum",
+ "strum_macros",
+ "thiserror",
+ "tokio 0.3.7",
+ "url",
+]
+
 [[package]]
 name = "lemmy_db_queries"
 version = "0.1.0"
@@ -1996,6 +2039,7 @@ dependencies = [
  "lemmy_api_common",
  "lemmy_api_crud",
  "lemmy_apub",
+ "lemmy_apub_receive",
  "lemmy_db_queries",
  "lemmy_db_schema",
  "lemmy_db_views",
index 4f338f9b15cee6f1b5d95de301214f508cc68542..0fd838819682c74e8304cd43e35c4c4efc9ace88 100644 (file)
@@ -15,6 +15,7 @@ members = [
     "crates/api_crud",
     "crates/api_common",
     "crates/apub",
+    "crates/apub_receive",
     "crates/utils",
     "crates/db_queries",
     "crates/db_schema",
@@ -29,6 +30,7 @@ members = [
 lemmy_api = { path = "./crates/api" }
 lemmy_api_crud = { path = "./crates/api_crud" }
 lemmy_apub = { path = "./crates/apub" }
+lemmy_apub_receive = { path = "./crates/apub_receive" }
 lemmy_utils = { path = "./crates/utils" }
 lemmy_db_schema = { path = "./crates/db_schema" }
 lemmy_db_queries = { path = "./crates/db_queries" }
index f7fde4a6813fffc78d8d25a94c78023a0f3e47ee..deebc12fa2c82a91d788c3f0e7ddb93cadee5ad7 100644 (file)
@@ -38,7 +38,6 @@ itertools = "0.10.0"
 uuid = { version = "0.8.2", features = ["serde", "v4"] }
 sha2 = "0.9.3"
 async-trait = "0.1.42"
-captcha = "0.0.8"
 anyhow = "1.0.38"
 thiserror = "1.0.23"
 background-jobs = "0.8.0"
index cb61fcf21986a4d3636d37a3ea11a03c2a8239cd..5c9ff69435df7566ac12e87c7ee840c08a0c4b8d 100644 (file)
@@ -1,2 +1 @@
-pub(crate) mod receive;
 pub mod send;
index 041ca4bf0a271bb109a09d8ef5531b2beecf432b..63ae2c6d0e7efa5d427ed66d3ba1c9fd19c57c5f 100644 (file)
@@ -3,7 +3,7 @@ use lemmy_utils::LemmyError;
 use serde_json::json;
 use url::Url;
 
-pub(crate) fn lemmy_context() -> Result<Vec<AnyBase>, LemmyError> {
+pub fn lemmy_context() -> Result<Vec<AnyBase>, LemmyError> {
   let context_ext = AnyBase::from_arbitrary_json(json!(
   {
     "sc": "http://schema.org#",
index 2f7df8211a3d619e3619bef909d4f2174f68b775..19e37894d616bf5afbeb2fe422f24fdcb537e2ab 100644 (file)
@@ -1,5 +1,5 @@
-pub(crate) mod context;
+pub mod context;
 pub(crate) mod group_extension;
 pub(crate) mod page_extension;
 pub(crate) mod person_extension;
-pub(crate) mod signatures;
+pub mod signatures;
index a9b4cfbdf0af94a849420cc75f90f784652aa4fa..92e2a306d3fc34e2ace14411b9542e834c3a7058 100644 (file)
@@ -26,7 +26,7 @@ lazy_static! {
 
 /// Creates an HTTP post request to `inbox_url`, with the given `client` and `headers`, and
 /// `activity` as request body. The request is signed with `private_key` and then sent.
-pub async fn sign_and_send(
+pub(crate) async fn sign_and_send(
   client: &Client,
   headers: BTreeMap<String, String>,
   inbox_url: &Url,
@@ -65,10 +65,7 @@ pub async fn sign_and_send(
 }
 
 /// Verifies the HTTP signature on an incoming inbox request.
-pub(crate) fn verify_signature(
-  request: &HttpRequest,
-  actor: &dyn ActorType,
-) -> Result<(), LemmyError> {
+pub fn verify_signature(request: &HttpRequest, actor: &dyn ActorType) -> Result<(), LemmyError> {
   let public_key = actor.public_key().context(location_info!())?;
   let verified = CONFIG2
     .begin_verify(
index c657bfad4514d3d76a14b2ca1e3f65f14f1a8902..6187ac10cf3fe58a33b9c74de7b2f34c680d003f 100644 (file)
@@ -5,7 +5,6 @@ use crate::{
     person::get_or_fetch_and_upsert_person,
     should_refetch_actor,
   },
-  inbox::person_inbox::receive_announce,
   objects::FromApub,
   GroupExt,
 };
@@ -31,7 +30,7 @@ use url::Url;
 ///
 /// If it exists locally and `!should_refetch_actor()`, it is returned directly from the database.
 /// Otherwise it is fetched from the remote instance, stored and returned.
-pub(crate) async fn get_or_fetch_and_upsert_community(
+pub async fn get_or_fetch_and_upsert_community(
   apub_id: &Url,
   context: &LemmyContext,
   recursion_counter: &mut i32,
@@ -158,7 +157,8 @@ async fn fetch_community_outbox(
   }
 
   for activity in outbox_activities {
-    receive_announce(context, activity, community, recursion_counter).await?;
+    todo!("{:?} {:?} {:?}", activity, community, recursion_counter);
+    //receive_announce(context, activity, community, recursion_counter).await?;
   }
 
   Ok(())
index 234a929b97cefda28c0029f6b7f512f3395f661a..477cecc87b900c26f4adc210585f3df3e48df88e 100644 (file)
@@ -1,7 +1,7 @@
-pub(crate) mod community;
+pub mod community;
 mod fetch;
-pub(crate) mod objects;
-pub(crate) mod person;
+pub mod objects;
+pub mod person;
 pub mod search;
 
 use crate::{
@@ -42,7 +42,7 @@ where
 ///
 /// If it exists locally and `!should_refetch_actor()`, it is returned directly from the database.
 /// Otherwise it is fetched from the remote instance, stored and returned.
-pub(crate) async fn get_or_fetch_and_upsert_actor(
+pub async fn get_or_fetch_and_upsert_actor(
   apub_id: &Url,
   context: &LemmyContext,
   recursion_counter: &mut i32,
index b8f8bbde4087940aa55244077df6dfedbfc27656..41bc075a046724f7578afcff5a81518857e425e9 100644 (file)
@@ -13,7 +13,7 @@ use url::Url;
 /// pulled from its apub ID, inserted and returned.
 ///
 /// The parent community is also pulled if necessary. Comments are not pulled.
-pub(crate) async fn get_or_fetch_and_insert_post(
+pub async fn get_or_fetch_and_insert_post(
   post_ap_id: &Url,
   context: &LemmyContext,
   recursion_counter: &mut i32,
@@ -49,7 +49,7 @@ pub(crate) async fn get_or_fetch_and_insert_post(
 /// pulled from its apub ID, inserted and returned.
 ///
 /// The parent community, post and comment are also pulled if necessary.
-pub(crate) async fn get_or_fetch_and_insert_comment(
+pub async fn get_or_fetch_and_insert_comment(
   comment_ap_id: &Url,
   context: &LemmyContext,
   recursion_counter: &mut i32,
index 81ba731b1c99606bb1b96a3fde7808c5633a0ecb..4e6191abb035a25777b19effdaec3b45bc6ac577 100644 (file)
@@ -17,7 +17,7 @@ use url::Url;
 ///
 /// If it exists locally and `!should_refetch_actor()`, it is returned directly from the database.
 /// Otherwise it is fetched from the remote instance, stored and returned.
-pub(crate) async fn get_or_fetch_and_upsert_person(
+pub async fn get_or_fetch_and_upsert_person(
   apub_id: &Url,
   context: &LemmyContext,
   recursion_counter: &mut i32,
index ad697d0ce604a52e74bfe05adcfc090d5a63cab8..8dd35ea3de3779e93b91c1967e4d93cbc3fea17e 100644 (file)
@@ -5,10 +5,7 @@ pub mod activities;
 pub mod activity_queue;
 pub mod extensions;
 pub mod fetcher;
-pub mod http;
-pub mod inbox;
 pub mod objects;
-pub mod routes;
 
 use crate::extensions::{
   group_extension::GroupExtension,
@@ -20,7 +17,7 @@ use activitystreams::{
   activity::Follow,
   actor,
   base::AnyBase,
-  object::{ApObject, Note, Page},
+  object::{ApObject, AsObject, Note, ObjectExt, Page},
 };
 use activitystreams_ext::{Ext1, Ext2};
 use anyhow::{anyhow, Context};
@@ -36,8 +33,10 @@ use lemmy_db_schema::{
     post::Post,
     private_message::PrivateMessage,
   },
+  CommunityId,
   DbUrl,
 };
+use lemmy_db_views_actor::community_person_ban_view::CommunityPersonBanView;
 use lemmy_utils::{location_info, settings::structs::Settings, LemmyError};
 use lemmy_websocket::LemmyContext;
 use serde::Serialize;
@@ -49,8 +48,8 @@ type GroupExt = Ext2<actor::ApActor<ApObject<actor::Group>>, GroupExtension, Pub
 /// Activitystreams type for person
 type PersonExt = Ext2<actor::ApActor<ApObject<actor::Person>>, PersonExtension, PublicKeyExtension>;
 /// Activitystreams type for post
-type PageExt = Ext1<ApObject<Page>, PageExtension>;
-type NoteExt = ApObject<Note>;
+pub type PageExt = Ext1<ApObject<Page>, PageExtension>;
+pub type NoteExt = ApObject<Note>;
 
 pub static APUB_JSON_CONTENT_TYPE: &str = "application/activity+json";
 
@@ -63,7 +62,7 @@ pub static APUB_JSON_CONTENT_TYPE: &str = "application/activity+json";
 /// - URL not being in the blocklist (if it is active)
 ///
 /// Note that only one of allowlist and blacklist can be enabled, not both.
-fn check_is_apub_id_valid(apub_id: &Url) -> Result<(), LemmyError> {
+pub fn check_is_apub_id_valid(apub_id: &Url) -> Result<(), LemmyError> {
   let settings = Settings::get();
   let domain = apub_id.domain().context(location_info!())?.to_string();
   let local_instance = settings.get_hostname_without_port()?;
@@ -294,13 +293,13 @@ pub fn generate_shared_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, LemmyError>
   Ok(Url::parse(&url)?.into())
 }
 
-pub(crate) fn generate_moderators_url(community_id: &DbUrl) -> Result<DbUrl, LemmyError> {
+pub fn generate_moderators_url(community_id: &DbUrl) -> Result<DbUrl, LemmyError> {
   Ok(Url::parse(&format!("{}/moderators", community_id))?.into())
 }
 
 /// Store a sent or received activity in the database, for logging purposes. These records are not
 /// persistent.
-pub(crate) async fn insert_activity<T>(
+pub async fn insert_activity<T>(
   ap_id: &Url,
   activity: T,
   local: bool,
@@ -318,7 +317,7 @@ where
   Ok(())
 }
 
-pub(crate) enum PostOrComment {
+pub enum PostOrComment {
   Comment(Box<Comment>),
   Post(Box<Post>),
 }
@@ -326,7 +325,7 @@ pub(crate) enum PostOrComment {
 /// Tries to find a post or comment in the local database, without any network requests.
 /// This is used to handle deletions and removals, because in case we dont have the object, we can
 /// simply ignore the activity.
-pub(crate) async fn find_post_or_comment_by_id(
+pub async fn find_post_or_comment_by_id(
   context: &LemmyContext,
   apub_id: Url,
 ) -> Result<PostOrComment, LemmyError> {
@@ -400,3 +399,49 @@ pub(crate) async fn find_object_by_id(
 
   Err(NotFound.into())
 }
+
+pub async fn check_community_or_site_ban(
+  person: &Person,
+  community_id: CommunityId,
+  pool: &DbPool,
+) -> Result<(), LemmyError> {
+  if person.banned {
+    return Err(anyhow!("Person is banned from site").into());
+  }
+  let person_id = person.id;
+  let is_banned =
+    move |conn: &'_ _| CommunityPersonBanView::get(conn, person_id, community_id).is_ok();
+  if blocking(pool, is_banned).await? {
+    return Err(anyhow!("Person is banned from community").into());
+  }
+
+  Ok(())
+}
+
+pub fn get_activity_to_and_cc<T, Kind>(activity: &T) -> Vec<Url>
+where
+  T: AsObject<Kind>,
+{
+  let mut to_and_cc = vec![];
+  if let Some(to) = activity.to() {
+    let to = to.to_owned().unwrap_to_vec();
+    let mut to = to
+      .iter()
+      .map(|t| t.as_xsd_any_uri())
+      .flatten()
+      .map(|t| t.to_owned())
+      .collect();
+    to_and_cc.append(&mut to);
+  }
+  if let Some(cc) = activity.cc() {
+    let cc = cc.to_owned().unwrap_to_vec();
+    let mut cc = cc
+      .iter()
+      .map(|c| c.as_xsd_any_uri())
+      .flatten()
+      .map(|c| c.to_owned())
+      .collect();
+    to_and_cc.append(&mut cc);
+  }
+  to_and_cc
+}
index 08822abfdc533c09af4d59bde020d954ee31046c..8c18e3417e0d137702f2b675a3c58624b5f9ff0b 100644 (file)
@@ -1,7 +1,8 @@
 use crate::{
+  check_community_or_site_ban,
   check_is_apub_id_valid,
   fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
-  inbox::{community_inbox::check_community_or_site_ban, get_activity_to_and_cc},
+  get_activity_to_and_cc,
   PageExt,
 };
 use activitystreams::{
@@ -33,14 +34,14 @@ pub(crate) mod private_message;
 
 /// Trait for converting an object or actor into the respective ActivityPub type.
 #[async_trait::async_trait(?Send)]
-pub(crate) trait ToApub {
+pub trait ToApub {
   type ApubType;
   async fn to_apub(&self, pool: &DbPool) -> Result<Self::ApubType, LemmyError>;
   fn to_tombstone(&self) -> Result<Tombstone, LemmyError>;
 }
 
 #[async_trait::async_trait(?Send)]
-pub(crate) trait FromApub {
+pub trait FromApub {
   type ApubType;
   /// Converts an object from ActivityPub type to Lemmy internal type.
   ///
diff --git a/crates/apub_receive/Cargo.toml b/crates/apub_receive/Cargo.toml
new file mode 100644 (file)
index 0000000..54e01f7
--- /dev/null
@@ -0,0 +1,45 @@
+[package]
+name = "lemmy_apub_receive"
+version = "0.1.0"
+edition = "2018"
+
+[dependencies]
+lemmy_utils = { path = "../utils" }
+lemmy_apub = { path = "../apub" }
+lemmy_db_queries = { path = "../db_queries" }
+lemmy_db_schema = { path = "../db_schema" }
+lemmy_db_views = { path = "../db_views" }
+lemmy_db_views_actor = { path = "../db_views_actor" }
+lemmy_api_common = { path = "../api_common" }
+lemmy_websocket = { path = "../websocket" }
+diesel = "1.4.5"
+activitystreams = "0.7.0-alpha.11"
+activitystreams-ext = "0.1.0-alpha.2"
+bcrypt = "0.9.0"
+chrono = { version = "0.4.19", features = ["serde"] }
+serde_json = { version = "1.0.61", features = ["preserve_order"] }
+serde = { version = "1.0.123", features = ["derive"] }
+actix = "0.10.0"
+actix-web = { version = "3.3.2", default-features = false }
+actix-rt = { version = "1.1.1", default-features = false }
+awc = { version = "2.0.3", default-features = false }
+log = "0.4.14"
+rand = "0.8.3"
+strum = "0.20.0"
+strum_macros = "0.20.1"
+url = { version = "2.2.1", features = ["serde"] }
+percent-encoding = "2.1.0"
+openssl = "0.10.32"
+http = "0.2.3"
+http-signature-normalization-actix = { version = "0.4.1", default-features = false, features = ["sha-2"] }
+http-signature-normalization-reqwest = { version = "0.1.3", default-features = false, features = ["sha-2"] }
+base64 = "0.13.0"
+tokio = "0.3.6"
+futures = "0.3.12"
+itertools = "0.10.0"
+sha2 = "0.9.3"
+async-trait = "0.1.42"
+anyhow = "1.0.38"
+thiserror = "1.0.23"
+backtrace = "0.3.56"
+
diff --git a/crates/apub_receive/src/activities/mod.rs b/crates/apub_receive/src/activities/mod.rs
new file mode 100644 (file)
index 0000000..cbdeafa
--- /dev/null
@@ -0,0 +1 @@
+pub(crate) mod receive;
similarity index 98%
rename from crates/apub/src/activities/receive/comment.rs
rename to crates/apub_receive/src/activities/receive/comment.rs
index d79ef84a23fe10c618ff0451772a5028f5a4eacc..18508fa20426acfaac61f179b3f626a334f28170 100644 (file)
@@ -1,10 +1,11 @@
-use crate::{activities::receive::get_actor_as_person, objects::FromApub, ActorType, NoteExt};
+use crate::activities::receive::get_actor_as_person;
 use activitystreams::{
   activity::{ActorAndObjectRefExt, Create, Dislike, Like, Update},
   base::ExtendsExt,
 };
 use anyhow::Context;
 use lemmy_api_common::{blocking, comment::CommentResponse, send_local_notifs};
+use lemmy_apub::{objects::FromApub, ActorType, NoteExt};
 use lemmy_db_queries::{source::comment::Comment_, Crud, Likeable};
 use lemmy_db_schema::source::{
   comment::{Comment, CommentLike, CommentLikeForm},
similarity index 97%
rename from crates/apub/src/activities/receive/mod.rs
rename to crates/apub_receive/src/activities/receive/mod.rs
index 1d5fcc300f1cb8552cd4b3733b32b0ec2f3b27f7..afad2dfc942523fa2013718b42c1b83af46b70fe 100644 (file)
@@ -1,10 +1,10 @@
-use crate::fetcher::person::get_or_fetch_and_upsert_person;
 use activitystreams::{
   activity::{ActorAndObjectRef, ActorAndObjectRefExt},
   base::{AsBase, BaseExt},
   error::DomainError,
 };
 use anyhow::{anyhow, Context};
+use lemmy_apub::fetcher::person::get_or_fetch_and_upsert_person;
 use lemmy_db_schema::source::person::Person;
 use lemmy_utils::{location_info, LemmyError};
 use lemmy_websocket::LemmyContext;
similarity index 99%
rename from crates/apub/src/activities/receive/post.rs
rename to crates/apub_receive/src/activities/receive/post.rs
index 2f4290d0b7a9aa1e1e4cf4fb50ae173540692002..07f6a6653dc78d7b761ab835457a3d8599686443 100644 (file)
@@ -1,9 +1,6 @@
 use crate::{
   activities::receive::get_actor_as_person,
   inbox::receive_for_community::verify_mod_activity,
-  objects::FromApub,
-  ActorType,
-  PageExt,
 };
 use activitystreams::{
   activity::{Announce, Create, Dislike, Like, Update},
@@ -11,6 +8,7 @@ use activitystreams::{
 };
 use anyhow::Context;
 use lemmy_api_common::{blocking, post::PostResponse};
+use lemmy_apub::{objects::FromApub, ActorType, PageExt};
 use lemmy_db_queries::{source::post::Post_, ApubObject, Crud, Likeable};
 use lemmy_db_schema::{
   source::{
similarity index 98%
rename from crates/apub/src/activities/receive/private_message.rs
rename to crates/apub_receive/src/activities/receive/private_message.rs
index 6d90e8681ead8c9e99bf77aa9cd239f804335232..6be1a0415ced0b9ce65e338caf05083a421ec7fe 100644 (file)
@@ -1,11 +1,4 @@
-use crate::{
-  activities::receive::verify_activity_domains_valid,
-  check_is_apub_id_valid,
-  fetcher::person::get_or_fetch_and_upsert_person,
-  inbox::get_activity_to_and_cc,
-  objects::FromApub,
-  NoteExt,
-};
+use crate::activities::receive::verify_activity_domains_valid;
 use activitystreams::{
   activity::{ActorAndObjectRefExt, Create, Delete, Undo, Update},
   base::{AsBase, ExtendsExt},
@@ -14,6 +7,13 @@ use activitystreams::{
 };
 use anyhow::{anyhow, Context};
 use lemmy_api_common::{blocking, person::PrivateMessageResponse};
+use lemmy_apub::{
+  check_is_apub_id_valid,
+  fetcher::person::get_or_fetch_and_upsert_person,
+  get_activity_to_and_cc,
+  objects::FromApub,
+  NoteExt,
+};
 use lemmy_db_queries::source::private_message::PrivateMessage_;
 use lemmy_db_schema::source::private_message::PrivateMessage;
 use lemmy_db_views::{local_user_view::LocalUserView, private_message_view::PrivateMessageView};
similarity index 90%
rename from crates/apub/src/http/comment.rs
rename to crates/apub_receive/src/http/comment.rs
index 4f63d89d3f7671e2777297683afa5a7a59563d6f..001879e005abcd8b45a4bb5a1c7496b63f7dd368 100644 (file)
@@ -1,10 +1,8 @@
-use crate::{
-  http::{create_apub_response, create_apub_tombstone_response},
-  objects::ToApub,
-};
+use crate::http::{create_apub_response, create_apub_tombstone_response};
 use actix_web::{body::Body, web, web::Path, HttpResponse};
 use diesel::result::Error::NotFound;
 use lemmy_api_common::blocking;
+use lemmy_apub::objects::ToApub;
 use lemmy_db_queries::Crud;
 use lemmy_db_schema::{source::comment::Comment, CommentId};
 use lemmy_utils::LemmyError;
similarity index 98%
rename from crates/apub/src/http/community.rs
rename to crates/apub_receive/src/http/community.rs
index 4d3d8481d69bb7dd89313d6016ae336df6af3f17..1d5ae906e67273ef7fb06c552f6dc86c9647164e 100644 (file)
@@ -1,10 +1,4 @@
-use crate::{
-  extensions::context::lemmy_context,
-  generate_moderators_url,
-  http::{create_apub_response, create_apub_tombstone_response},
-  objects::ToApub,
-  ActorType,
-};
+use crate::http::{create_apub_response, create_apub_tombstone_response};
 use activitystreams::{
   base::{AnyBase, BaseExt},
   collection::{CollectionExt, OrderedCollection, UnorderedCollection},
@@ -12,6 +6,12 @@ use activitystreams::{
 };
 use actix_web::{body::Body, web, HttpResponse};
 use lemmy_api_common::blocking;
+use lemmy_apub::{
+  extensions::context::lemmy_context,
+  generate_moderators_url,
+  objects::ToApub,
+  ActorType,
+};
 use lemmy_db_queries::source::{activity::Activity_, community::Community_};
 use lemmy_db_schema::source::{activity::Activity, community::Community};
 use lemmy_db_views_actor::{
similarity index 97%
rename from crates/apub/src/http/mod.rs
rename to crates/apub_receive/src/http/mod.rs
index 5d0cf71f2511f5c9e28bd65ec3f4d6ef4765746a..531c37890ab3f8001f8839d2cf226db568ac2046 100644 (file)
@@ -1,7 +1,7 @@
-use crate::APUB_JSON_CONTENT_TYPE;
 use actix_web::{body::Body, web, HttpResponse};
 use http::StatusCode;
 use lemmy_api_common::blocking;
+use lemmy_apub::APUB_JSON_CONTENT_TYPE;
 use lemmy_db_queries::source::activity::Activity_;
 use lemmy_db_schema::source::activity::Activity;
 use lemmy_utils::{settings::structs::Settings, LemmyError};
similarity index 93%
rename from crates/apub/src/http/person.rs
rename to crates/apub_receive/src/http/person.rs
index 6a5a9a27b8fcf6d4b6c7cb0d90f626ae13b0f5d2..69598ec2af906895d592e56dad97eefa279d0e12 100644 (file)
@@ -1,15 +1,11 @@
-use crate::{
-  extensions::context::lemmy_context,
-  http::{create_apub_response, create_apub_tombstone_response},
-  objects::ToApub,
-  ActorType,
-};
+use crate::http::{create_apub_response, create_apub_tombstone_response};
 use activitystreams::{
   base::BaseExt,
   collection::{CollectionExt, OrderedCollection},
 };
 use actix_web::{body::Body, web, HttpResponse};
 use lemmy_api_common::blocking;
+use lemmy_apub::{extensions::context::lemmy_context, objects::ToApub, ActorType};
 use lemmy_db_queries::source::person::Person_;
 use lemmy_db_schema::source::person::Person;
 use lemmy_utils::LemmyError;
similarity index 89%
rename from crates/apub/src/http/post.rs
rename to crates/apub_receive/src/http/post.rs
index 324bb7da9a5d31019042b8d92a6fc6eb50fb2644..45a0191ebe4bb194f35446aec0881ddb37a9fdf2 100644 (file)
@@ -1,10 +1,8 @@
-use crate::{
-  http::{create_apub_response, create_apub_tombstone_response},
-  objects::ToApub,
-};
+use crate::http::{create_apub_response, create_apub_tombstone_response};
 use actix_web::{body::Body, web, HttpResponse};
 use diesel::result::Error::NotFound;
 use lemmy_api_common::blocking;
+use lemmy_apub::objects::ToApub;
 use lemmy_db_queries::Crud;
 use lemmy_db_schema::{source::post::Post, PostId};
 use lemmy_utils::LemmyError;
similarity index 91%
rename from crates/apub/src/inbox/community_inbox.rs
rename to crates/apub_receive/src/inbox/community_inbox.rs
index 61123d06f3856940dabf7dd8d2d71a1e7b5a94cf..486636caa1f38430f1ef6d46517810d8e08b6b4a 100644 (file)
@@ -3,7 +3,6 @@ use crate::{
   inbox::{
     assert_activity_not_local,
     get_activity_id,
-    get_activity_to_and_cc,
     inbox_verify_http_signature,
     is_activity_already_known,
     receive_for_community::{
@@ -18,9 +17,6 @@ use crate::{
     },
     verify_is_addressed_to_public,
   },
-  insert_activity,
-  ActorType,
-  CommunityType,
 };
 use activitystreams::{
   activity::{kind::FollowType, ActorAndObject, Follow, Undo},
@@ -30,15 +26,18 @@ use activitystreams::{
 use actix_web::{web, HttpRequest, HttpResponse};
 use anyhow::{anyhow, Context};
 use lemmy_api_common::blocking;
-use lemmy_db_queries::{source::community::Community_, ApubObject, DbPool, Followable};
-use lemmy_db_schema::{
-  source::{
-    community::{Community, CommunityFollower, CommunityFollowerForm},
-    person::Person,
-  },
-  CommunityId,
+use lemmy_apub::{
+  check_community_or_site_ban,
+  get_activity_to_and_cc,
+  insert_activity,
+  ActorType,
+  CommunityType,
+};
+use lemmy_db_queries::{source::community::Community_, ApubObject, Followable};
+use lemmy_db_schema::source::{
+  community::{Community, CommunityFollower, CommunityFollowerForm},
+  person::Person,
 };
-use lemmy_db_views_actor::community_person_ban_view::CommunityPersonBanView;
 use lemmy_utils::{location_info, LemmyError};
 use lemmy_websocket::LemmyContext;
 use log::info;
@@ -318,21 +317,3 @@ async fn handle_undo_follow(
 
   Ok(())
 }
-
-pub(crate) async fn check_community_or_site_ban(
-  person: &Person,
-  community_id: CommunityId,
-  pool: &DbPool,
-) -> Result<(), LemmyError> {
-  if person.banned {
-    return Err(anyhow!("Person is banned from site").into());
-  }
-  let person_id = person.id;
-  let is_banned =
-    move |conn: &'_ _| CommunityPersonBanView::get(conn, person_id, community_id).is_ok();
-  if blocking(pool, is_banned).await? {
-    return Err(anyhow!("Person is banned from community").into());
-  }
-
-  Ok(())
-}
similarity index 86%
rename from crates/apub/src/inbox/mod.rs
rename to crates/apub_receive/src/inbox/mod.rs
index 72b00c33459529e761564b48fe81c8e290695f9a..453781fde8072300831fd55d7e4c423702620652 100644 (file)
@@ -1,18 +1,19 @@
-use crate::{
-  check_is_apub_id_valid,
-  extensions::signatures::verify_signature,
-  fetcher::get_or_fetch_and_upsert_actor,
-  ActorType,
-};
 use activitystreams::{
   activity::ActorAndObjectRefExt,
   base::{AsBase, BaseExt, Extends},
-  object::{AsObject, ObjectExt},
+  object::AsObject,
   public,
 };
 use actix_web::HttpRequest;
 use anyhow::{anyhow, Context};
 use lemmy_api_common::blocking;
+use lemmy_apub::{
+  check_is_apub_id_valid,
+  extensions::signatures::verify_signature,
+  fetcher::get_or_fetch_and_upsert_actor,
+  get_activity_to_and_cc,
+  ActorType,
+};
 use lemmy_db_queries::{
   source::{activity::Activity_, community::Community_},
   ApubObject,
@@ -56,34 +57,6 @@ pub(crate) async fn is_activity_already_known(
   }
 }
 
-pub(crate) fn get_activity_to_and_cc<T, Kind>(activity: &T) -> Vec<Url>
-where
-  T: AsObject<Kind>,
-{
-  let mut to_and_cc = vec![];
-  if let Some(to) = activity.to() {
-    let to = to.to_owned().unwrap_to_vec();
-    let mut to = to
-      .iter()
-      .map(|t| t.as_xsd_any_uri())
-      .flatten()
-      .map(|t| t.to_owned())
-      .collect();
-    to_and_cc.append(&mut to);
-  }
-  if let Some(cc) = activity.cc() {
-    let cc = cc.to_owned().unwrap_to_vec();
-    let mut cc = cc
-      .iter()
-      .map(|c| c.as_xsd_any_uri())
-      .flatten()
-      .map(|c| c.to_owned())
-      .collect();
-    to_and_cc.append(&mut cc);
-  }
-  to_and_cc
-}
-
 pub(crate) fn verify_is_addressed_to_public<T, Kind>(activity: &T) -> Result<(), LemmyError>
 where
   T: AsBase<Kind> + AsObject<Kind> + ActorAndObjectRefExt,
similarity index 99%
rename from crates/apub/src/inbox/person_inbox.rs
rename to crates/apub_receive/src/inbox/person_inbox.rs
index 99c0f18f52ee7b3e48325c342d05604261f20bc2..42567ab63e6009a660c56ee7475ce959447383a1 100644 (file)
@@ -16,12 +16,9 @@ use crate::{
     receive_unhandled_activity,
     verify_activity_domains_valid,
   },
-  check_is_apub_id_valid,
-  fetcher::community::get_or_fetch_and_upsert_community,
   inbox::{
     assert_activity_not_local,
     get_activity_id,
-    get_activity_to_and_cc,
     inbox_verify_http_signature,
     is_activity_already_known,
     is_addressed_to_community_followers,
@@ -38,8 +35,6 @@ use crate::{
     },
     verify_is_addressed_to_public,
   },
-  insert_activity,
-  ActorType,
 };
 use activitystreams::{
   activity::{Accept, ActorAndObject, Announce, Create, Delete, Follow, Remove, Undo, Update},
@@ -50,6 +45,13 @@ use actix_web::{web, HttpRequest, HttpResponse};
 use anyhow::{anyhow, Context};
 use diesel::NotFound;
 use lemmy_api_common::blocking;
+use lemmy_apub::{
+  check_is_apub_id_valid,
+  fetcher::community::get_or_fetch_and_upsert_community,
+  get_activity_to_and_cc,
+  insert_activity,
+  ActorType,
+};
 use lemmy_db_queries::{source::person::Person_, ApubObject, Followable};
 use lemmy_db_schema::source::{
   community::{Community, CommunityFollower},
similarity index 99%
rename from crates/apub/src/inbox/receive_for_community.rs
rename to crates/apub_receive/src/inbox/receive_for_community.rs
index 5fe2bdf7a01bf74ba6afd3a6ad6d3acbd99f6fe7..181a86d120c9ff27b02cd249706341ddd22a4e3d 100644 (file)
@@ -31,15 +31,7 @@ use crate::{
     receive_unhandled_activity,
     verify_activity_domains_valid,
   },
-  fetcher::{
-    objects::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
-    person::get_or_fetch_and_upsert_person,
-  },
-  find_post_or_comment_by_id,
-  generate_moderators_url,
   inbox::verify_is_addressed_to_public,
-  CommunityType,
-  PostOrComment,
 };
 use activitystreams::{
   activity::{
@@ -62,6 +54,16 @@ use activitystreams::{
 use anyhow::{anyhow, Context};
 use diesel::result::Error::NotFound;
 use lemmy_api_common::blocking;
+use lemmy_apub::{
+  fetcher::{
+    objects::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
+    person::get_or_fetch_and_upsert_person,
+  },
+  find_post_or_comment_by_id,
+  generate_moderators_url,
+  CommunityType,
+  PostOrComment,
+};
 use lemmy_db_queries::{source::community::CommunityModerator_, ApubObject, Crud, Joinable};
 use lemmy_db_schema::{
   source::{
similarity index 91%
rename from crates/apub/src/inbox/shared_inbox.rs
rename to crates/apub_receive/src/inbox/shared_inbox.rs
index 710f34b443e6d09c71d3fbcbd4d224cd516e4b30..cd4ae145a9c5ef35251c64e09251ba98bff9bbae 100644 (file)
@@ -1,21 +1,18 @@
-use crate::{
-  inbox::{
-    assert_activity_not_local,
-    community_inbox::{community_receive_message, CommunityAcceptedActivities},
-    get_activity_id,
-    get_activity_to_and_cc,
-    inbox_verify_http_signature,
-    is_activity_already_known,
-    is_addressed_to_community_followers,
-    is_addressed_to_local_person,
-    person_inbox::{person_receive_message, PersonAcceptedActivities},
-  },
-  insert_activity,
+use crate::inbox::{
+  assert_activity_not_local,
+  community_inbox::{community_receive_message, CommunityAcceptedActivities},
+  get_activity_id,
+  inbox_verify_http_signature,
+  is_activity_already_known,
+  is_addressed_to_community_followers,
+  is_addressed_to_local_person,
+  person_inbox::{person_receive_message, PersonAcceptedActivities},
 };
 use activitystreams::{activity::ActorAndObject, prelude::*};
 use actix_web::{web, HttpRequest, HttpResponse};
 use anyhow::Context;
 use lemmy_api_common::blocking;
+use lemmy_apub::{get_activity_to_and_cc, insert_activity};
 use lemmy_db_queries::{ApubObject, DbPool};
 use lemmy_db_schema::source::community::Community;
 use lemmy_utils::{location_info, LemmyError};
diff --git a/crates/apub_receive/src/lib.rs b/crates/apub_receive/src/lib.rs
new file mode 100644 (file)
index 0000000..69c32b3
--- /dev/null
@@ -0,0 +1,4 @@
+mod activities;
+mod http;
+mod inbox;
+pub mod routes;
similarity index 98%
rename from crates/apub/src/routes.rs
rename to crates/apub_receive/src/routes.rs
index fecf333fab3006b21dd9c87234b4d4df7a89d856..d112afbeaef048125dc9e30a980064e4d8bd5daf 100644 (file)
@@ -17,10 +17,10 @@ use crate::{
     person_inbox::person_inbox,
     shared_inbox::shared_inbox,
   },
-  APUB_JSON_CONTENT_TYPE,
 };
 use actix_web::*;
 use http_signature_normalization_actix::digest::middleware::VerifyDigest;
+use lemmy_apub::APUB_JSON_CONTENT_TYPE;
 use lemmy_utils::settings::structs::Settings;
 use sha2::{Digest, Sha256};
 
index f8838bfb0ae5e7b786903666aeb8426eb105a099..5b8a7ec1d1bf2ee7f6e88a0007bca6f3ecd9169e 100644 (file)
@@ -91,7 +91,7 @@ async fn main() -> Result<(), LemmyError> {
       .data(context)
       // The routes
       .configure(|cfg| api_routes::config(cfg, &rate_limiter))
-      .configure(lemmy_apub::routes::config)
+      .configure(lemmy_apub_receive::routes::config)
       .configure(feeds::config)
       .configure(|cfg| images::config(cfg, &rate_limiter))
       .configure(nodeinfo::config)