]> Untitled Git - lemmy.git/commitdiff
Merge apub, apub_receive crates (fixes #1621)
authorFelix Ableitner <me@nutomic.com>
Sat, 17 Jul 2021 16:20:44 +0000 (18:20 +0200)
committerFelix Ableitner <me@nutomic.com>
Sat, 17 Jul 2021 16:20:44 +0000 (18:20 +0200)
56 files changed:
Cargo.lock
Cargo.toml
ansible/templates/docker-compose.yml
api_tests/prepare-drone-federation-test.sh
crates/apub/Cargo.toml
crates/apub/src/activities/comment/create.rs [moved from crates/apub_receive/src/activities/comment/create.rs with 90% similarity]
crates/apub/src/activities/comment/mod.rs [moved from crates/apub_receive/src/activities/comment/mod.rs with 96% similarity]
crates/apub/src/activities/comment/remove.rs [moved from crates/apub_receive/src/activities/comment/remove.rs with 94% similarity]
crates/apub/src/activities/comment/undo_remove.rs [moved from crates/apub_receive/src/activities/comment/undo_remove.rs with 95% similarity]
crates/apub/src/activities/comment/update.rs [moved from crates/apub_receive/src/activities/comment/update.rs with 90% similarity]
crates/apub/src/activities/community/add_mod.rs [moved from crates/apub_receive/src/activities/community/add_mod.rs with 94% similarity]
crates/apub/src/activities/community/announce.rs [moved from crates/apub_receive/src/activities/community/announce.rs with 98% similarity]
crates/apub/src/activities/community/block_user.rs [moved from crates/apub_receive/src/activities/community/block_user.rs with 91% similarity]
crates/apub/src/activities/community/mod.rs [moved from crates/apub_receive/src/activities/community/mod.rs with 100% similarity]
crates/apub/src/activities/community/undo_block_user.rs [moved from crates/apub_receive/src/activities/community/undo_block_user.rs with 87% similarity]
crates/apub/src/activities/community/update.rs [moved from crates/apub_receive/src/activities/community/update.rs with 92% similarity]
crates/apub/src/activities/deletion/delete.rs [moved from crates/apub_receive/src/activities/deletion/delete.rs with 94% similarity]
crates/apub/src/activities/deletion/mod.rs [moved from crates/apub_receive/src/activities/deletion/mod.rs with 100% similarity]
crates/apub/src/activities/deletion/undo_delete.rs [moved from crates/apub_receive/src/activities/deletion/undo_delete.rs with 91% similarity]
crates/apub/src/activities/following/accept.rs [moved from crates/apub_receive/src/activities/following/accept.rs with 89% similarity]
crates/apub/src/activities/following/follow.rs [moved from crates/apub_receive/src/activities/following/follow.rs with 96% similarity]
crates/apub/src/activities/following/mod.rs [moved from crates/apub_receive/src/activities/following/mod.rs with 100% similarity]
crates/apub/src/activities/following/undo.rs [moved from crates/apub_receive/src/activities/following/undo.rs with 90% similarity]
crates/apub/src/activities/mod.rs
crates/apub/src/activities/post/create.rs [moved from crates/apub_receive/src/activities/post/create.rs with 92% similarity]
crates/apub/src/activities/post/mod.rs [moved from crates/apub_receive/src/activities/post/mod.rs with 100% similarity]
crates/apub/src/activities/post/update.rs [moved from crates/apub_receive/src/activities/post/update.rs with 94% similarity]
crates/apub/src/activities/private_message/create.rs [moved from crates/apub_receive/src/activities/private_message/create.rs with 91% similarity]
crates/apub/src/activities/private_message/delete.rs [moved from crates/apub_receive/src/activities/private_message/delete.rs with 100% similarity]
crates/apub/src/activities/private_message/mod.rs [moved from crates/apub_receive/src/activities/private_message/mod.rs with 100% similarity]
crates/apub/src/activities/private_message/undo_delete.rs [moved from crates/apub_receive/src/activities/private_message/undo_delete.rs with 100% similarity]
crates/apub/src/activities/private_message/update.rs [moved from crates/apub_receive/src/activities/private_message/update.rs with 91% similarity]
crates/apub/src/activities/removal/mod.rs [moved from crates/apub_receive/src/activities/removal/mod.rs with 100% similarity]
crates/apub/src/activities/removal/remove.rs [moved from crates/apub_receive/src/activities/removal/remove.rs with 93% similarity]
crates/apub/src/activities/removal/undo_remove.rs [moved from crates/apub_receive/src/activities/removal/undo_remove.rs with 91% similarity]
crates/apub/src/activities/voting/dislike.rs [moved from crates/apub_receive/src/activities/voting/dislike.rs with 100% similarity]
crates/apub/src/activities/voting/like.rs [moved from crates/apub_receive/src/activities/voting/like.rs with 100% similarity]
crates/apub/src/activities/voting/mod.rs [moved from crates/apub_receive/src/activities/voting/mod.rs with 96% similarity]
crates/apub/src/activities/voting/undo_dislike.rs [moved from crates/apub_receive/src/activities/voting/undo_dislike.rs with 100% similarity]
crates/apub/src/activities/voting/undo_like.rs [moved from crates/apub_receive/src/activities/voting/undo_like.rs with 100% similarity]
crates/apub/src/fetcher/community.rs
crates/apub/src/http/comment.rs [moved from crates/apub_receive/src/http/comment.rs with 90% similarity]
crates/apub/src/http/community.rs [moved from crates/apub_receive/src/http/community.rs with 96% similarity]
crates/apub/src/http/inbox_enums.rs [moved from crates/apub_receive/src/http/inbox_enums.rs with 100% similarity]
crates/apub/src/http/mod.rs [moved from crates/apub_receive/src/http/mod.rs with 98% similarity]
crates/apub/src/http/person.rs [moved from crates/apub_receive/src/http/person.rs with 91% similarity]
crates/apub/src/http/post.rs [moved from crates/apub_receive/src/http/post.rs with 89% similarity]
crates/apub/src/http/routes.rs [moved from crates/apub_receive/src/http/routes.rs with 84% similarity]
crates/apub/src/lib.rs
crates/apub_receive/Cargo.toml [deleted file]
crates/apub_receive/src/activities/mod.rs [deleted file]
crates/apub_receive/src/lib.rs [deleted file]
docker/dev/docker-compose.yml
docker/federation/docker-compose.yml
docker/prod/docker-compose.yml
src/main.rs

index 31492222fc3d70404c7d3fb31dc756622bd46021..53e3e0071e56f6a122714b536f2f970c86c2b7ba 100644 (file)
@@ -1726,6 +1726,7 @@ dependencies = [
  "itertools",
  "lazy_static",
  "lemmy_api_common",
+ "lemmy_apub_lib",
  "lemmy_db_queries",
  "lemmy_db_schema",
  "lemmy_db_views",
@@ -1772,51 +1773,6 @@ dependencies = [
  "trybuild",
 ]
 
-[[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_apub_lib",
- "lemmy_db_queries",
- "lemmy_db_schema",
- "lemmy_db_views",
- "lemmy_db_views_actor",
- "lemmy_utils",
- "lemmy_websocket",
- "log",
- "openssl",
- "percent-encoding",
- "rand 0.8.4",
- "serde",
- "serde_json",
- "sha2",
- "strum",
- "strum_macros",
- "thiserror",
- "tokio",
- "url",
-]
-
 [[package]]
 name = "lemmy_db_queries"
 version = "0.1.0"
@@ -1932,7 +1888,6 @@ dependencies = [
  "lemmy_api_common",
  "lemmy_api_crud",
  "lemmy_apub",
- "lemmy_apub_receive",
  "lemmy_db_queries",
  "lemmy_db_schema",
  "lemmy_db_views",
index 2352a7d645b0b23a9a6110860651a6c0e4019fb1..0259f69ddab9bf6ca7bd1cd80f38d83acc4317ef 100644 (file)
@@ -17,7 +17,6 @@ members = [
     "crates/apub_lib",
     "crates/apub_lib_derive",
     "crates/apub",
-    "crates/apub_receive",
     "crates/utils",
     "crates/db_queries",
     "crates/db_schema",
@@ -32,7 +31,6 @@ 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 03053d3470db87e041e943c84f4697c06c8ec11a..1d2609e63ef58f50577386811077150f473d25a3 100644 (file)
@@ -7,7 +7,7 @@ services:
       - "127.0.0.1:8536:8536"
     restart: always
     environment:
-      - RUST_LOG="warn,lemmy_server=info,lemmy_api=info,lemmy_api_common=info,lemmy_api_crud=info,lemmy_apub=info,lemmy_apub_receive=info,lemmy_db_queries=info,lemmy_db_schema=info,lemmy_db_views=info,lemmy_db_views_actor=info,lemmy_db_views_moderator=info,lemmy_routes=info,lemmy_utils=info,lemmy_websocket=info"
+      - RUST_LOG="warn,lemmy_server=info,lemmy_api=info,lemmy_api_common=info,lemmy_api_crud=info,lemmy_apub=info,lemmy_db_queries=info,lemmy_db_schema=info,lemmy_db_views=info,lemmy_db_views_actor=info,lemmy_db_views_moderator=info,lemmy_routes=info,lemmy_utils=info,lemmy_websocket=info"
     volumes:
       - ./lemmy.hjson:/config/config.hjson:ro
     depends_on:
index c2c7805aa99ec20f5283c83049dc346cff8858c2..7a8fb2bd8b261ab572d29af5fe4c1d342549deb4 100755 (executable)
@@ -3,7 +3,7 @@ set -e
 
 export LEMMY_TEST_SEND_SYNC=1
 export RUST_BACKTRACE=1
-export RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_apub_receive=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
+export RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
 
 for INSTANCE in lemmy_alpha lemmy_beta lemmy_gamma lemmy_delta lemmy_epsilon; do
   psql "${LEMMY_DATABASE_URL}/lemmy" -c "DROP DATABASE IF EXISTS $INSTANCE"
index 9f5b3e5049aed8a57c4f90e8b48c50254fd8a9c6..ac4453bbc518e911718958eceb27d45f832046ca 100644 (file)
@@ -10,6 +10,7 @@ doctest = false
 
 [dependencies]
 lemmy_utils = { path = "../utils" }
+lemmy_apub_lib = { path = "../apub_lib" }
 lemmy_db_queries = { path = "../db_queries" }
 lemmy_db_schema = { path = "../db_schema" }
 lemmy_db_views = { path = "../db_views" }
@@ -31,7 +32,6 @@ log = "0.4.14"
 rand = "0.8.4"
 strum = "0.21.0"
 strum_macros = "0.21.1"
-lazy_static = "1.4.0"
 url = { version = "2.2.2", features = ["serde"] }
 percent-encoding = "2.1.0"
 openssl = "0.10.35"
@@ -50,3 +50,5 @@ thiserror = "1.0.26"
 background-jobs = "0.9.0"
 reqwest = { version = "0.11.4", features = ["json"] }
 backtrace = "0.3.60"
+lazy_static = "1.4.0"
+
similarity index 90%
rename from crates/apub_receive/src/activities/comment/create.rs
rename to crates/apub/src/activities/comment/create.rs
index 7ce5d09af9e00d54b35cef3099af4ccb64c4401e..84dab107132b3b92d0c7fdbc8627158a7d8dd24c 100644 (file)
@@ -1,10 +1,13 @@
-use crate::activities::{
-  comment::{get_notif_recipients, send_websocket_message},
-  verify_activity,
-  verify_person_in_community,
+use crate::{
+  activities::{
+    comment::{get_notif_recipients, send_websocket_message},
+    verify_activity,
+    verify_person_in_community,
+  },
+  objects::FromApub,
+  NoteExt,
 };
 use activitystreams::{activity::kind::CreateType, base::BaseExt};
-use lemmy_apub::{objects::FromApub, NoteExt};
 use lemmy_apub_lib::{verify_domains_match_opt, ActivityCommonFields, ActivityHandler, PublicUrl};
 use lemmy_db_schema::source::comment::Comment;
 use lemmy_utils::LemmyError;
similarity index 96%
rename from crates/apub_receive/src/activities/comment/mod.rs
rename to crates/apub/src/activities/comment/mod.rs
index e5cdb4dd6daed010719f6eede470089274691165..292d57bf404d10d0108089044e14f59b67cc4ce6 100644 (file)
@@ -1,5 +1,5 @@
+use crate::fetcher::person::get_or_fetch_and_upsert_person;
 use lemmy_api_common::{blocking, comment::CommentResponse, send_local_notifs};
-use lemmy_apub::fetcher::person::get_or_fetch_and_upsert_person;
 use lemmy_db_queries::Crud;
 use lemmy_db_schema::{
   source::{comment::Comment, post::Post},
similarity index 94%
rename from crates/apub_receive/src/activities/comment/remove.rs
rename to crates/apub/src/activities/comment/remove.rs
index 53e69b6589ba64e3a371e65a47196834ba089c20..d60e3f80444d347a98a890e34330f075ca7fb35b 100644 (file)
@@ -1,7 +1,7 @@
 use crate::activities::{comment::send_websocket_message, verify_mod_action};
 use activitystreams::activity::kind::RemoveType;
 use lemmy_api_common::blocking;
-use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_comment};
+use crate::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_comment};
 use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandlerNew, PublicUrl};
 use lemmy_db_queries::source::comment::Comment_;
 use lemmy_db_schema::source::comment::Comment;
similarity index 95%
rename from crates/apub_receive/src/activities/comment/undo_remove.rs
rename to crates/apub/src/activities/comment/undo_remove.rs
index 444f3ce40c6422322d2424f3afcf6d19c7f978e6..f3ebdf3851ab2d4ef5b203c7634d22146a26ce6b 100644 (file)
@@ -4,7 +4,7 @@ use crate::activities::{
 };
 use activitystreams::activity::kind::UndoType;
 use lemmy_api_common::blocking;
-use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_comment};
+use crate::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_comment};
 use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandlerNew, PublicUrl};
 use lemmy_db_queries::source::comment::Comment_;
 use lemmy_db_schema::source::comment::Comment;
similarity index 90%
rename from crates/apub_receive/src/activities/comment/update.rs
rename to crates/apub/src/activities/comment/update.rs
index c07837e390f9f34538371ed85260ccac6a7d0d9e..142656f506e41dce0f4a9725a0363629244f3a71 100644 (file)
@@ -1,10 +1,13 @@
-use crate::activities::{
-  comment::{get_notif_recipients, send_websocket_message},
-  verify_activity,
-  verify_person_in_community,
+use crate::{
+  activities::{
+    comment::{get_notif_recipients, send_websocket_message},
+    verify_activity,
+    verify_person_in_community,
+  },
+  objects::FromApub,
+  NoteExt,
 };
 use activitystreams::{activity::kind::UpdateType, base::BaseExt};
-use lemmy_apub::{objects::FromApub, NoteExt};
 use lemmy_apub_lib::{verify_domains_match_opt, ActivityCommonFields, ActivityHandler, PublicUrl};
 use lemmy_db_schema::source::comment::Comment;
 use lemmy_utils::LemmyError;
similarity index 94%
rename from crates/apub_receive/src/activities/community/add_mod.rs
rename to crates/apub/src/activities/community/add_mod.rs
index 2cf64f717a226913bf007f21ee3c58428a6f9f33..2785856c131e53919fd59906623d763d335c6b60 100644 (file)
@@ -1,15 +1,15 @@
-use crate::activities::{
-  verify_activity,
-  verify_add_remove_moderator_target,
-  verify_mod_action,
-  verify_person_in_community,
-};
-use activitystreams::{activity::kind::AddType, base::AnyBase};
-use lemmy_api_common::blocking;
-use lemmy_apub::{
+use crate::{
+  activities::{
+    verify_activity,
+    verify_add_remove_moderator_target,
+    verify_mod_action,
+    verify_person_in_community,
+  },
   fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
   CommunityType,
 };
+use activitystreams::{activity::kind::AddType, base::AnyBase};
+use lemmy_api_common::blocking;
 use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl};
 use lemmy_db_queries::{source::community::CommunityModerator_, Joinable};
 use lemmy_db_schema::source::community::{CommunityModerator, CommunityModeratorForm};
similarity index 98%
rename from crates/apub_receive/src/activities/community/announce.rs
rename to crates/apub/src/activities/community/announce.rs
index 09f51a7ea544b81097fe894800e207a288947824..301ccc64840574e0bcce1a9e839b96677cfa7700 100644 (file)
@@ -25,9 +25,9 @@ use crate::{
     },
   },
   http::is_activity_already_known,
+  insert_activity,
 };
 use activitystreams::activity::kind::AnnounceType;
