add cc field for all activities which i forgot before

This commit is contained in:
Felix Ableitner 2021-06-27 05:41:56 +02:00
parent 27c12ce411
commit 074febb960
19 changed files with 43 additions and 39 deletions

View file

@ -16,6 +16,7 @@ pub struct CreateComment {
actor: Url,
to: PublicUrl,
object: NoteExt,
cc: Vec<Url>,
#[serde(rename = "type")]
kind: CreateType,
}

View file

@ -15,7 +15,7 @@ pub struct DeleteComment {
actor: Url,
to: PublicUrl,
object: Url,
cc: Vec<Url>,
cc: [Url; 1],
#[serde(rename = "type")]
kind: DeleteType,
}

View file

@ -12,7 +12,7 @@ pub struct DislikeComment {
actor: Url,
to: PublicUrl,
object: Url,
cc: Vec<Url>,
cc: [Url; 1],
#[serde(rename = "type")]
kind: DislikeType,
}

View file

@ -12,7 +12,7 @@ pub struct LikeComment {
actor: Url,
to: PublicUrl,
object: Url,
cc: Vec<Url>,
cc: [Url; 1],
#[serde(rename = "type")]
kind: LikeType,
}

View file

@ -18,7 +18,7 @@ pub struct RemoveComment {
actor: Url,
to: PublicUrl,
object: Url,
cc: Vec<Url>,
cc: [Url; 1],
#[serde(rename = "type")]
kind: RemoveType,
}
@ -28,7 +28,7 @@ impl VerifyActivity for Activity<RemoveComment> {
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.inner.actor, self.id_unchecked())?;
check_is_apub_id_valid(&self.inner.actor, false)?;
verify_mod_action(self.inner.actor.clone(), self.inner.cc.clone(), context).await
verify_mod_action(self.inner.actor.clone(), self.inner.cc[0].clone(), context).await
}
}

View file

@ -16,6 +16,7 @@ pub struct UpdateComment {
actor: Url,
to: PublicUrl,
object: NoteExt,
cc: Vec<Url>,
#[serde(rename = "type")]
kind: UpdateType,
}

View file

@ -26,7 +26,7 @@ pub struct DeleteCommunity {
actor: Url,
to: PublicUrl,
pub(in crate::activities_new::community) object: Url,
cc: Url,
cc: [Url; 1],
#[serde(rename = "type")]
kind: DeleteType,
}
@ -41,14 +41,14 @@ impl VerifyActivity for Activity<DeleteCommunity> {
.await?;
// remote mod action on local community
if let Ok(c) = community {
verify_domains_match(&self.inner.object, &self.inner.cc)?;
verify_domains_match(&self.inner.object, &self.inner.cc[0])?;
check_is_apub_id_valid(&self.inner.actor, false)?;
verify_is_community_mod(self.inner.actor.clone(), c.actor_id(), context).await
}
// community action sent to followers
else {
verify_domains_match(&self.inner.actor, &self.inner.object)?;
verify_domains_match(&self.inner.actor, &self.inner.cc)
verify_domains_match(&self.inner.actor, &self.inner.cc[0])
}
}
}

View file

@ -18,7 +18,7 @@ pub struct RemoveCommunity {
actor: Url,
to: PublicUrl,
pub(in crate::activities_new::community) object: Url,
cc: Url,
cc: [Url; 1],
#[serde(rename = "type")]
kind: RemoveType,
}
@ -28,7 +28,7 @@ impl VerifyActivity for Activity<RemoveCommunity> {
async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
check_is_apub_id_valid(&self.inner.actor, false)?;
verify_domains_match(&self.inner.actor, &self.inner.object)?;
verify_domains_match(&self.inner.actor, &self.inner.cc)
verify_domains_match(&self.inner.actor, &self.inner.cc[0])
}
}

View file

@ -30,7 +30,7 @@ pub struct UndoDeleteCommunity {
actor: Url,
to: PublicUrl,
object: Activity<DeleteCommunity>,
cc: Url,
cc: [Url; 1],
#[serde(rename = "type")]
kind: DeleteType,
}
@ -45,14 +45,14 @@ impl VerifyActivity for Activity<UndoDeleteCommunity> {
.await?;
// remote mod action on local community
if let Ok(c) = community {
verify_domains_match(&self.inner.object.inner.object, &self.inner.cc)?;
verify_domains_match(&self.inner.object.inner.object, &self.inner.cc[0])?;
check_is_apub_id_valid(&self.inner.actor, false)?;
verify_is_community_mod(self.inner.actor.clone(), c.actor_id(), context).await?;
}
// community action sent to followers
else {
verify_domains_match(&self.inner.actor, &self.inner.object.inner.object)?;
verify_domains_match(&self.inner.actor, &self.inner.cc)?;
verify_domains_match(&self.inner.actor, &self.inner.cc[0])?;
}
self.inner.object.verify(context).await
}

View file

@ -18,7 +18,7 @@ pub struct UndoRemoveCommunity {
actor: Url,
to: PublicUrl,
object: Activity<RemoveCommunity>,
cc: Url,
cc: [Url; 1],
#[serde(rename = "type")]
kind: RemoveType,
}
@ -28,7 +28,7 @@ impl VerifyActivity for Activity<UndoRemoveCommunity> {
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
check_is_apub_id_valid(&self.inner.actor, false)?;
verify_domains_match(&self.inner.actor, &self.inner.object.inner.object)?;
verify_domains_match(&self.inner.actor, &self.inner.cc)?;
verify_domains_match(&self.inner.actor, &self.inner.cc[0])?;
self.inner.object.verify(context).await
}
}

