]> Untitled Git - lemmy.git/commitdiff
For verify_is_public() we also need to check cc field
authorFelix Ableitner <me@nutomic.com>
Sat, 6 Nov 2021 17:44:34 +0000 (18:44 +0100)
committerFelix Ableitner <me@nutomic.com>
Sat, 6 Nov 2021 17:44:34 +0000 (18:44 +0100)
17 files changed:
crates/apub/src/activities/comment/create_or_update.rs
crates/apub/src/activities/community/add_mod.rs
crates/apub/src/activities/community/announce.rs
crates/apub/src/activities/community/block_user.rs
crates/apub/src/activities/community/remove_mod.rs
crates/apub/src/activities/community/undo_block_user.rs
crates/apub/src/activities/community/update.rs
crates/apub/src/activities/deletion/delete.rs
crates/apub/src/activities/deletion/undo_delete.rs
crates/apub/src/activities/mod.rs
crates/apub/src/activities/post/create_or_update.rs
crates/apub/src/activities/voting/undo_vote.rs
crates/apub/src/activities/voting/vote.rs
crates/apub/src/objects/comment.rs
crates/apub/src/objects/post.rs
crates/apub/src/protocol/objects/note.rs
crates/apub/src/protocol/objects/page.rs

index 1ba2c8bb5708c624029cce554162644fb5b570fa..7ac1e4e599811f53beecb16b0df9c993fe8bd7e5 100644 (file)
@@ -75,7 +75,7 @@ impl ActivityHandler for CreateOrUpdateComment {
     context: &Data<LemmyContext>,
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
-    verify_is_public(&self.to)?;
+    verify_is_public(&self.to, &self.cc)?;
     let post = self.object.get_parents(context, request_counter).await?.0;
     let community = self.get_community(context, request_counter).await?;
 
index 8dad860964d8b078379a2b7822109e035e8cda78..f8026cce63f82074029f893119226608178b1f0d 100644 (file)
@@ -64,7 +64,7 @@ impl ActivityHandler for AddMod {
     context: &Data<LemmyContext>,
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
-    verify_is_public(&self.to)?;
+    verify_is_public(&self.to, &self.cc)?;
     verify_activity(&self.id, self.actor.inner(), &context.settings())?;
     let community = self.get_community(context, request_counter).await?;
     verify_person_in_community(&self.actor, &community, context, request_counter).await?;
index 1fcce83774845d1a4f6da5d7877138007eb89ae5..6830bd1394eeb9a48c7a2b7570ae292278d508f4 100644 (file)
@@ -59,7 +59,7 @@ impl ActivityHandler for AnnounceActivity {
     context: &Data<LemmyContext>,
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
-    verify_is_public(&self.to)?;
+    verify_is_public(&self.to, &self.cc)?;
     verify_activity(&self.id, self.actor.inner(), &context.settings())?;
     self.object.verify(context, request_counter).await?;
     Ok(())
index 851c96fd0f9dd5680ea6709f70b3f58d8ed09882..4be0660f8bb0cfc38d96ea24754f2aa6171d48c1 100644 (file)
@@ -75,7 +75,7 @@ impl ActivityHandler for BlockUserFromCommunity {
     context: &Data<LemmyContext>,
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
-    verify_is_public(&self.to)?;
+    verify_is_public(&self.to, &self.cc)?;
     verify_activity(&self.id, self.actor.inner(), &context.settings())?;
     let community = self.get_community(context, request_counter).await?;
     verify_person_in_community(&self.actor, &community, context, request_counter).await?;
index c5edf333b5e807d41bbb18199f18d018f27e37aa..a644c19d7a8ec47e15c1cbe2ef84c0f08b87bfe2 100644 (file)
@@ -63,7 +63,7 @@ impl ActivityHandler for RemoveMod {
     context: &Data<LemmyContext>,
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
-    verify_is_public(&self.to)?;
+    verify_is_public(&self.to, &self.cc)?;
     verify_activity(&self.id, self.actor.inner(), &context.settings())?;
     let community = self.get_community(context, request_counter).await?;
     verify_person_in_community(&self.actor, &community, context, request_counter).await?;
index bb4c0358737a34072939650c3e54d0f80ec70155..f309fe2b8bc5ff66690708f05ca8b065afd8a034 100644 (file)
@@ -65,7 +65,7 @@ impl ActivityHandler for UndoBlockUserFromCommunity {
     context: &Data<LemmyContext>,
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
-    verify_is_public(&self.to)?;
+    verify_is_public(&self.to, &self.cc)?;
     verify_activity(&self.id, self.actor.inner(), &context.settings())?;
     let community = self.get_community(context, request_counter).await?;
     verify_person_in_community(&self.actor, &community, context, request_counter).await?;
index eebfe336c49b844e532dad958274f34da92d9a7b..b4ffb7fc63df573299b45a87e7e2c0a8dd8a829c 100644 (file)
@@ -58,7 +58,7 @@ impl ActivityHandler for UpdateCommunity {
     context: &Data<LemmyContext>,
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
-    verify_is_public(&self.to)?;
+    verify_is_public(&self.to, &self.cc)?;
     verify_activity(&self.id, self.actor.inner(), &context.settings())?;
     let community = self.get_community(context, request_counter).await?;
     verify_person_in_community(&self.actor, &community, context, request_counter).await?;
index 6e2174982fbcda2725188f3414f8a2897eb881c8..54e9c3941e2dbb985e32a7546d2023cd636f3075 100644 (file)
@@ -50,7 +50,7 @@ impl ActivityHandler for Delete {
     context: &Data<LemmyContext>,
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
-    verify_is_public(&self.to)?;
+    verify_is_public(&self.to, &self.cc)?;
     verify_activity(&self.id, self.actor.inner(), &context.settings())?;
     let community = self.get_community(context, request_counter).await?;
     verify_delete_activity(
index b3e44af293fb1a1250aeb69ae5ec1dc75bf1103b..edd893bc3afcebee91f4109700d568dff51bde6d 100644 (file)
@@ -35,7 +35,7 @@ impl ActivityHandler for UndoDelete {
     context: &Data<LemmyContext>,
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
-    verify_is_public(&self.to)?;
+    verify_is_public(&self.to, &self.cc)?;
     verify_activity(&self.id, self.actor.inner(), &context.settings())?;
     self.object.verify(context, request_counter).await?;
     let community = self.get_community(context, request_counter).await?;
index 920a531e98bcc0c346fde60c1ba80a038c1ba46b..a6c7537647b54a3f1ac606ecc42529e17c2bae6d 100644 (file)
@@ -116,8 +116,8 @@ fn verify_add_remove_moderator_target(
   Ok(())
 }
 
-pub(crate) fn verify_is_public(to: &[Url]) -> Result<(), LemmyError> {
-  if !to.contains(&public()) {
+pub(crate) fn verify_is_public(to: &[Url], cc: &[Url]) -> Result<(), LemmyError> {
+  if !to.contains(&public()) && !cc.contains(&public()) {
     return Err(anyhow!("Object is not public").into());
   }
   Ok(())
index db5d725fc2c9a5f4caeef0b3cf47ae36d86124e8..05a7f38d08ae6612f8a4b97f99405534f2316430 100644 (file)
@@ -74,7 +74,7 @@ impl ActivityHandler for CreateOrUpdatePost {
     context: &Data<LemmyContext>,
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
-    verify_is_public(&self.to)?;
+    verify_is_public(&self.to, &self.cc)?;
     verify_activity(&self.id, self.actor.inner(), &context.settings())?;
     let community = self.get_community(context, request_counter).await?;
     verify_person_in_community(&self.actor, &community, context, request_counter).await?;
index 6d6f3eaff4592d2382334e1ddd35d62a29be21e6..c066d731ca6e47718a9a0ddb09b406ae80cb09b9 100644 (file)
@@ -68,7 +68,7 @@ impl ActivityHandler for UndoVote {
     context: &Data<LemmyContext>,
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
-    verify_is_public(&self.to)?;
+    verify_is_public(&self.to, &self.cc)?;
     verify_activity(&self.id, self.actor.inner(), &context.settings())?;
     let community = self.get_community(context, request_counter).await?;
     verify_person_in_community(&self.actor, &community, context, request_counter).await?;
index 89e88fe64775a8ce19c1c0b15134848fccf732ee..304c512a75ff656755ebb56cf73064e5d590593f 100644 (file)
@@ -74,7 +74,7 @@ impl ActivityHandler for Vote {
     context: &Data<LemmyContext>,
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
-    verify_is_public(&self.to)?;
+    verify_is_public(&self.to, &self.cc)?;
     verify_activity(&self.id, self.actor.inner(), &context.settings())?;
     let community = self.get_community(context, request_counter).await?;
     verify_person_in_community(&self.actor, &community, context, request_counter).await?;
index d0f74acfad54c427babbeb1824d5388836f0f179..83895e8d3c32c3bf894f379cbf5eaa72b8b88945 100644 (file)
@@ -107,6 +107,7 @@ impl ApubObject for ApubComment {
       id: ObjectId::new(self.ap_id.clone()),
       attributed_to: ObjectId::new(creator.actor_id),
       to: vec![public()],
+      cc: vec![],
       content: markdown_to_html(&self.content),
       media_type: Some(MediaTypeHtml::Html),
       source: SourceCompat::Lemmy(Source {
@@ -137,7 +138,7 @@ impl ApubObject for ApubComment {
   ) -> Result<(), LemmyError> {
     verify_domains_match(note.id.inner(), expected_domain)?;
     verify_domains_match(note.attributed_to.inner(), note.id.inner())?;
-    verify_is_public(&note.to)?;
+    verify_is_public(&note.to, &note.cc)?;
     let (post, _) = note.get_parents(context, request_counter).await?;
     let community_id = post.community_id;
     let community = blocking(context.pool(), move |conn| {
index 9e68cbb1de1e0fbb0c36b24a10ae1395a9b34bc6..4e34fc88e73f3c672c00905c910cfdd3b0eaaa2e 100644 (file)
@@ -110,6 +110,7 @@ impl ApubObject for ApubPost {
       id: ObjectId::new(self.ap_id.clone()),
       attributed_to: ObjectId::new(creator.actor_id),
       to: vec![community.actor_id.into(), public()],
+      cc: vec![],
       name: self.name.clone(),
       content: self.body.as_ref().map(|b| markdown_to_html(b)),
       media_type: Some(MediaTypeHtml::Html),
@@ -150,7 +151,7 @@ impl ApubObject for ApubPost {
     verify_person_in_community(&page.attributed_to, &community, context, request_counter).await?;
     check_slurs(&page.name, &context.settings().slur_regex())?;
     verify_domains_match(page.attributed_to.inner(), page.id.inner())?;
-    verify_is_public(&page.to.clone())?;
+    verify_is_public(&page.to, &page.cc)?;
     Ok(())
   }
 
index acb4b6fb18b0949b3f46b98678ab07132ad9fd61..3ffc1123d4dea5e1aa97b68a275ab5461c3e6b46 100644 (file)
@@ -23,6 +23,8 @@ pub struct Note {
   pub(crate) id: ObjectId<ApubComment>,
   pub(crate) attributed_to: ObjectId<ApubPerson>,
   pub(crate) to: Vec<Url>,
+  #[serde(default)]
+  pub(crate) cc: Vec<Url>,
   pub(crate) content: String,
   pub(crate) media_type: Option<MediaTypeHtml>,
   pub(crate) source: SourceCompat,
index ef7ab6e69d96a3abbe99c9b903d5f88368f3d478..89fb11415c425afb03d319b5f427706884277b87 100644 (file)
@@ -20,6 +20,8 @@ pub struct Page {
   pub(crate) id: ObjectId<ApubPost>,
   pub(crate) attributed_to: ObjectId<ApubPerson>,
   pub(crate) to: Vec<Url>,
+  #[serde(default)]
+  pub(crate) cc: Vec<Url>,
   pub(crate) name: String,
   pub(crate) content: Option<String>,
   pub(crate) media_type: Option<MediaTypeHtml>,