2021-11-03 17:33:51 +00:00
|
|
|
use crate::{
|
|
|
|
activities::{
|
|
|
|
deletion::{receive_delete_action, verify_delete_activity, DeletableObjects},
|
|
|
|
generate_activity_id,
|
|
|
|
},
|
2023-07-14 15:17:06 +00:00
|
|
|
insert_received_activity,
|
2023-03-21 15:03:05 +00:00
|
|
|
objects::person::ApubPerson,
|
2021-11-03 17:33:51 +00:00
|
|
|
protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete},
|
|
|
|
};
|
2023-03-21 15:03:05 +00:00
|
|
|
use activitypub_federation::{config::Data, kinds::activity::UndoType, traits::ActivityHandler};
|
2023-06-06 16:27:22 +00:00
|
|
|
use lemmy_api_common::context::LemmyContext;
|
2022-04-07 20:44:28 +00:00
|
|
|
use lemmy_db_schema::{
|
|
|
|
source::{
|
2022-10-27 09:24:07 +00:00
|
|
|
comment::{Comment, CommentUpdateForm},
|
|
|
|
community::{Community, CommunityUpdateForm},
|
2022-04-07 20:44:28 +00:00
|
|
|
moderator::{
|
2023-09-23 01:39:03 +00:00
|
|
|
ModRemoveComment, ModRemoveCommentForm, ModRemoveCommunity, ModRemoveCommunityForm,
|
|
|
|
ModRemovePost, ModRemovePostForm,
|
2022-04-07 20:44:28 +00:00
|
|
|
},
|
2022-10-27 09:24:07 +00:00
|
|
|
post::{Post, PostUpdateForm},
|
2022-04-07 20:44:28 +00:00
|
|
|
},
|
|
|
|
traits::Crud,
|
|
|
|
};
|
2023-07-10 14:50:07 +00:00
|
|
|
use lemmy_utils::error::{LemmyError, LemmyErrorType};
|
2021-11-03 17:33:51 +00:00
|
|
|
use url::Url;
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
|
2023-03-21 15:03:05 +00:00
|
|
|
#[async_trait::async_trait]
|
2021-08-17 18:04:58 +00:00
|
|
|
impl ActivityHandler for UndoDelete {
|
2021-10-06 20:20:05 +00:00
|
|
|
type DataType = LemmyContext;
|
2022-06-02 14:33:41 +00:00
|
|
|
type Error = LemmyError;
|
|
|
|
|
|
|
|
fn id(&self) -> &Url {
|
|
|
|
&self.id
|
|
|
|
}
|
|
|
|
|
|
|
|
fn actor(&self) -> &Url {
|
|
|
|
self.actor.inner()
|
|
|
|
}
|
2021-12-06 14:54:47 +00:00
|
|
|
|
2023-03-21 15:03:05 +00:00
|
|
|
async fn verify(&self, data: &Data<Self::DataType>) -> Result<(), Self::Error> {
|
2023-07-14 15:17:06 +00:00
|
|
|
insert_received_activity(&self.id, data).await?;
|
2023-03-21 15:03:05 +00:00
|
|
|
self.object.verify(data).await?;
|
|
|
|
verify_delete_activity(&self.object, self.object.summary.is_some(), data).await?;
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
2023-03-21 15:03:05 +00:00
|
|
|
async fn receive(self, context: &Data<LemmyContext>) -> Result<(), LemmyError> {
|
2021-08-17 18:04:58 +00:00
|
|
|
if self.object.summary.is_some() {
|
2022-04-07 20:44:28 +00:00
|
|
|
UndoDelete::receive_undo_remove_action(
|
2023-03-21 15:03:05 +00:00
|
|
|
&self.actor.dereference(context).await?,
|
2022-04-07 20:44:28 +00:00
|
|
|
self.object.object.id(),
|
|
|
|
context,
|
|
|
|
)
|
|
|
|
.await
|
2021-08-17 18:04:58 +00:00
|
|
|
} else {
|
2023-03-21 15:03:05 +00:00
|
|
|
receive_delete_action(self.object.object.id(), &self.actor, false, context).await
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-17 18:04:58 +00:00
|
|
|
|
|
|
|
impl UndoDelete {
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
2022-02-14 15:14:24 +00:00
|
|
|
pub(in crate::activities::deletion) fn new(
|
2022-06-08 15:45:39 +00:00
|
|
|
actor: &ApubPerson,
|
2021-11-16 00:58:15 +00:00
|
|
|
object: DeletableObjects,
|
2022-02-14 15:14:24 +00:00
|
|
|
to: Url,
|
|
|
|
community: Option<&Community>,
|
2021-08-17 18:04:58 +00:00
|
|
|
summary: Option<String>,
|
2023-03-21 15:03:05 +00:00
|
|
|
context: &Data<LemmyContext>,
|
2022-02-14 15:14:24 +00:00
|
|
|
) -> Result<UndoDelete, LemmyError> {
|
|
|
|
let object = Delete::new(actor, object, to.clone(), community, summary, context)?;
|
2021-08-17 18:04:58 +00:00
|
|
|
|
2021-09-22 15:57:09 +00:00
|
|
|
let id = generate_activity_id(
|
|
|
|
UndoType::Undo,
|
|
|
|
&context.settings().get_protocol_and_hostname(),
|
|
|
|
)?;
|
2022-02-14 15:14:24 +00:00
|
|
|
let cc: Option<Url> = community.map(|c| c.actor_id.clone().into());
|
|
|
|
Ok(UndoDelete {
|
2023-03-21 15:03:05 +00:00
|
|
|
actor: actor.actor_id.clone().into(),
|
2022-02-14 15:14:24 +00:00
|
|
|
to: vec![to],
|
2021-08-19 21:24:33 +00:00
|
|
|
object,
|
2022-02-14 15:14:24 +00:00
|
|
|
cc: cc.into_iter().collect(),
|
2021-08-17 18:04:58 +00:00
|
|
|
kind: UndoType::Undo,
|
2022-02-14 15:14:24 +00:00
|
|
|
id,
|
2023-03-21 15:03:05 +00:00
|
|
|
audience: community.map(|c| c.actor_id.clone().into()),
|
2022-02-14 15:14:24 +00:00
|
|
|
})
|
2021-08-17 18:04:58 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
2021-08-17 18:04:58 +00:00
|
|
|
pub(in crate::activities) async fn receive_undo_remove_action(
|
2022-04-07 20:44:28 +00:00
|
|
|
actor: &ApubPerson,
|
2021-08-17 18:04:58 +00:00
|
|
|
object: &Url,
|
2023-03-21 15:03:05 +00:00
|
|
|
context: &Data<LemmyContext>,
|
2021-08-17 18:04:58 +00:00
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
match DeletableObjects::read_from_db(object, context).await? {
|
|
|
|
DeletableObjects::Community(community) => {
|
|
|
|
if community.local {
|
2023-08-31 13:01:08 +00:00
|
|
|
Err(LemmyErrorType::OnlyLocalAdminCanRestoreCommunity)?
|
2021-08-17 18:04:58 +00:00
|
|
|
}
|
2022-04-07 20:44:28 +00:00
|
|
|
let form = ModRemoveCommunityForm {
|
|
|
|
mod_person_id: actor.id,
|
|
|
|
community_id: community.id,
|
|
|
|
removed: Some(false),
|
|
|
|
reason: None,
|
|
|
|
expires: None,
|
|
|
|
};
|
2023-07-11 13:09:59 +00:00
|
|
|
ModRemoveCommunity::create(&mut context.pool(), &form).await?;
|
2023-06-06 16:27:22 +00:00
|
|
|
Community::update(
|
2023-07-11 13:09:59 +00:00
|
|
|
&mut context.pool(),
|
2022-11-09 10:05:00 +00:00
|
|
|
community.id,
|
2023-08-08 09:41:41 +00:00
|
|
|
&CommunityUpdateForm {
|
|
|
|
removed: Some(false),
|
|
|
|
..Default::default()
|
|
|
|
},
|
2022-11-09 10:05:00 +00:00
|
|
|
)
|
|
|
|
.await?;
|
2021-08-17 18:04:58 +00:00
|
|
|
}
|
|
|
|
DeletableObjects::Post(post) => {
|
2022-04-07 20:44:28 +00:00
|
|
|
let form = ModRemovePostForm {
|
|
|
|
mod_person_id: actor.id,
|
|
|
|
post_id: post.id,
|
|
|
|
removed: Some(false),
|
|
|
|
reason: None,
|
|
|
|
};
|
2023-07-11 13:09:59 +00:00
|
|
|
ModRemovePost::create(&mut context.pool(), &form).await?;
|
2023-06-06 16:27:22 +00:00
|
|
|
Post::update(
|
2023-07-11 13:09:59 +00:00
|
|
|
&mut context.pool(),
|
2022-11-09 10:05:00 +00:00
|
|
|
post.id,
|
2023-08-08 09:41:41 +00:00
|
|
|
&PostUpdateForm {
|
|
|
|
removed: Some(false),
|
|
|
|
..Default::default()
|
|
|
|
},
|
2022-11-09 10:05:00 +00:00
|
|
|
)
|
|
|
|
.await?;
|
2021-08-17 18:04:58 +00:00
|
|
|
}
|
|
|
|
DeletableObjects::Comment(comment) => {
|
2022-04-07 20:44:28 +00:00
|
|
|
let form = ModRemoveCommentForm {
|
|
|
|
mod_person_id: actor.id,
|
|
|
|
comment_id: comment.id,
|
|
|
|
removed: Some(false),
|
|
|
|
reason: None,
|
|
|
|
};
|
2023-07-11 13:09:59 +00:00
|
|
|
ModRemoveComment::create(&mut context.pool(), &form).await?;
|
2023-06-06 16:27:22 +00:00
|
|
|
Comment::update(
|
2023-07-11 13:09:59 +00:00
|
|
|
&mut context.pool(),
|
2022-11-09 10:05:00 +00:00
|
|
|
comment.id,
|
2023-08-08 09:41:41 +00:00
|
|
|
&CommentUpdateForm {
|
|
|
|
removed: Some(false),
|
|
|
|
..Default::default()
|
|
|
|
},
|
2022-11-09 10:05:00 +00:00
|
|
|
)
|
|
|
|
.await?;
|
2021-08-17 18:04:58 +00:00
|
|
|
}
|
2022-02-14 15:14:24 +00:00
|
|
|
DeletableObjects::PrivateMessage(_) => unimplemented!(),
|
2021-08-17 18:04:58 +00:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|