Change activity.cc to Vec<Url> in public activities

pleroma-compat
Felix Ableitner 2021-10-28 14:47:56 +02:00
parent 271785b7fb
commit 2d04ff93f5
12 changed files with 45 additions and 52 deletions

View File

@ -45,7 +45,7 @@ pub struct AddMod {
to: Vec<Url>, to: Vec<Url>,
object: ObjectId<ApubPerson>, object: ObjectId<ApubPerson>,
target: Url, target: Url,
cc: [ObjectId<ApubCommunity>; 1], cc: Vec<Url>,
#[serde(rename = "type")] #[serde(rename = "type")]
kind: AddType, kind: AddType,
id: Url, id: Url,
@ -71,7 +71,7 @@ impl AddMod {
to: vec![public()], to: vec![public()],
object: ObjectId::new(added_mod.actor_id()), object: ObjectId::new(added_mod.actor_id()),
target: generate_moderators_url(&community.actor_id)?.into(), target: generate_moderators_url(&community.actor_id)?.into(),
cc: [ObjectId::new(community.actor_id())], cc: vec![community.actor_id()],
kind: AddType::Add, kind: AddType::Add,
id: id.clone(), id: id.clone(),
context: lemmy_context(), context: lemmy_context(),
@ -97,8 +97,8 @@ impl ActivityHandler for AddMod {
verify_activity(self, &context.settings())?; verify_activity(self, &context.settings())?;
let community = self.get_community(context, request_counter).await?; let community = self.get_community(context, request_counter).await?;
verify_person_in_community(&self.actor, &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?;
verify_add_remove_moderator_target(&self.target, &self.cc[0])?; verify_add_remove_moderator_target(&self.target, &community)?;
Ok(()) Ok(())
} }

View File

@ -46,7 +46,7 @@ pub struct BlockUserFromCommunity {
actor: ObjectId<ApubPerson>, actor: ObjectId<ApubPerson>,
to: Vec<Url>, to: Vec<Url>,
pub(in crate::activities::community) object: ObjectId<ApubPerson>, pub(in crate::activities::community) object: ObjectId<ApubPerson>,
cc: [ObjectId<ApubCommunity>; 1], cc: Vec<Url>,
target: ObjectId<ApubCommunity>, target: ObjectId<ApubCommunity>,
#[serde(rename = "type")] #[serde(rename = "type")]
kind: BlockType, kind: BlockType,
@ -68,7 +68,7 @@ impl BlockUserFromCommunity {
actor: ObjectId::new(actor.actor_id()), actor: ObjectId::new(actor.actor_id()),
to: vec![public()], to: vec![public()],
object: ObjectId::new(target.actor_id()), object: ObjectId::new(target.actor_id()),
cc: [ObjectId::new(community.actor_id())], cc: vec![community.actor_id()],
target: ObjectId::new(community.actor_id()), target: ObjectId::new(community.actor_id()),
kind: BlockType::Block, kind: BlockType::Block,
id: generate_activity_id( id: generate_activity_id(
@ -107,7 +107,7 @@ impl ActivityHandler for BlockUserFromCommunity {
verify_activity(self, &context.settings())?; verify_activity(self, &context.settings())?;
let community = self.get_community(context, request_counter).await?; let community = self.get_community(context, request_counter).await?;
verify_person_in_community(&self.actor, &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(()) Ok(())
} }

View File

@ -44,7 +44,7 @@ pub struct RemoveMod {
actor: ObjectId<ApubPerson>, actor: ObjectId<ApubPerson>,
to: Vec<Url>, to: Vec<Url>,
pub(in crate::activities) object: ObjectId<ApubPerson>, pub(in crate::activities) object: ObjectId<ApubPerson>,
cc: [ObjectId<ApubCommunity>; 1], cc: Vec<Url>,
#[serde(rename = "type")] #[serde(rename = "type")]
kind: RemoveType, kind: RemoveType,
pub(in crate::activities) target: Url, pub(in crate::activities) target: Url,
@ -73,7 +73,7 @@ impl RemoveMod {
target: generate_moderators_url(&community.actor_id)?.into(), target: generate_moderators_url(&community.actor_id)?.into(),
id: id.clone(), id: id.clone(),
context: lemmy_context(), context: lemmy_context(),
cc: [ObjectId::new(community.actor_id())], cc: vec![community.actor_id()],
kind: RemoveType::Remove, kind: RemoveType::Remove,
unparsed: Default::default(), unparsed: Default::default(),
}; };
@ -96,8 +96,8 @@ impl ActivityHandler for RemoveMod {
verify_activity(self, &context.settings())?; verify_activity(self, &context.settings())?;
let community = self.get_community(context, request_counter).await?; let community = self.get_community(context, request_counter).await?;
verify_person_in_community(&self.actor, &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?;
verify_add_remove_moderator_target(&self.target, &self.cc[0])?; verify_add_remove_moderator_target(&self.target, &community)?;
Ok(()) Ok(())
} }

View File

@ -42,7 +42,7 @@ pub struct UndoBlockUserFromCommunity {
actor: ObjectId<ApubPerson>, actor: ObjectId<ApubPerson>,
to: Vec<Url>, to: Vec<Url>,
object: BlockUserFromCommunity, object: BlockUserFromCommunity,
cc: [ObjectId<ApubCommunity>; 1], cc: Vec<Url>,
#[serde(rename = "type")] #[serde(rename = "type")]
kind: UndoType, kind: UndoType,
id: Url, id: Url,
@ -69,7 +69,7 @@ impl UndoBlockUserFromCommunity {
actor: ObjectId::new(actor.actor_id()), actor: ObjectId::new(actor.actor_id()),
to: vec![public()], to: vec![public()],
object: block, object: block,
cc: [ObjectId::new(community.actor_id())], cc: vec![community.actor_id()],
kind: UndoType::Undo, kind: UndoType::Undo,
id: id.clone(), id: id.clone(),
context: lemmy_context(), context: lemmy_context(),
@ -94,7 +94,7 @@ impl ActivityHandler for UndoBlockUserFromCommunity {
verify_activity(self, &context.settings())?; verify_activity(self, &context.settings())?;
let community = self.get_community(context, request_counter).await?; let community = self.get_community(context, request_counter).await?;
verify_person_in_community(&self.actor, &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?; self.object.verify(context, request_counter).await?;
Ok(()) Ok(())
} }

View File

@ -47,7 +47,7 @@ pub struct UpdateCommunity {
to: Vec<Url>, to: Vec<Url>,
// TODO: would be nice to use a separate struct here, which only contains the fields updated here // TODO: would be nice to use a separate struct here, which only contains the fields updated here
object: Group, object: Group,
cc: [ObjectId<ApubCommunity>; 1], cc: Vec<Url>,
#[serde(rename = "type")] #[serde(rename = "type")]
kind: UpdateType, kind: UpdateType,
id: Url, id: Url,
@ -71,7 +71,7 @@ impl UpdateCommunity {
actor: ObjectId::new(actor.actor_id()), actor: ObjectId::new(actor.actor_id()),
to: vec![public()], to: vec![public()],
object: community.to_apub(context).await?, object: community.to_apub(context).await?,
cc: [ObjectId::new(community.actor_id())], cc: vec![community.actor_id()],
kind: UpdateType::Update, kind: UpdateType::Update,
id: id.clone(), id: id.clone(),
context: lemmy_context(), context: lemmy_context(),
@ -95,7 +95,7 @@ impl ActivityHandler for UpdateCommunity {
verify_activity(self, &context.settings())?; verify_activity(self, &context.settings())?;
let community = self.get_community(context, request_counter).await?; let community = self.get_community(context, request_counter).await?;
verify_person_in_community(&self.actor, &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(()) Ok(())
} }

View File

@ -72,7 +72,7 @@ pub struct Delete {
actor: ObjectId<ApubPerson>, actor: ObjectId<ApubPerson>,
to: Vec<Url>, to: Vec<Url>,
pub(in crate::activities::deletion) object: 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")] #[serde(rename = "type")]
kind: DeleteType, kind: DeleteType,
/// If summary is present, this is a mod action (Remove in Lemmy terms). Otherwise, its a user /// 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> { ) -> Result<(), LemmyError> {
verify_is_public(&self.to)?; verify_is_public(&self.to)?;
verify_activity(self, &context.settings())?; verify_activity(self, &context.settings())?;
let community = self.get_community(context, request_counter).await?;
verify_delete_activity( verify_delete_activity(
&self.object, &self.object,
self, self,
&self.cc[0], &community,
self.summary.is_some(), self.summary.is_some(),
context, context,
request_counter, request_counter,
@ -151,7 +152,7 @@ impl Delete {
actor: ObjectId::new(actor.actor_id()), actor: ObjectId::new(actor.actor_id()),
to: vec![public()], to: vec![public()],
object: object_id, object: object_id,
cc: [ObjectId::new(community.actor_id())], cc: vec![community.actor_id()],
kind: DeleteType::Delete, kind: DeleteType::Delete,
summary, summary,
id: generate_activity_id( id: generate_activity_id(

View File

@ -82,7 +82,7 @@ impl DeletableObjects {
pub(in crate::activities) async fn verify_delete_activity( pub(in crate::activities) async fn verify_delete_activity(
object: &Url, object: &Url,
activity: &dyn ActivityFields, activity: &dyn ActivityFields,
community_id: &ObjectId<ApubCommunity>, community: &ApubCommunity,
is_mod_action: bool, is_mod_action: bool,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, 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 object = DeletableObjects::read_from_db(object, context).await?;
let actor = ObjectId::new(activity.actor().clone()); let actor = ObjectId::new(activity.actor().clone());
match object { match object {
DeletableObjects::Community(c) => { DeletableObjects::Community(community) => {
if c.local { if community.local {
// can only do this check for local community, in remote case it would try to fetch the // can only do this check for local community, in remote case it would try to fetch the
// deleted community (which fails) // 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 // community deletion is always a mod (or admin) action
verify_mod_action( verify_mod_action(&actor, &community, context, request_counter).await?;
&actor,
&ObjectId::new(c.actor_id()),
context,
request_counter,
)
.await?;
} }
DeletableObjects::Post(p) => { DeletableObjects::Post(p) => {
verify_delete_activity_post_or_comment( verify_delete_activity_post_or_comment(
activity, activity,
&p.ap_id.clone().into(), &p.ap_id.clone().into(),
community_id, community,
is_mod_action, is_mod_action,
context, context,
request_counter, request_counter,
@ -120,7 +114,7 @@ pub(in crate::activities) async fn verify_delete_activity(
verify_delete_activity_post_or_comment( verify_delete_activity_post_or_comment(
activity, activity,
&c.ap_id.clone().into(), &c.ap_id.clone().into(),
community_id, community,
is_mod_action, is_mod_action,
context, context,
request_counter, request_counter,
@ -134,16 +128,15 @@ pub(in crate::activities) async fn verify_delete_activity(
async fn verify_delete_activity_post_or_comment( async fn verify_delete_activity_post_or_comment(
activity: &dyn ActivityFields, activity: &dyn ActivityFields,
object_id: &Url, object_id: &Url,
community_id: &ObjectId<ApubCommunity>, community: &ApubCommunity,
is_mod_action: bool, is_mod_action: bool,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let actor = ObjectId::new(activity.actor().clone()); 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 { if is_mod_action {
verify_mod_action(&actor, community_id, context, request_counter).await?; verify_mod_action(&actor, community, context, request_counter).await?;
} else { } else {
// domain of post ap_id and post.creator ap_id are identical, so we just check the former // 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)?; verify_domains_match(activity.actor(), object_id)?;

View File

@ -48,7 +48,7 @@ pub struct UndoDelete {
actor: ObjectId<ApubPerson>, actor: ObjectId<ApubPerson>,
to: Vec<Url>, to: Vec<Url>,
object: Delete, object: Delete,
cc: [ObjectId<ApubCommunity>; 1], cc: Vec<Url>,
#[serde(rename = "type")] #[serde(rename = "type")]
kind: UndoType, kind: UndoType,
id: Url, id: Url,
@ -69,10 +69,11 @@ impl ActivityHandler for UndoDelete {
verify_is_public(&self.to)?; verify_is_public(&self.to)?;
verify_activity(self, &context.settings())?; verify_activity(self, &context.settings())?;
self.object.verify(context, request_counter).await?; self.object.verify(context, request_counter).await?;
let community = self.get_community(context, request_counter).await?;
verify_delete_activity( verify_delete_activity(
&self.object.object, &self.object.object,
self, self,
&self.cc[0], &community,
self.object.summary.is_some(), self.object.summary.is_some(),
context, context,
request_counter, request_counter,
@ -124,7 +125,7 @@ impl UndoDelete {
actor: ObjectId::new(actor.actor_id()), actor: ObjectId::new(actor.actor_id()),
to: vec![public()], to: vec![public()],
object, object,
cc: [ObjectId::new(community.actor_id())], cc: vec![community.actor_id()],
kind: UndoType::Undo, kind: UndoType::Undo,
id: id.clone(), id: id.clone(),
context: lemmy_context(), context: lemmy_context(),

View File

@ -83,12 +83,10 @@ fn verify_activity(activity: &dyn ActivityFields, settings: &Settings) -> Result
/// is not federated, we cant verify their actions remotely. /// is not federated, we cant verify their actions remotely.
pub(crate) async fn verify_mod_action( pub(crate) async fn verify_mod_action(
actor_id: &ObjectId<ApubPerson>, actor_id: &ObjectId<ApubPerson>,
community_id: &ObjectId<ApubCommunity>, community: &ApubCommunity,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let community = community_id.dereference_local(context).await?;
if community.local { if community.local {
let actor = actor_id.dereference(context, request_counter).await?; 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. /// /c/community/moderators. Any different values are unsupported.
fn verify_add_remove_moderator_target( fn verify_add_remove_moderator_target(
target: &Url, target: &Url,
community: &ObjectId<ApubCommunity>, community: &ApubCommunity,
) -> Result<(), LemmyError> { ) -> 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()); return Err(anyhow!("Unkown target url").into());
} }
Ok(()) Ok(())

View File

@ -40,7 +40,7 @@ pub struct CreateOrUpdatePost {
actor: ObjectId<ApubPerson>, actor: ObjectId<ApubPerson>,
to: Vec<Url>, to: Vec<Url>,
object: Page, object: Page,
cc: [ObjectId<ApubCommunity>; 1], cc: Vec<Url>,
#[serde(rename = "type")] #[serde(rename = "type")]
kind: CreateOrUpdateType, kind: CreateOrUpdateType,
id: Url, id: Url,
@ -66,7 +66,7 @@ impl CreateOrUpdatePost {
actor: ObjectId::new(actor.actor_id()), actor: ObjectId::new(actor.actor_id()),
to: vec![public()], to: vec![public()],
object: post.to_apub(context).await?, object: post.to_apub(context).await?,
cc: [ObjectId::new(community.actor_id())], cc: vec![community.actor_id()],
kind, kind,
id: id.clone(), id: id.clone(),
context: lemmy_context(), context: lemmy_context(),
@ -123,7 +123,7 @@ impl ActivityHandler for CreateOrUpdatePost {
CreateOrUpdateType::Update => { CreateOrUpdateType::Update => {
let is_mod_action = self.object.is_mod_action(context).await?; let is_mod_action = self.object.is_mod_action(context).await?;
if is_mod_action { 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 { } else {
verify_domains_match(self.actor.inner(), self.object.id_unchecked())?; verify_domains_match(self.actor.inner(), self.object.id_unchecked())?;
verify_urls_match(self.actor(), self.object.attributed_to.inner())?; verify_urls_match(self.actor(), self.object.attributed_to.inner())?;

View File

@ -45,7 +45,7 @@ pub struct UndoVote {
actor: ObjectId<ApubPerson>, actor: ObjectId<ApubPerson>,
to: Vec<Url>, to: Vec<Url>,
object: Vote, object: Vote,
cc: [ObjectId<ApubCommunity>; 1], cc: Vec<Url>,
#[serde(rename = "type")] #[serde(rename = "type")]
kind: UndoType, kind: UndoType,
id: Url, id: Url,
@ -78,7 +78,7 @@ impl UndoVote {
actor: ObjectId::new(actor.actor_id()), actor: ObjectId::new(actor.actor_id()),
to: vec![public()], to: vec![public()],
object, object,
cc: [ObjectId::new(community.actor_id())], cc: vec![community.actor_id()],
kind: UndoType::Undo, kind: UndoType::Undo,
id: id.clone(), id: id.clone(),
context: lemmy_context(), context: lemmy_context(),

View File

@ -67,7 +67,7 @@ pub struct Vote {
actor: ObjectId<ApubPerson>, actor: ObjectId<ApubPerson>,
to: Vec<Url>, to: Vec<Url>,
pub(in crate::activities::voting) object: ObjectId<PostOrComment>, pub(in crate::activities::voting) object: ObjectId<PostOrComment>,
cc: [ObjectId<ApubCommunity>; 1], cc: Vec<Url>,
#[serde(rename = "type")] #[serde(rename = "type")]
pub(in crate::activities::voting) kind: VoteType, pub(in crate::activities::voting) kind: VoteType,
id: Url, id: Url,
@ -89,7 +89,7 @@ impl Vote {
actor: ObjectId::new(actor.actor_id()), actor: ObjectId::new(actor.actor_id()),
to: vec![public()], to: vec![public()],
object: ObjectId::new(object.ap_id()), object: ObjectId::new(object.ap_id()),
cc: [ObjectId::new(community.actor_id())], cc: vec![community.actor_id()],
kind: kind.clone(), kind: kind.clone(),
id: generate_activity_id(kind, &context.settings().get_protocol_and_hostname())?, id: generate_activity_id(kind, &context.settings().get_protocol_and_hostname())?,
context: lemmy_context(), context: lemmy_context(),