View file

@ -20,7 +20,7 @@ pub struct UpdateCommunity {
actor: Url,
to: PublicUrl,
object: GroupExt,
cc: Url,
cc: [Url; 1],
#[serde(rename = "type")]
kind: UpdateType,
}
@ -28,9 +28,9 @@ pub struct UpdateCommunity {
#[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UpdateCommunity> {
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
self.inner.object.id(self.inner.cc.as_str())?;
self.inner.object.id(self.inner.cc[0].as_str())?;
check_is_apub_id_valid(&self.inner.actor, false)?;
verify_is_community_mod(self.inner.actor.clone(), self.inner.cc.clone(), context).await
verify_is_community_mod(self.inner.actor.clone(), self.inner.cc[0].clone(), context).await
}
}
@ -41,7 +41,7 @@ impl ReceiveActivity for Activity<UpdateCommunity> {
context: &LemmyContext,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
let cc = self.inner.cc.clone().into();
let cc = self.inner.cc[0].clone().into();
let community = blocking(context.pool(), move |conn| {
Community::read_from_apub_id(conn, &cc)
})

View file

@ -1,9 +1,9 @@
use anyhow::{anyhow, Context};
use anyhow::anyhow;
use lemmy_api_common::blocking;
use lemmy_db_queries::ApubObject;
use lemmy_db_schema::source::{community::Community, person::Person};
use lemmy_db_views_actor::community_view::CommunityView;
use lemmy_utils::{location_info, LemmyError};
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
use url::Url;
@ -15,20 +15,13 @@ pub mod private_message;
async fn verify_mod_action(
actor_id: Url,
activity_cc: Vec<Url>,
activity_cc: Url,
context: &LemmyContext,
) -> Result<(), LemmyError> {
let mut cc = activity_cc.into_iter();
let community: Community = loop {
let current = cc.next().context(location_info!())?;
let community = blocking(context.pool(), move |conn| {
Community::read_from_apub_id(conn, &current.into())
Community::read_from_apub_id(conn, &activity_cc.into())
})
.await?;
if let Ok(c) = community {
break c;
}
};
.await??;
if community.local {
let actor = blocking(&context.pool(), move |conn| {

View file

@ -19,6 +19,7 @@ pub struct CreatePost {
actor: Url,
to: PublicUrl,
object: PageExt,
cc: Vec<Url>,
#[serde(rename = "type")]
kind: CreateType,
}

View file

@ -15,6 +15,7 @@ pub struct DeletePost {
actor: Url,
to: PublicUrl,
object: Url,
cc: [Url; 1],
#[serde(rename = "type")]
kind: DeleteType,
}

View file

@ -12,6 +12,7 @@ pub struct DislikePost {
actor: Url,
to: PublicUrl,
object: Url,
cc: [Url; 1],
#[serde(rename = "type")]
kind: DislikeType,
}

View file

@ -12,6 +12,7 @@ pub struct LikePost {
actor: Url,
to: PublicUrl,
object: Url,
cc: [Url; 1],
#[serde(rename = "type")]
kind: LikeType,
}

View file

@ -18,7 +18,7 @@ pub struct RemovePost {
actor: Url,
to: PublicUrl,
object: Url,
cc: Vec<Url>,
cc: [Url; 1],
#[serde(rename = "type")]
kind: RemoveType,
}
@ -28,7 +28,7 @@ impl VerifyActivity for Activity<RemovePost> {
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.inner.actor, self.id_unchecked())?;
check_is_apub_id_valid(&self.inner.actor, false)?;
verify_mod_action(self.inner.actor.clone(), self.inner.cc.clone(), context).await
verify_mod_action(self.inner.actor.clone(), self.inner.cc[0].clone(), context).await
}
}

View file

@ -28,6 +28,7 @@ pub struct UpdatePost {
actor: Url,
to: PublicUrl,
object: PageExt,
cc: Vec<Url>,
#[serde(rename = "type")]
kind: UpdateType,
}

View file

@ -7,7 +7,13 @@ use crate::activities_new::{
remove::RemoveComment,
update::UpdateComment,
},
community::{delete::DeleteCommunity, update::UpdateCommunity},
community::{
delete::DeleteCommunity,
remove::RemoveCommunity,
undo_delete::UndoDeleteCommunity,
undo_remove::UndoRemoveCommunity,
update::UpdateCommunity,
},
follow::AcceptFollowCommunity,
post::{
create::CreatePost,
@ -29,9 +35,6 @@ use lemmy_apub_lib::{ReceiveActivity, VerifyActivity};
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
use url::Url;
use crate::activities_new::community::remove::RemoveCommunity;
use crate::activities_new::community::undo_remove::UndoRemoveCommunity;
use crate::activities_new::community::undo_delete::UndoDeleteCommunity;
// TODO: would be nice if we could move this to lemmy_apub_lib crate. doing that gives error:
// "only traits defined in the current crate can be implemented for arbitrary types"
@ -57,6 +60,7 @@ impl<Kind> Activity<Kind> {
}
}
// TODO: this is probably wrong, it contains all activities
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub enum PersonAcceptedActivitiesNew {
AcceptFollowCommunity(AcceptFollowCommunity),