Change activity.cc to Vec<Url> in public activities
authorFelix Ableitner <me@nutomic.com>
Thu, 28 Oct 2021 12:47:56 +0000 (14:47 +0200)
committerFelix Ableitner <me@nutomic.com>
Fri, 29 Oct 2021 10:50:32 +0000 (12:50 +0200)
12 files changed:
crates/apub/src/activities/community/add_mod.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/mod.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

index 876fcc94ef31958c94c35e055429f365a675a596..11abb5ba58c74f7cf933cabeaa63725dd12ed89b 100644 (file)
@@ -45,7 +45,7 @@ pub struct AddMod {
   to: Vec<Url>,
   object: ObjectId<ApubPerson>,
   target: Url,
-  cc: [ObjectId<ApubCommunity>; 1],
+  cc: Vec<Url>,
   #[serde(rename = "type")]
   kind: AddType,
   id: Url,
@@ -71,7 +71,7 @@ impl AddMod {
       to: vec![public()],
       object: ObjectId::new(added_mod.actor_id()),
       target: generate_moderators_url(&community.actor_id)?.into(),
-      cc: [ObjectId::new(community.actor_id())],
+      cc: vec![community.actor_id()],
       kind: AddType::Add,
       id: id.clone(),
       context: lemmy_context(),
@@ -97,8 +97,8 @@ impl ActivityHandler for AddMod {
     verify_activity(self, &context.settings())?;
     let community = self.get_community(context, request_counter).await?;
     verify_person_in_community(&self.actor, &community, context, request_counter).await?;
-    verify_mod_action(&self.actor, &self.cc[0], context, request_counter).await?;
-    verify_add_remove_moderator_target(&self.target, &self.cc[0])?;
+    verify_mod_action(&self.actor, &community, context, request_counter).await?;
+    verify_add_remove_moderator_target(&self.target, &community)?;
     Ok(())
   }
 
index 35cde2e6ee521773a9a89695315435acd62871e6..21493214594a56cc43fda833fcf316150ae82a64 100644 (file)
@@ -46,7 +46,7 @@ pub struct BlockUserFromCommunity {
   actor: ObjectId<ApubPerson>,
   to: Vec<Url>,
   pub(in crate::activities::community) object: ObjectId<ApubPerson>,
-  cc: [ObjectId<ApubCommunity>; 1],
+  cc: Vec<Url>,
   target: ObjectId<ApubCommunity>,
   #[serde(rename = "type")]
   kind: BlockType,
@@ -68,7 +68,7 @@ impl BlockUserFromCommunity {
       actor: ObjectId::new(actor.actor_id()),
       to: vec![public()],
       object: ObjectId::new(target.actor_id()),
-      cc: [ObjectId::new(community.actor_id())],
+      cc: vec![community.actor_id()],
       target: ObjectId::new(community.actor_id()),
       kind: BlockType::Block,
       id: generate_activity_id(
@@ -107,7 +107,7 @@ impl ActivityHandler for BlockUserFromCommunity {
     verify_activity(self, &context.settings())?;
     let community = self.get_community(context, request_counter).await?;
     verify_person_in_community(&self.actor, &community, context, request_counter).await?;
-    verify_mod_action(&self.actor, &self.cc[0], context, request_counter).await?;
+    verify_mod_action(&self.actor, &community, context, request_counter).await?;
     Ok(())
   }
 
index f08ae9646d8ba69bcb9f30be256cd06e5cc3eb66..786740d53c03183bd723608d26d188c56a112553 100644 (file)
@@ -44,7 +44,7 @@ pub struct RemoveMod {
   actor: ObjectId<ApubPerson>,
   to: Vec<Url>,
   pub(in crate::activities) object: ObjectId<ApubPerson>,
-  cc: [ObjectId<ApubCommunity>; 1],
+  cc: Vec<Url>,
   #[serde(rename = "type")]
   kind: RemoveType,
   pub(in crate::activities) target: Url,
@@ -73,7 +73,7 @@ impl RemoveMod {
       target: generate_moderators_url(&community.actor_id)?.into(),
       id: id.clone(),
       context: lemmy_context(),
-      cc: [ObjectId::new(community.actor_id())],
+      cc: vec![community.actor_id()],
       kind: RemoveType::Remove,
       unparsed: Default::default(),
     };
@@ -96,8 +96,8 @@ impl ActivityHandler for RemoveMod {
     verify_activity(self, &context.settings())?;
     let community = self.get_community(context, request_counter).await?;
     verify_person_in_community(&self.actor, &community, context, request_counter).await?;
-    verify_mod_action(&self.actor, &self.cc[0], context, request_counter).await?;
-    verify_add_remove_moderator_target(&self.target, &self.cc[0])?;
+    verify_mod_action(&self.actor, &community, context, request_counter).await?;
+    verify_add_remove_moderator_target(&self.target, &community)?;
     Ok(())
   }
 
index c33c81e6ef76a0a1bf88b43c7574b9f5288b302d..b5e2a69cba20dba542164dbac73bf2b04b8016ae 100644 (file)
@@ -42,7 +42,7 @@ pub struct UndoBlockUserFromCommunity {
   actor: ObjectId<ApubPerson>,
   to: Vec<Url>,
   object: BlockUserFromCommunity,
-  cc: [ObjectId<ApubCommunity>; 1],
+  cc: Vec<Url>,
   #[serde(rename = "type")]
   kind: UndoType,
   id: Url,
@@ -69,7 +69,7 @@ impl UndoBlockUserFromCommunity {
       actor: ObjectId::new(actor.actor_id()),
       to: vec![public()],
       object: block,
-      cc: [ObjectId::new(community.actor_id())],
+      cc: vec![community.actor_id()],
       kind: UndoType::Undo,
       id: id.clone(),
       context: lemmy_context(),
@@ -94,7 +94,7 @@ impl ActivityHandler for UndoBlockUserFromCommunity {
     verify_activity(self, &context.settings())?;
     let community = self.get_community(context, request_counter).await?;
     verify_person_in_community(&self.actor, &community, context, request_counter).await?;
-    verify_mod_action(&self.actor, &self.cc[0], context, request_counter).await?;
+    verify_mod_action(&self.actor, &community, context, request_counter).await?;
     self.object.verify(context, request_counter).await?;
     Ok(())
   }
index 13837433581359a9b4cf4a7ab1eeaca2cac210e9..b5ad7f920c408b177ce22e410d49798e472d1cd4 100644 (file)
@@ -47,7 +47,7 @@ pub struct UpdateCommunity {
   to: Vec<Url>,
   // TODO: would be nice to use a separate struct here, which only contains the fields updated here
   object: Group,
-  cc: [ObjectId<ApubCommunity>; 1],
+  cc: Vec<Url>,
   #[serde(rename = "type")]
   kind: UpdateType,
   id: Url,
@@ -71,7 +71,7 @@ impl UpdateCommunity {
       actor: ObjectId::new(actor.actor_id()),
       to: vec![public()],
       object: community.to_apub(context).await?,
-      cc: [ObjectId::new(community.actor_id())],
+      cc: vec![community.actor_id()],
       kind: UpdateType::Update,
       id: id.clone(),
       context: lemmy_context(),
@@ -95,7 +95,7 @@ impl ActivityHandler for UpdateCommunity {
     verify_activity(self, &context.settings())?;
     let community = self.get_community(context, request_counter).await?;
     verify_person_in_community(&self.actor, &community, context, request_counter).await?;
-    verify_mod_action(&self.actor, &self.cc[0], context, request_counter).await?;
+    verify_mod_action(&self.actor, &community, context, request_counter).await?;
     Ok(())
   }
 
index 8797ed6b10940b96839e0f59615e8f3318ccedc0..2677ea901c59b2547c1e44a28b2169a1f99ae4c6 100644 (file)
@@ -72,7 +72,7 @@ pub struct Delete {
   actor: ObjectId<ApubPerson>,
   to: Vec<Url>,
   pub(in crate::activities::deletion) object: Url,
-  pub(in crate::activities::deletion) cc: [ObjectId<ApubCommunity>; 1],
+  pub(in crate::activities::deletion) cc: Vec<Url>,
   #[serde(rename = "type")]
   kind: DeleteType,
   /// If summary is present, this is a mod action (Remove in Lemmy terms). Otherwise, its a user
@@ -95,10 +95,11 @@ impl ActivityHandler for Delete {
   ) -> Result<(), LemmyError> {
     verify_is_public(&self.to)?;
     verify_activity(self, &context.settings())?;
+    let community = self.get_community(context, request_counter).await?;
     verify_delete_activity(
       &self.object,
       self,
-      &self.cc[0],
+      &community,
       self.summary.is_some(),
       context,
       request_counter,
@@ -151,7 +152,7 @@ impl Delete {
       actor: ObjectId::new(actor.actor_id()),
       to: vec![public()],
       object: object_id,
-      cc: [ObjectId::new(community.actor_id())],
+      cc: vec![community.actor_id()],
       kind: DeleteType::Delete,
       summary,
       id: generate_activity_id(
index f523ca71e8cce5bc2c317695bfedd96067c97192..1af02245904f17ddf4c7dfd0b473edadebf12ead 100644 (file)
@@ -82,7 +82,7 @@ impl DeletableObjects {
 pub(in crate::activities) async fn verify_delete_activity(
   object: &Url,
   activity: &dyn ActivityFields,
-  community_id: &ObjectId<ApubCommunity>,
+  community: &ApubCommunity,
   is_mod_action: bool,
   context: &LemmyContext,
   request_counter: &mut i32,
@@ -90,26 +90,20 @@ pub(in crate::activities) async fn verify_delete_activity(
   let object = DeletableObjects::read_from_db(object, context).await?;
   let actor = ObjectId::new(activity.actor().clone());
   match object {
-    DeletableObjects::Community(c) => {
-      if c.local {
+    DeletableObjects::Community(community) => {
+      if community.local {
         // can only do this check for local community, in remote case it would try to fetch the
         // deleted community (which fails)
-        verify_person_in_community(&actor, &c, context, request_counter).await?;
+        verify_person_in_community(&actor, &community, context, request_counter).await?;
       }
       // community deletion is always a mod (or admin) action
-      verify_mod_action(
-        &actor,
-        &ObjectId::new(c.actor_id()),
-        context,
-        request_counter,
-      )
-      .await?;
+      verify_mod_action(&actor, &community, context, request_counter).await?;
     }
     DeletableObjects::Post(p) => {
       verify_delete_activity_post_or_comment(
         activity,
         &p.ap_id.clone().into(),
-        community_id,
+        community,
         is_mod_action,
         context,
         request_counter,
@@ -120,7 +114,7 @@ pub(in crate::activities) async fn verify_delete_activity(
       verify_delete_activity_post_or_comment(
         activity,
         &c.ap_id.clone().into(),
-        community_id,
+        community,
         is_mod_action,
         context,
         request_counter,
@@ -134,16 +128,15 @@ pub(in crate::activities) async fn verify_delete_activity(
 async fn verify_delete_activity_post_or_comment(
   activity: &dyn ActivityFields,
   object_id: &Url,
-  community_id: &ObjectId<ApubCommunity>,
+  community: &ApubCommunity,
   is_mod_action: bool,
   context: &LemmyContext,
   request_counter: &mut i32,
 ) -> Result<(), LemmyError> {
   let actor = ObjectId::new(activity.actor().clone());
-  let community = community_id.dereference(context, request_counter).await?;
-  verify_person_in_community(&actor, &community, context, request_counter).await?;
+  verify_person_in_community(&actor, community, context, request_counter).await?;
   if is_mod_action {
-    verify_mod_action(&actor, community_id, context, request_counter).await?;
+    verify_mod_action(&actor, community, context, request_counter).await?;
   } else {
     // domain of post ap_id and post.creator ap_id are identical, so we just check the former
     verify_domains_match(activity.actor(), object_id)?;
index d2816b114ca84c603453804fc6a722b2558812f2..d881ab424373f1e70723ee218b28f7cab786906d 100644 (file)
@@ -48,7 +48,7 @@ pub struct UndoDelete {
   actor: ObjectId<ApubPerson>,
   to: Vec<Url>,
   object: Delete,
-  cc: [ObjectId<ApubCommunity>; 1],
+  cc: Vec<Url>,
   #[serde(rename = "type")]
   kind: UndoType,
   id: Url,
@@ -69,10 +69,11 @@ impl ActivityHandler for UndoDelete {
     verify_is_public(&self.to)?;
     verify_activity(self, &context.settings())?;
     self.object.verify(context, request_counter).await?;
+    let community = self.get_community(context, request_counter).await?;
     verify_delete_activity(
       &self.object.object,
       self,
-      &self.cc[0],
+      &community,
       self.object.summary.is_some(),
       context,
       request_counter,
@@ -124,7 +125,7 @@ impl UndoDelete {
       actor: ObjectId::new(actor.actor_id()),
       to: vec![public()],
       object,
-      cc: [ObjectId::new(community.actor_id())],
+      cc: vec![community.actor_id()],
       kind: UndoType::Undo,
       id: id.clone(),
       context: lemmy_context(),
index b180b6f3c9a3b3f6fc94c1a6f50eed1d224f38e2..63f79caa0d8e3c695062df8583f69d7d42288fff 100644 (file)
@@ -83,12 +83,10 @@ fn verify_activity(activity: &dyn ActivityFields, settings: &Settings) -> Result
 /// is not federated, we cant verify their actions remotely.
 pub(crate) async fn verify_mod_action(
   actor_id: &ObjectId<ApubPerson>,
-  community_id: &ObjectId<ApubCommunity>,
+  community: &ApubCommunity,
   context: &LemmyContext,
   request_counter: &mut i32,
 ) -> Result<(), LemmyError> {
-  let community = community_id.dereference_local(context).await?;
-
   if community.local {
     let actor = actor_id.dereference(context, request_counter).await?;
 
@@ -111,9 +109,9 @@ pub(crate) async fn verify_mod_action(
 /// /c/community/moderators. Any different values are unsupported.
 fn verify_add_remove_moderator_target(
   target: &Url,
-  community: &ObjectId<ApubCommunity>,
+  community: &ApubCommunity,
 ) -> Result<(), LemmyError> {
-  if target != &generate_moderators_url(&community.clone().into())?.into_inner() {
+  if target != &generate_moderators_url(&community.actor_id)?.into_inner() {
     return Err(anyhow!("Unkown target url").into());
   }
   Ok(())
index b18d100e0894db254e225edcaf37a1f3e54c94c6..44498823e4a69ee7fd1164477fe6e534c330fb3d 100644 (file)
@@ -40,7 +40,7 @@ pub struct CreateOrUpdatePost {
   actor: ObjectId<ApubPerson>,
   to: Vec<Url>,
   object: Page,
-  cc: [ObjectId<ApubCommunity>; 1],
+  cc: Vec<Url>,
   #[serde(rename = "type")]
   kind: CreateOrUpdateType,
   id: Url,
@@ -66,7 +66,7 @@ impl CreateOrUpdatePost {
       actor: ObjectId::new(actor.actor_id()),
       to: vec![public()],
       object: post.to_apub(context).await?,
-      cc: [ObjectId::new(community.actor_id())],
+      cc: vec![community.actor_id()],
       kind,
       id: id.clone(),
       context: lemmy_context(),
@@ -123,7 +123,7 @@ impl ActivityHandler for CreateOrUpdatePost {
       CreateOrUpdateType::Update => {
         let is_mod_action = self.object.is_mod_action(context).await?;
         if is_mod_action {
-          verify_mod_action(&self.actor, &self.cc[0], context, request_counter).await?;
+          verify_mod_action(&self.actor, &community, context, request_counter).await?;
         } else {
           verify_domains_match(self.actor.inner(), self.object.id_unchecked())?;
           verify_urls_match(self.actor(), self.object.attributed_to.inner())?;
index 6d63e90530153a6549743ef3543424122bfd4a4f..144cbfc1819c545f691bcc47ccce7264e3499ec3 100644 (file)
@@ -45,7 +45,7 @@ pub struct UndoVote {
   actor: ObjectId<ApubPerson>,
   to: Vec<Url>,
   object: Vote,
-  cc: [ObjectId<ApubCommunity>; 1],
+  cc: Vec<Url>,
   #[serde(rename = "type")]
   kind: UndoType,
   id: Url,
@@ -78,7 +78,7 @@ impl UndoVote {
       actor: ObjectId::new(actor.actor_id()),
       to: vec![public()],
       object,
-      cc: [ObjectId::new(community.actor_id())],
+      cc: vec![community.actor_id()],
       kind: UndoType::Undo,
       id: id.clone(),
       context: lemmy_context(),
index 4d6697283b9ffa7ce2b706e151b54b348fc6beeb..5b08390fa45fbd332bf90f424b26c99734703d6a 100644 (file)
@@ -67,7 +67,7 @@ pub struct Vote {
   actor: ObjectId<ApubPerson>,
   to: Vec<Url>,
   pub(in crate::activities::voting) object: ObjectId<PostOrComment>,
-  cc: [ObjectId<ApubCommunity>; 1],
+  cc: Vec<Url>,
   #[serde(rename = "type")]
   pub(in crate::activities::voting) kind: VoteType,
   id: Url,
@@ -89,7 +89,7 @@ impl Vote {
       actor: ObjectId::new(actor.actor_id()),
       to: vec![public()],
       object: ObjectId::new(object.ap_id()),
-      cc: [ObjectId::new(community.actor_id())],
+      cc: vec![community.actor_id()],
       kind: kind.clone(),
       id: generate_activity_id(kind, &context.settings().get_protocol_and_hostname())?,
       context: lemmy_context(),