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

This commit is contained in:
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>,
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(())
}

View 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(())
}

View 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(())
}

View 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(())
}

View 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(())
}

View 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(

View 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)?;

View 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(),

View 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(())

View 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())?;

View 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(),

View 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(),