From: Felix Ableitner Date: Thu, 28 Oct 2021 12:47:56 +0000 (+0200) Subject: Change activity.cc to Vec in public activities X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%7B?a=commitdiff_plain;h=2d04ff93f5ccdb8d5e7af54aaabec796d8fe96a8;p=lemmy.git Change activity.cc to Vec in public activities --- diff --git a/crates/apub/src/activities/community/add_mod.rs b/crates/apub/src/activities/community/add_mod.rs index 876fcc94..11abb5ba 100644 --- a/crates/apub/src/activities/community/add_mod.rs +++ b/crates/apub/src/activities/community/add_mod.rs @@ -45,7 +45,7 @@ pub struct AddMod { to: Vec, object: ObjectId, target: Url, - cc: [ObjectId; 1], + cc: Vec, #[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(()) } diff --git a/crates/apub/src/activities/community/block_user.rs b/crates/apub/src/activities/community/block_user.rs index 35cde2e6..21493214 100644 --- a/crates/apub/src/activities/community/block_user.rs +++ b/crates/apub/src/activities/community/block_user.rs @@ -46,7 +46,7 @@ pub struct BlockUserFromCommunity { actor: ObjectId, to: Vec, pub(in crate::activities::community) object: ObjectId, - cc: [ObjectId; 1], + cc: Vec, target: ObjectId, #[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(()) } diff --git a/crates/apub/src/activities/community/remove_mod.rs b/crates/apub/src/activities/community/remove_mod.rs index f08ae964..786740d5 100644 --- a/crates/apub/src/activities/community/remove_mod.rs +++ b/crates/apub/src/activities/community/remove_mod.rs @@ -44,7 +44,7 @@ pub struct RemoveMod { actor: ObjectId, to: Vec, pub(in crate::activities) object: ObjectId, - cc: [ObjectId; 1], + cc: Vec, #[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(()) } diff --git a/crates/apub/src/activities/community/undo_block_user.rs b/crates/apub/src/activities/community/undo_block_user.rs index c33c81e6..b5e2a69c 100644 --- a/crates/apub/src/activities/community/undo_block_user.rs +++ b/crates/apub/src/activities/community/undo_block_user.rs @@ -42,7 +42,7 @@ pub struct UndoBlockUserFromCommunity { actor: ObjectId, to: Vec, object: BlockUserFromCommunity, - cc: [ObjectId; 1], + cc: Vec, #[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(()) } diff --git a/crates/apub/src/activities/community/update.rs b/crates/apub/src/activities/community/update.rs index 13837433..b5ad7f92 100644 --- a/crates/apub/src/activities/community/update.rs +++ b/crates/apub/src/activities/community/update.rs @@ -47,7 +47,7 @@ pub struct UpdateCommunity { to: Vec, // TODO: would be nice to use a separate struct here, which only contains the fields updated here object: Group, - cc: [ObjectId; 1], + cc: Vec, #[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(()) } diff --git a/crates/apub/src/activities/deletion/delete.rs b/crates/apub/src/activities/deletion/delete.rs index 8797ed6b..2677ea90 100644 --- a/crates/apub/src/activities/deletion/delete.rs +++ b/crates/apub/src/activities/deletion/delete.rs @@ -72,7 +72,7 @@ pub struct Delete { actor: ObjectId, to: Vec, pub(in crate::activities::deletion) object: Url, - pub(in crate::activities::deletion) cc: [ObjectId; 1], + pub(in crate::activities::deletion) cc: Vec, #[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( diff --git a/crates/apub/src/activities/deletion/mod.rs b/crates/apub/src/activities/deletion/mod.rs index f523ca71..1af02245 100644 --- a/crates/apub/src/activities/deletion/mod.rs +++ b/crates/apub/src/activities/deletion/mod.rs @@ -82,7 +82,7 @@ impl DeletableObjects { pub(in crate::activities) async fn verify_delete_activity( object: &Url, activity: &dyn ActivityFields, - community_id: &ObjectId, + 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, + 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)?; diff --git a/crates/apub/src/activities/deletion/undo_delete.rs b/crates/apub/src/activities/deletion/undo_delete.rs index d2816b11..d881ab42 100644 --- a/crates/apub/src/activities/deletion/undo_delete.rs +++ b/crates/apub/src/activities/deletion/undo_delete.rs @@ -48,7 +48,7 @@ pub struct UndoDelete { actor: ObjectId, to: Vec, object: Delete, - cc: [ObjectId; 1], + cc: Vec, #[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(), diff --git a/crates/apub/src/activities/mod.rs b/crates/apub/src/activities/mod.rs index b180b6f3..63f79caa 100644 --- a/crates/apub/src/activities/mod.rs +++ b/crates/apub/src/activities/mod.rs @@ -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, - community_id: &ObjectId, + 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, + 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(()) diff --git a/crates/apub/src/activities/post/create_or_update.rs b/crates/apub/src/activities/post/create_or_update.rs index b18d100e..44498823 100644 --- a/crates/apub/src/activities/post/create_or_update.rs +++ b/crates/apub/src/activities/post/create_or_update.rs @@ -40,7 +40,7 @@ pub struct CreateOrUpdatePost { actor: ObjectId, to: Vec, object: Page, - cc: [ObjectId; 1], + cc: Vec, #[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())?; diff --git a/crates/apub/src/activities/voting/undo_vote.rs b/crates/apub/src/activities/voting/undo_vote.rs index 6d63e905..144cbfc1 100644 --- a/crates/apub/src/activities/voting/undo_vote.rs +++ b/crates/apub/src/activities/voting/undo_vote.rs @@ -45,7 +45,7 @@ pub struct UndoVote { actor: ObjectId, to: Vec, object: Vote, - cc: [ObjectId; 1], + cc: Vec, #[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(), diff --git a/crates/apub/src/activities/voting/vote.rs b/crates/apub/src/activities/voting/vote.rs index 4d669728..5b08390f 100644 --- a/crates/apub/src/activities/voting/vote.rs +++ b/crates/apub/src/activities/voting/vote.rs @@ -67,7 +67,7 @@ pub struct Vote { actor: ObjectId, to: Vec, pub(in crate::activities::voting) object: ObjectId, - cc: [ObjectId; 1], + cc: Vec, #[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(),