-use lemmy_apub::insert_activity;
 use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
similarity index 91%
rename from crates/apub_receive/src/activities/community/block_user.rs
rename to crates/apub/src/activities/community/block_user.rs
index 03a19e9c751aaec266ae7a41dd359c8fde7d6546..c20652b02c85f61c6b584a4894564735cfe416d5 100644 (file)
@@ -1,10 +1,9 @@
-use crate::activities::{verify_activity, verify_mod_action, verify_person_in_community};
+use crate::{
+  activities::{verify_activity, verify_mod_action, verify_person_in_community},
+  fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
+};
 use activitystreams::activity::kind::BlockType;
 use lemmy_api_common::blocking;
-use lemmy_apub::fetcher::{
-  community::get_or_fetch_and_upsert_community,
-  person::get_or_fetch_and_upsert_person,
-};
 use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl};
 use lemmy_db_queries::{Bannable, Followable};
 use lemmy_db_schema::source::community::{
similarity index 87%
rename from crates/apub_receive/src/activities/community/undo_block_user.rs
rename to crates/apub/src/activities/community/undo_block_user.rs
index 88518385baa2cf3d8b9f9af9d247d300138c80af..025c498a6d4fff01908b7b8916d6856457166bd0 100644 (file)
@@ -1,15 +1,14 @@
-use crate::activities::{
-  community::block_user::BlockUserFromCommunity,
-  verify_activity,
-  verify_mod_action,
-  verify_person_in_community,
+use crate::{
+  activities::{
+    community::block_user::BlockUserFromCommunity,
+    verify_activity,
+    verify_mod_action,
+    verify_person_in_community,
+  },
+  fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
 };
 use activitystreams::activity::kind::UndoType;
 use lemmy_api_common::blocking;
-use lemmy_apub::fetcher::{
-  community::get_or_fetch_and_upsert_community,
-  person::get_or_fetch_and_upsert_person,
-};
 use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl};
 use lemmy_db_queries::Bannable;
 use lemmy_db_schema::source::community::{CommunityPersonBan, CommunityPersonBanForm};
similarity index 92%
rename from crates/apub_receive/src/activities/community/update.rs
rename to crates/apub/src/activities/community/update.rs
index a333c1bbfeea5ff4e344753960f39e0b412670ee..cfee29da74399c381383926783f7fba472ebd110 100644 (file)
@@ -1,12 +1,15 @@
-use crate::activities::{
-  community::send_websocket_message,
-  verify_activity,
-  verify_mod_action,
-  verify_person_in_community,
+use crate::{
+  activities::{
+    community::send_websocket_message,
+    verify_activity,
+    verify_mod_action,
+    verify_person_in_community,
+  },
+  objects::FromApubToForm,
+  GroupExt,
 };
 use activitystreams::activity::kind::UpdateType;
 use lemmy_api_common::blocking;
-use lemmy_apub::{objects::FromApubToForm, GroupExt};
 use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl};
 use lemmy_db_queries::{ApubObject, Crud};
 use lemmy_db_schema::source::community::{Community, CommunityForm};
similarity index 94%
rename from crates/apub_receive/src/activities/deletion/delete.rs
rename to crates/apub/src/activities/deletion/delete.rs
index 0276516dd4e776952e847ceaf6128431360fac94..f0f4185a7b744d8e109dabed9b9c3c3db48f0fbe 100644 (file)
@@ -1,14 +1,12 @@
-use crate::activities::{
-  comment::send_websocket_message as send_comment_message,
-  community::send_websocket_message as send_community_message,
-  post::send_websocket_message as send_post_message,
-  verify_activity,
-  verify_mod_action,
-  verify_person_in_community,
-};
-use activitystreams::activity::kind::DeleteType;
-use lemmy_api_common::blocking;
-use lemmy_apub::{
+use crate::{
+  activities::{
+    comment::send_websocket_message as send_comment_message,
+    community::send_websocket_message as send_community_message,
+    post::send_websocket_message as send_post_message,
+    verify_activity,
+    verify_mod_action,
+    verify_person_in_community,
+  },
   fetcher::{
     community::get_or_fetch_and_upsert_community,
     objects::get_or_fetch_and_insert_post_or_comment,
@@ -18,6 +16,8 @@ use lemmy_apub::{
   CommunityType,
   PostOrComment,
 };
+use activitystreams::activity::kind::DeleteType;
+use lemmy_api_common::blocking;
 use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandler, PublicUrl};
 use lemmy_db_queries::{
   source::{comment::Comment_, community::Community_, post::Post_},
similarity index 91%
rename from crates/apub_receive/src/activities/deletion/undo_delete.rs
rename to crates/apub/src/activities/deletion/undo_delete.rs
index 9875a2a9afa58b2cf42463e2a102a05d351f5c17..1de5ca587ead823f4e331b99c1a74ed36030a7bf 100644 (file)
@@ -1,15 +1,13 @@
-use crate::activities::{
-  comment::send_websocket_message as send_comment_message,
-  community::send_websocket_message as send_community_message,
-  deletion::delete::DeletePostCommentOrCommunity,
-  post::send_websocket_message as send_post_message,
-  verify_activity,
-  verify_mod_action,
-  verify_person_in_community,
-};
-use activitystreams::activity::kind::UndoType;
-use lemmy_api_common::blocking;
-use lemmy_apub::{
+use crate::{
+  activities::{
+    comment::send_websocket_message as send_comment_message,
+    community::send_websocket_message as send_community_message,
+    deletion::delete::DeletePostCommentOrCommunity,
+    post::send_websocket_message as send_post_message,
+    verify_activity,
+    verify_mod_action,
+    verify_person_in_community,
+  },
   fetcher::{
     community::get_or_fetch_and_upsert_community,
     objects::get_or_fetch_and_insert_post_or_comment,
@@ -18,6 +16,8 @@ use lemmy_apub::{
   CommunityType,
   PostOrComment,
 };
+use activitystreams::activity::kind::UndoType;
+use lemmy_api_common::blocking;
 use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandler, PublicUrl};
 use lemmy_db_queries::source::{comment::Comment_, community::Community_, post::Post_};
 use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post};
similarity index 89%
rename from crates/apub_receive/src/activities/following/accept.rs
rename to crates/apub/src/activities/following/accept.rs
index d5cf474d470e432961ea65f1ed0cbb9f06992efa..6bd5d272f7f4d8420c8929a46975e3149ca9e9ff 100644 (file)
@@ -1,10 +1,9 @@
-use crate::activities::{following::follow::FollowCommunity, verify_activity, verify_community};
+use crate::{
+  activities::{following::follow::FollowCommunity, verify_activity, verify_community},
+  fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
+};
 use activitystreams::activity::kind::AcceptType;
 use lemmy_api_common::blocking;
-use lemmy_apub::fetcher::{
-  community::get_or_fetch_and_upsert_community,
-  person::get_or_fetch_and_upsert_person,
-};
 use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandler};
 use lemmy_db_queries::Followable;
 use lemmy_db_schema::source::community::CommunityFollower;
similarity index 96%
rename from crates/apub_receive/src/activities/following/follow.rs
rename to crates/apub/src/activities/following/follow.rs
index fd0649f196ada13c3e0481b0fb53b19f5a5bb821..49c9970c0f1484b865fea39911e72140c43a3700 100644 (file)
@@ -1,14 +1,14 @@
-use crate::activities::{verify_activity, verify_person};
+use crate::{
+  activities::{verify_activity, verify_person},
+  fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
+  CommunityType,
+};
 use activitystreams::{
   activity::{kind::FollowType, Follow},
   base::{AnyBase, ExtendsExt},
 };
 use anyhow::Context;
 use lemmy_api_common::blocking;
-use lemmy_apub::{
-  fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
-  CommunityType,
-};
 use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandler};
 use lemmy_db_queries::Followable;
 use lemmy_db_schema::source::community::{CommunityFollower, CommunityFollowerForm};
similarity index 90%
rename from crates/apub_receive/src/activities/following/undo.rs
rename to crates/apub/src/activities/following/undo.rs
index 1f3d12e6141a1de991d4c01d10a47aa57fdff2ef..1936997f4ce4675b07c1c627d6d4745f291cdc41 100644 (file)
@@ -1,10 +1,9 @@
-use crate::activities::{following::follow::FollowCommunity, verify_activity, verify_person};
+use crate::{
+  activities::{following::follow::FollowCommunity, verify_activity, verify_person},
+  fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
+};
 use activitystreams::activity::kind::UndoType;
 use lemmy_api_common::blocking;
-use lemmy_apub::fetcher::{
-  community::get_or_fetch_and_upsert_community,
-  person::get_or_fetch_and_upsert_person,
-};
 use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandler};
 use lemmy_db_queries::Followable;
 use lemmy_db_schema::source::community::{CommunityFollower, CommunityFollowerForm};
index 5c9ff69435df7566ac12e87c7ee840c08a0c4b8d..d9f3dcddef0843a7fe433598b7ab475a66b3f582 100644 (file)
@@ -1 +1,122 @@
+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},
+  generate_moderators_url,
+};
+use anyhow::anyhow;
+use lemmy_api_common::blocking;
+use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields};
+use lemmy_db_queries::ApubObject;
+use lemmy_db_schema::{
+  source::{community::Community, person::Person},
+  DbUrl,
+};
+use lemmy_db_views_actor::community_view::CommunityView;
+use lemmy_utils::LemmyError;
+use lemmy_websocket::LemmyContext;
+use url::Url;
+
+pub mod comment;
+pub mod community;
+pub mod deletion;
+pub mod following;
+pub mod post;
+pub mod private_message;
+pub mod removal;
 pub mod send;
+pub mod voting;
+
+/// Checks that the specified Url actually identifies a Person (by fetching it), and that the person
+/// doesn't have a site ban.
+async fn verify_person(
+  person_id: &Url,
+  context: &LemmyContext,
+  request_counter: &mut i32,
+) -> Result<(), LemmyError> {
+  let person = get_or_fetch_and_upsert_person(person_id, context, request_counter).await?;
+  if person.banned {
+    return Err(anyhow!("Person {} is banned", person_id).into());
+  }
+  Ok(())
+}
+
+/// Fetches the person and community to verify their type, then checks if person is banned from site
+/// or community.
+async fn verify_person_in_community(
+  person_id: &Url,
+  cc: &[Url],
+  context: &LemmyContext,
+  request_counter: &mut i32,
+) -> Result<Community, LemmyError> {
+  let person = get_or_fetch_and_upsert_person(person_id, context, request_counter).await?;
+  let mut cc_iter = cc.iter();
+  let community: Community = loop {
+    if let Some(cid) = cc_iter.next() {
+      if let Ok(c) = get_or_fetch_and_upsert_community(cid, context, request_counter).await {
+        break c;
+      }
+    } else {
+      return Err(anyhow!("No community found in cc").into());
+    }
+  };
+  check_community_or_site_ban(&person, community.id, context.pool()).await?;
+  Ok(community)
+}
+
+/// Simply check that the url actually refers to a valid group.
+async fn verify_community(
+  community_id: &Url,
+  context: &LemmyContext,
+  request_counter: &mut i32,
+) -> Result<(), LemmyError> {
+  get_or_fetch_and_upsert_community(community_id, context, request_counter).await?;
+  Ok(())
+}
+
+fn verify_activity(common: &ActivityCommonFields) -> Result<(), LemmyError> {
+  check_is_apub_id_valid(&common.actor, false)?;
+  verify_domains_match(common.id_unchecked(), &common.actor)?;
+  Ok(())
+}
+
+async fn verify_mod_action(
+  actor_id: &Url,
+  activity_cc: Url,
+  context: &LemmyContext,
+) -> Result<(), LemmyError> {
+  let community = blocking(context.pool(), move |conn| {
+    Community::read_from_apub_id(conn, &activity_cc.into())
+  })
+  .await??;
+
+  if community.local {
+    let actor_id: DbUrl = actor_id.clone().into();
+    let actor = blocking(context.pool(), move |conn| {
+      Person::read_from_apub_id(conn, &actor_id)
+    })
+    .await??;
+
+    // Note: this will also return true for admins in addition to mods, but as we dont know about
+    //       remote admins, it doesnt make any difference.
+    let community_id = community.id;
+    let actor_id = actor.id;
+    let is_mod_or_admin = blocking(context.pool(), move |conn| {
+      CommunityView::is_mod_or_admin(conn, actor_id, community_id)
+    })
+    .await?;
+    if !is_mod_or_admin {
+      return Err(anyhow!("Not a mod").into());
+    }
+  }
+  Ok(())
+}
+
+/// For Add/Remove community moderator activities, check that the target field actually contains
+/// /c/community/moderators. Any different values are unsupported.
+fn verify_add_remove_moderator_target(target: &Url, community: Url) -> Result<(), LemmyError> {
+  if target != &generate_moderators_url(&community.into())?.into_inner() {
+    return Err(anyhow!("Unkown target url").into());
+  }
+  Ok(())
+}
similarity index 92%
rename from crates/apub_receive/src/activities/post/create.rs
rename to crates/apub/src/activities/post/create.rs
index 2d31fa0d18fd0624dd74562e5d8f1b3072cb0624..a2ccf4ce5c418b09a063b54c2ae8a843fc8d8337 100644 (file)
@@ -1,15 +1,11 @@
-use crate::activities::{
-  post::send_websocket_message,
-  verify_activity,
-  verify_person_in_community,
-};
-use activitystreams::{activity::kind::CreateType, base::BaseExt};
-use lemmy_apub::{
+use crate::{
+  activities::{post::send_websocket_message, verify_activity, verify_person_in_community},
   fetcher::person::get_or_fetch_and_upsert_person,
   objects::FromApub,
   ActorType,
   PageExt,
 };
+use activitystreams::{activity::kind::CreateType, base::BaseExt};
 use lemmy_apub_lib::{verify_domains_match_opt, ActivityCommonFields, ActivityHandler, PublicUrl};
 use lemmy_db_schema::source::post::Post;
 use lemmy_utils::LemmyError;
similarity index 94%
rename from crates/apub_receive/src/activities/post/update.rs
rename to crates/apub/src/activities/post/update.rs
index 1f5924929004e47f999442496ab9b369352d8fcf..13456dcd8ce761ae20733a63abbd33c060eb44ca 100644 (file)
@@ -1,17 +1,17 @@
-use crate::activities::{
-  post::send_websocket_message,
-  verify_activity,
-  verify_mod_action,
-  verify_person_in_community,
-};
-use activitystreams::{activity::kind::UpdateType, base::BaseExt};
-use anyhow::Context;
-use lemmy_api_common::blocking;
-use lemmy_apub::{
+use crate::{
+  activities::{
+    post::send_websocket_message,
+    verify_activity,
+    verify_mod_action,
+    verify_person_in_community,
+  },
   objects::{FromApub, FromApubToForm},
   ActorType,
   PageExt,
 };
+use activitystreams::{activity::kind::UpdateType, base::BaseExt};
+use anyhow::Context;
+use lemmy_api_common::blocking;
 use lemmy_apub_lib::{verify_domains_match_opt, ActivityCommonFields, ActivityHandler, PublicUrl};
 use lemmy_db_queries::ApubObject;
 use lemmy_db_schema::{
similarity index 91%
rename from crates/apub_receive/src/activities/private_message/create.rs
rename to crates/apub/src/activities/private_message/create.rs
index 2d766565e2ff2523a6d9e724f68baca1ff0525ff..5e6db4ea87d9bdd5c6cc13435c9ba92086a5d1a7 100644 (file)
@@ -1,6 +1,9 @@
-use crate::activities::{private_message::send_websocket_message, verify_activity, verify_person};
+use crate::{
+  activities::{private_message::send_websocket_message, verify_activity, verify_person},
+  objects::FromApub,
+  NoteExt,
+};
 use activitystreams::{activity::kind::CreateType, base::BaseExt};
-use lemmy_apub::{objects::FromApub, NoteExt};
 use lemmy_apub_lib::{verify_domains_match_opt, ActivityCommonFields, ActivityHandler};
 use lemmy_db_schema::source::private_message::PrivateMessage;
 use lemmy_utils::LemmyError;
similarity index 91%
rename from crates/apub_receive/src/activities/private_message/update.rs
rename to crates/apub/src/activities/private_message/update.rs
index 56a79f8e813932be988b2c1a0b1a1fbb696f6434..72ac0749a927c36df4996d4bdaa12ab301000a3b 100644 (file)
@@ -1,6 +1,9 @@
-use crate::activities::{private_message::send_websocket_message, verify_activity, verify_person};
+use crate::{
+  activities::{private_message::send_websocket_message, verify_activity, verify_person},
+  objects::FromApub,
+  NoteExt,
+};
 use activitystreams::{activity::kind::UpdateType, base::BaseExt};
-use lemmy_apub::{objects::FromApub, NoteExt};
 use lemmy_apub_lib::{verify_domains_match_opt, ActivityCommonFields, ActivityHandler};
 use lemmy_db_schema::source::private_message::PrivateMessage;
 use lemmy_utils::LemmyError;
similarity index 93%
rename from crates/apub_receive/src/activities/removal/remove.rs
rename to crates/apub/src/activities/removal/remove.rs
index bb1c307b19d89695f143c32a0faee2c584433767..a30f23327ffedaaade7a4e49e931b849eca56e7b 100644 (file)
@@ -1,16 +1,13 @@
-use crate::activities::{
-  comment::send_websocket_message as send_comment_message,
-  community::send_websocket_message as send_community_message,
-  post::send_websocket_message as send_post_message,
-  verify_activity,
-  verify_add_remove_moderator_target,
-  verify_mod_action,
-  verify_person_in_community,
-};
-use activitystreams::{activity::kind::RemoveType, base::AnyBase};
-use anyhow::anyhow;
-use lemmy_api_common::blocking;
-use lemmy_apub::{
+use crate::{
+  activities::{
+    comment::send_websocket_message as send_comment_message,
+    community::send_websocket_message as send_community_message,
+    post::send_websocket_message as send_post_message,
+    verify_activity,
+    verify_add_remove_moderator_target,
+    verify_mod_action,
+    verify_person_in_community,
+  },
   fetcher::{
     community::get_or_fetch_and_upsert_community,
     objects::get_or_fetch_and_insert_post_or_comment,
@@ -19,6 +16,9 @@ use lemmy_apub::{
   CommunityType,
   PostOrComment,
 };
+use activitystreams::{activity::kind::RemoveType, base::AnyBase};
+use anyhow::anyhow;
+use lemmy_api_common::blocking;
 use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl};
 use lemmy_db_queries::{
   source::{comment::Comment_, community::Community_, post::Post_},
similarity index 91%
rename from crates/apub_receive/src/activities/removal/undo_remove.rs
rename to crates/apub/src/activities/removal/undo_remove.rs
index e19c4194c5a4fdff46bc38d6fb22924d544bd9d1..997d527d8de9e108ead71553da5546f61b54c298 100644 (file)
@@ -1,22 +1,22 @@
-use crate::activities::{
-  comment::send_websocket_message as send_comment_message,
-  community::send_websocket_message as send_community_message,
-  post::send_websocket_message as send_post_message,
-  removal::remove::RemovePostCommentCommunityOrMod,
-  verify_activity,
-  verify_mod_action,
-  verify_person_in_community,
-};
-use activitystreams::activity::kind::UndoType;
-use anyhow::anyhow;
-use lemmy_api_common::blocking;
-use lemmy_apub::{
+use crate::{
+  activities::{
+    comment::send_websocket_message as send_comment_message,
+    community::send_websocket_message as send_community_message,
+    post::send_websocket_message as send_post_message,
+    removal::remove::RemovePostCommentCommunityOrMod,
+    verify_activity,
+    verify_mod_action,
+    verify_person_in_community,
+  },
   fetcher::{
     community::get_or_fetch_and_upsert_community,
     objects::get_or_fetch_and_insert_post_or_comment,
   },
   PostOrComment,
 };
+use activitystreams::activity::kind::UndoType;
+use anyhow::anyhow;
+use lemmy_api_common::blocking;
 use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl};
 use lemmy_db_queries::source::{comment::Comment_, community::Community_, post::Post_};
 use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post};
similarity index 96%
rename from crates/apub_receive/src/activities/voting/mod.rs
rename to crates/apub/src/activities/voting/mod.rs
index 123523e22aafe3a7daae237fa959cb5ee829510a..739c43051d4904396e9ec5b6db768392fee2317d 100644 (file)
@@ -1,15 +1,15 @@
-use crate::activities::{
-  comment::send_websocket_message as send_comment_message,
-  post::send_websocket_message as send_post_message,
-};
-use lemmy_api_common::blocking;
-use lemmy_apub::{
+use crate::{
+  activities::{
+    comment::send_websocket_message as send_comment_message,
+    post::send_websocket_message as send_post_message,
+  },
   fetcher::{
     objects::get_or_fetch_and_insert_post_or_comment,
     person::get_or_fetch_and_upsert_person,
   },
   PostOrComment,
 };
+use lemmy_api_common::blocking;
 use lemmy_db_queries::Likeable;
 use lemmy_db_schema::source::{
   comment::{Comment, CommentLike, CommentLikeForm},
index f0a759c54592530321a91b9a1ce49d96b3652dbb..670493a98539aadd544f224914894854432a6f4e 100644 (file)
@@ -1,4 +1,5 @@
 use crate::{
+  activities::community::announce::AnnounceActivity,
   fetcher::{
     fetch::fetch_remote_object,
     is_deleted,
@@ -15,6 +16,7 @@ use activitystreams::{
 use anyhow::Context;
 use diesel::result::Error::NotFound;
 use lemmy_api_common::blocking;
+use lemmy_apub_lib::ActivityHandler;
 use lemmy_db_queries::{source::community::Community_, ApubObject, Joinable};
 use lemmy_db_schema::source::community::{Community, CommunityModerator, CommunityModeratorForm};
 use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView;
@@ -84,7 +86,7 @@ async fn fetch_remote_community(
   // only fetch outbox for new communities, otherwise this can create an infinite loop
   if old_community.is_none() {
     let outbox = group.inner.outbox()?.context(location_info!())?;
-    fetch_community_outbox(context, outbox, &community, request_counter).await?
+    fetch_community_outbox(context, outbox, request_counter).await?
   }
 
   Ok(community)
@@ -143,7 +145,6 @@ async fn update_community_mods(
 async fn fetch_community_outbox(
   context: &LemmyContext,
   outbox: &Url,
-  community: &Community,
   recursion_counter: &mut i32,
 ) -> Result<(), LemmyError> {
   let outbox =
@@ -154,9 +155,12 @@ async fn fetch_community_outbox(
     outbox_activities = outbox_activities[0..20].to_vec();
   }
 
-  for activity in outbox_activities {
-    todo!("{:?} {:?} {:?}", activity, community, recursion_counter);
-    //receive_announce(context, activity, community, recursion_counter).await?;
+  for announce in outbox_activities {
+    // TODO: instead of converting like this, we should create a struct CommunityOutbox with
+    //       AnnounceActivity as inner type, but that gives me stackoverflow
+    let ser = serde_json::to_string(&announce)?;
+    let announce: AnnounceActivity = serde_json::from_str(&ser)?;
+    announce.receive(context, recursion_counter).await?;
   }
 
   Ok(())
similarity index 90%
rename from crates/apub_receive/src/http/comment.rs
rename to crates/apub/src/http/comment.rs
index 001879e005abcd8b45a4bb5a1c7496b63f7dd368..4f63d89d3f7671e2777297683afa5a7a59563d6f 100644 (file)
@@ -1,8 +1,10 @@
-use crate::http::{create_apub_response, create_apub_tombstone_response};
+use crate::{
+  http::{create_apub_response, create_apub_tombstone_response},
+  objects::ToApub,
+};
 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 96%
rename from crates/apub_receive/src/http/community.rs
rename to crates/apub/src/http/community.rs
index 106eeff2fbd72288100e233eb6d3e4d4372c1199..3173bca12c75432b0bb4201b738590a112b2b966 100644 (file)
@@ -1,9 +1,15 @@
-use crate::http::{
-  create_apub_response,
-  create_apub_tombstone_response,
-  inbox_enums::GroupInboxActivities,
-  payload_to_string,
-  receive_activity,
+use crate::{
+  extensions::context::lemmy_context,
+  generate_moderators_url,
+  http::{
+    create_apub_response,
+    create_apub_tombstone_response,
+    inbox_enums::GroupInboxActivities,
+    payload_to_string,
+    receive_activity,
+  },
+  objects::ToApub,
+  ActorType,
 };
 use activitystreams::{
   base::{AnyBase, BaseExt},
@@ -12,12 +18,6 @@ use activitystreams::{
 };
 use actix_web::{body::Body, web, web::Payload, HttpRequest, 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 98%
rename from crates/apub_receive/src/http/mod.rs
rename to crates/apub/src/http/mod.rs
index 44302d8d912a09e83a553c388ca4cb24750c0679..f366cb48c5cb56a18b043a967e2d58a04c5207fe 100644 (file)
@@ -1,4 +1,11 @@
-use crate::http::inbox_enums::SharedInboxActivities;
+use crate::{
+  check_is_apub_id_valid,
+  extensions::signatures::verify_signature,
+  fetcher::get_or_fetch_and_upsert_actor,
+  http::inbox_enums::SharedInboxActivities,
+  insert_activity,
+  APUB_JSON_CONTENT_TYPE,
+};
 use actix_web::{
   body::Body,
   web,
@@ -10,13 +17,6 @@ use anyhow::{anyhow, Context};
 use futures::StreamExt;
 use http::StatusCode;
 use lemmy_api_common::blocking;
-use lemmy_apub::{
-  check_is_apub_id_valid,
-  extensions::signatures::verify_signature,
-  fetcher::get_or_fetch_and_upsert_actor,
-  insert_activity,
-  APUB_JSON_CONTENT_TYPE,
-};
 use lemmy_apub_lib::ActivityHandler;
 use lemmy_db_queries::{source::activity::Activity_, DbPool};
 use lemmy_db_schema::source::activity::Activity;
similarity index 91%
rename from crates/apub_receive/src/http/person.rs
rename to crates/apub/src/http/person.rs
index 59cc869704c157495fd297a5f73ee76bd8f2fae7..2c96aafd8fca32a71648178dc69f4110ed28c7bb 100644 (file)
@@ -1,9 +1,14 @@
-use crate::http::{
-  create_apub_response,
-  create_apub_tombstone_response,
-  inbox_enums::PersonInboxActivities,
-  payload_to_string,
-  receive_activity,
+use crate::{
+  extensions::context::lemmy_context,
+  http::{
+    create_apub_response,
+    create_apub_tombstone_response,
+    inbox_enums::PersonInboxActivities,
+    payload_to_string,
+    receive_activity,
+  },
+  objects::ToApub,
+  ActorType,
 };
 use activitystreams::{
   base::BaseExt,
@@ -11,7 +16,6 @@ use activitystreams::{
 };
 use actix_web::{body::Body, web, web::Payload, HttpRequest, 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_receive/src/http/post.rs
rename to crates/apub/src/http/post.rs
index 45a0191ebe4bb194f35446aec0881ddb37a9fdf2..324bb7da9a5d31019042b8d92a6fc6eb50fb2644 100644 (file)
@@ -1,8 +1,10 @@
-use crate::http::{create_apub_response, create_apub_tombstone_response};
+use crate::{
+  http::{create_apub_response, create_apub_tombstone_response},
+  objects::ToApub,
+};
 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 84%
rename from crates/apub_receive/src/http/routes.rs
rename to crates/apub/src/http/routes.rs
index 929df38bbff60e9fc5c83e5f73f6cfdc9e6b90d3..1afc3f1e509cbdaa7893d34200f49ac01376f755 100644 (file)
@@ -1,21 +1,23 @@
-use crate::http::{
-  comment::get_apub_comment,
-  community::{
-    community_inbox,
-    get_apub_community_followers,
-    get_apub_community_http,
-    get_apub_community_inbox,
-    get_apub_community_moderators,
-    get_apub_community_outbox,
+use crate::{
+  http::{
+    comment::get_apub_comment,
+    community::{
+      community_inbox,
+      get_apub_community_followers,
+      get_apub_community_http,
+      get_apub_community_inbox,
+      get_apub_community_moderators,
+      get_apub_community_outbox,
+    },
+    get_activity,
+    person::{get_apub_person_http, get_apub_person_inbox, get_apub_person_outbox, person_inbox},
+    post::get_apub_post,
+    shared_inbox,
   },
-  get_activity,
-  person::{get_apub_person_http, get_apub_person_inbox, get_apub_person_outbox, person_inbox},
-  post::get_apub_post,
-  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 6bb97675419ef06d5ec09bcfa6c1c7603d40e816..bbc6d515ad68e0204a9c4f78675b15ff0f4a2986 100644 (file)
@@ -5,6 +5,7 @@ pub mod activities;
 pub mod activity_queue;
 pub mod extensions;
 pub mod fetcher;
+pub mod http;
 pub mod objects;
 
 use crate::{
diff --git a/crates/apub_receive/Cargo.toml b/crates/apub_receive/Cargo.toml
deleted file mode 100644 (file)
index ca21787..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-[package]
-name = "lemmy_apub_receive"
-version = "0.1.0"
-edition = "2018"
-
-[dependencies]
-lemmy_utils = { path = "../utils" }
-lemmy_apub_lib = { path = "../apub_lib" }
-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.7"
-activitystreams = "0.7.0-alpha.11"
-activitystreams-ext = "0.1.0-alpha.2"
-bcrypt = "0.10.0"
-chrono = { version = "0.4.19", features = ["serde"] }
-serde_json = { version = "1.0.64", features = ["preserve_order"] }
-serde = { version = "1.0.126", features = ["derive"] }
-actix = "0.12.0"
-actix-web = { version = "4.0.0-beta.8", default-features = false }
-actix-rt = { version = "2.2.0", default-features = false }
-awc = { version = "3.0.0-beta.7", default-features = false }
-log = "0.4.14"
-rand = "0.8.4"
-strum = "0.21.0"
-strum_macros = "0.21.1"
-url = { version = "2.2.2", features = ["serde"] }
-percent-encoding = "2.1.0"
-openssl = "0.10.35"
-http = "0.2.4"
-http-signature-normalization-actix = { version = "0.5.0-beta.6", default-features = false, features = ["sha-2"] }
-http-signature-normalization-reqwest = { version = "0.2.0", default-features = false, features = ["sha-2"] }
-base64 = "0.13.0"
-tokio = "1.8.0"
-futures = "0.3.15"
-itertools = "0.10.1"
-sha2 = "0.9.5"
-async-trait = "0.1.50"
-anyhow = "1.0.41"
-thiserror = "1.0.26"
-backtrace = "0.3.60"
-
diff --git a/crates/apub_receive/src/activities/mod.rs b/crates/apub_receive/src/activities/mod.rs
deleted file mode 100644 (file)
index 098d209..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-use anyhow::anyhow;
-use lemmy_api_common::blocking;
-use lemmy_apub::{
-  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},
-  generate_moderators_url,
-};
-use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields};
-use lemmy_db_queries::ApubObject;
-use lemmy_db_schema::{
-  source::{community::Community, person::Person},
-  DbUrl,
-};
-use lemmy_db_views_actor::community_view::CommunityView;
-use lemmy_utils::LemmyError;
-use lemmy_websocket::LemmyContext;
-use url::Url;
-
-pub mod comment;
-pub mod community;
-pub mod deletion;
-pub mod following;
-pub mod post;
-pub mod private_message;
-pub mod removal;
-pub mod voting;
-
-/// Checks that the specified Url actually identifies a Person (by fetching it), and that the person
-/// doesn't have a site ban.
-async fn verify_person(
-  person_id: &Url,
-  context: &LemmyContext,
-  request_counter: &mut i32,
-) -> Result<(), LemmyError> {
-  let person = get_or_fetch_and_upsert_person(person_id, context, request_counter).await?;
-  if person.banned {
-    return Err(anyhow!("Person {} is banned", person_id).into());
-  }
-  Ok(())
-}
-
-/// Fetches the person and community to verify their type, then checks if person is banned from site
-/// or community.
-async fn verify_person_in_community(
-  person_id: &Url,
-  cc: &[Url],
-  context: &LemmyContext,
-  request_counter: &mut i32,
-) -> Result<Community, LemmyError> {
-  let person = get_or_fetch_and_upsert_person(person_id, context, request_counter).await?;
-  let mut cc_iter = cc.iter();
-  let community: Community = loop {
-    if let Some(cid) = cc_iter.next() {
-      if let Ok(c) = get_or_fetch_and_upsert_community(cid, context, request_counter).await {
-        break c;
-      }
-    } else {
-      return Err(anyhow!("No community found in cc").into());
-    }
-  };
-  check_community_or_site_ban(&person, community.id, context.pool()).await?;
-  Ok(community)
-}
-
-/// Simply check that the url actually refers to a valid group.
-async fn verify_community(
-  community_id: &Url,
-  context: &LemmyContext,
-  request_counter: &mut i32,
-) -> Result<(), LemmyError> {
-  get_or_fetch_and_upsert_community(community_id, context, request_counter).await?;
-  Ok(())
-}
-
-fn verify_activity(common: &ActivityCommonFields) -> Result<(), LemmyError> {
-  check_is_apub_id_valid(&common.actor, false)?;
-  verify_domains_match(common.id_unchecked(), &common.actor)?;
-  Ok(())
-}
-
-async fn verify_mod_action(
-  actor_id: &Url,
-  activity_cc: Url,
-  context: &LemmyContext,
-) -> Result<(), LemmyError> {
-  let community = blocking(context.pool(), move |conn| {
-    Community::read_from_apub_id(conn, &activity_cc.into())
-  })
-  .await??;
-
-  if community.local {
-    let actor_id: DbUrl = actor_id.clone().into();
-    let actor = blocking(context.pool(), move |conn| {
-      Person::read_from_apub_id(conn, &actor_id)
-    })
-    .await??;
-
-    // Note: this will also return true for admins in addition to mods, but as we dont know about
-    //       remote admins, it doesnt make any difference.
-    let community_id = community.id;
-    let actor_id = actor.id;
-    let is_mod_or_admin = blocking(context.pool(), move |conn| {
-      CommunityView::is_mod_or_admin(conn, actor_id, community_id)
-    })
-    .await?;
-    if !is_mod_or_admin {
-      return Err(anyhow!("Not a mod").into());
-    }
-  }
-  Ok(())
-}
-
-/// For Add/Remove community moderator activities, check that the target field actually contains
-/// /c/community/moderators. Any different values are unsupported.
-fn verify_add_remove_moderator_target(target: &Url, community: Url) -> Result<(), LemmyError> {
-  if target != &generate_moderators_url(&community.into())?.into_inner() {
-    return Err(anyhow!("Unkown target url").into());
-  }
-  Ok(())
-}
diff --git a/crates/apub_receive/src/lib.rs b/crates/apub_receive/src/lib.rs
deleted file mode 100644 (file)
index dadc76b..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-mod activities;
-pub mod http;
index 1e532d555157a62ff59bc3d1a8a8a4f8bca91d38..a9e580a4b80a784cc90fb45ec792a5c7c7faf2eb 100644 (file)
@@ -8,7 +8,7 @@ services:
       - "8536:8536"
     restart: always
     environment:
-      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_apub_receive=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
+      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
     volumes:
       - ../lemmy.hjson:/config/config.hjson
     depends_on: 
index fca363a4d94fb9b2f380fd3477ab5c291648521f..a9d8863d3b21e0984e080963ac105dc5fd66a1e6 100644 (file)
@@ -43,7 +43,7 @@ services:
     environment:
       - LEMMY_TEST_SEND_SYNC=1
       - RUST_BACKTRACE=1
-      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_apub_receive=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
+      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
     depends_on:
       - postgres_alpha
     ports: 
@@ -72,7 +72,7 @@ services:
     environment:
       - LEMMY_TEST_SEND_SYNC=1
       - RUST_BACKTRACE=1
-      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_apub_receive=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
+      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
     depends_on:
       - postgres_beta
     ports: 
@@ -101,7 +101,7 @@ services:
     environment:
       - LEMMY_TEST_SEND_SYNC=1
       - RUST_BACKTRACE=1
-      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_apub_receive=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
+      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
     depends_on:
       - postgres_gamma
     ports: 
@@ -131,7 +131,7 @@ services:
     environment:
       - LEMMY_TEST_SEND_SYNC=1
       - RUST_BACKTRACE=1
-      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_apub_receive=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
+      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
     depends_on:
       - postgres_delta
     ports: 
@@ -161,7 +161,7 @@ services:
     environment:
       - LEMMY_TEST_SEND_SYNC=1
       - RUST_BACKTRACE=1
-      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_apub_receive=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
+      - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
     depends_on:
       - postgres_epsilon
     ports: 
index 0e8578e4d2bb303bc2557034ee8b2deef8be1745..5d8bf5680d7b8ada8f4159acabe3b67d3f85fb9d 100644 (file)
@@ -17,7 +17,7 @@ services:
       - "127.0.0.1:8536:8536"
     restart: always
     environment:
-      - RUST_LOG="warn,lemmy_server=info,lemmy_api=info,lemmy_api_common=info,lemmy_api_crud=info,lemmy_apub=info,lemmy_apub_receive=info,lemmy_db_queries=info,lemmy_db_schema=info,lemmy_db_views=info,lemmy_db_views_actor=info,lemmy_db_views_moderator=info,lemmy_routes=info,lemmy_utils=info,lemmy_websocket=info"
+      - RUST_LOG="warn,lemmy_server=info,lemmy_api=info,lemmy_api_common=info,lemmy_api_crud=info,lemmy_apub=info,lemmy_db_queries=info,lemmy_db_schema=info,lemmy_db_views=info,lemmy_db_views_actor=info,lemmy_db_views_moderator=info,lemmy_routes=info,lemmy_utils=info,lemmy_websocket=info"
     volumes:
       - ./lemmy.hjson:/config/config.hjson
     depends_on:
index fd5394fca8c5fb331dfa79519c5cb2e452f50df6..8076fb3653124cd8d40fde4be02516110a6f43b8 100644 (file)
@@ -91,7 +91,7 @@ async fn main() -> Result<(), LemmyError> {
       .app_data(Data::new(context))
       // The routes
       .configure(|cfg| api_routes::config(cfg, &rate_limiter))
-      .configure(lemmy_apub_receive::http::routes::config)
+      .configure(lemmy_apub::http::routes::config)
       .configure(feeds::config)
       .configure(|cfg| images::config(cfg, &rate_limiter))
       .configure(nodeinfo::config)