2021-11-03 17:33:51 +00:00
|
|
|
use crate::{
|
|
|
|
activities::{
|
2021-11-05 00:24:10 +00:00
|
|
|
deletion::{receive_delete_action, verify_delete_activity, DeletableObjects},
|
2021-11-03 17:33:51 +00:00
|
|
|
generate_activity_id,
|
|
|
|
},
|
2023-03-21 15:03:05 +00:00
|
|
|
insert_activity,
|
|
|
|
objects::person::ApubPerson,
|
2022-06-02 17:48:53 +00:00
|
|
|
protocol::{activities::deletion::delete::Delete, IdOrNestedObject},
|
2021-11-03 17:33:51 +00:00
|
|
|
};
|
2023-03-21 15:03:05 +00:00
|
|
|
use activitypub_federation::{config::Data, kinds::activity::DeleteType, traits::ActivityHandler};
|
2023-06-06 16:27:22 +00:00
|
|
|
use lemmy_api_common::context::LemmyContext;
|
2021-10-16 13:33:38 +00:00
|
|
|
use lemmy_db_schema::{
|
|
|
|
source::{
|
2022-10-27 09:24:07 +00:00
|
|
|
comment::{Comment, CommentUpdateForm},
|
|
|
|
community::{Community, CommunityUpdateForm},
|
2021-10-16 13:33:38 +00:00
|
|
|
moderator::{
|
|
|
|
ModRemoveComment,
|
|
|
|
ModRemoveCommentForm,
|
|
|
|
ModRemoveCommunity,
|
|
|
|
ModRemoveCommunityForm,
|
|
|
|
ModRemovePost,
|
|
|
|
ModRemovePostForm,
|
|
|
|
},
|
2022-10-27 09:24:07 +00:00
|
|
|
post::{Post, PostUpdateForm},
|
2021-08-17 18:04:58 +00:00
|
|
|
},
|
2021-10-16 13:33:38 +00:00
|
|
|
traits::Crud,
|
2021-08-17 18:04:58 +00:00
|
|
|
};
|
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 Delete {
|
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
|
|
|
|
|
|
|
#[tracing::instrument(skip_all)]
|
2023-03-21 15:03:05 +00:00
|
|
|
async fn verify(&self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
|
|
|
|
verify_delete_activity(self, self.summary.is_some(), 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
|
|
|
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> {
|
|
|
|
insert_activity(&self.id, &self, false, false, context).await?;
|
2021-08-17 18:04:58 +00:00
|
|
|
if let Some(reason) = self.summary {
|
|
|
|
// We set reason to empty string if it doesn't exist, to distinguish between delete and
|
|
|
|
// remove. Here we change it back to option, so we don't write it to db.
|
|
|
|
let reason = if reason.is_empty() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(reason)
|
|
|
|
};
|
2021-11-16 00:58:15 +00:00
|
|
|
receive_remove_action(
|
2023-03-21 15:03:05 +00:00
|
|
|
&self.actor.dereference(context).await?,
|
2022-02-14 15:14:24 +00:00
|
|
|
self.object.id(),
|
2021-11-16 00:58:15 +00:00
|
|
|
reason,
|
|
|
|
context,
|
|
|
|
)
|
|
|
|
.await
|
2021-08-17 18:04:58 +00:00
|
|
|
} else {
|
2023-03-21 15:03:05 +00:00
|
|
|
receive_delete_action(self.object.id(), &self.actor, true, 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 Delete {
|
2021-08-19 21:24:33 +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>,
|
2021-08-19 21:24:33 +00:00
|
|
|
) -> Result<Delete, LemmyError> {
|
2022-02-14 15:14:24 +00:00
|
|
|
let id = generate_activity_id(
|
|
|
|
DeleteType::Delete,
|
|
|
|
&context.settings().get_protocol_and_hostname(),
|
|
|
|
)?;
|
|
|
|
let cc: Option<Url> = community.map(|c| c.actor_id.clone().into());
|
2021-08-19 21:24:33 +00:00
|
|
|
Ok(Delete {
|
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],
|
2022-06-02 17:48:53 +00:00
|
|
|
object: IdOrNestedObject::Id(object.id()),
|
2022-02-14 15:14:24 +00:00
|
|
|
cc: cc.into_iter().collect(),
|
2021-08-17 18:04:58 +00:00
|
|
|
kind: DeleteType::Delete,
|
|
|
|
summary,
|
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()),
|
2021-08-19 21:24:33 +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_remove_action(
|
2022-04-07 20:44:28 +00:00
|
|
|
actor: &ApubPerson,
|
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
|
|
|
object: &Url,
|
2021-08-17 18:04:58 +00:00
|
|
|
reason: Option<String>,
|
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-07-10 14:50:07 +00:00
|
|
|
return Err(LemmyErrorType::OnlyLocalAdminCanRemoveCommunity)?;
|
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
|
|
|
let form = ModRemoveCommunityForm {
|
|
|
|
mod_person_id: actor.id,
|
|
|
|
community_id: community.id,
|
|
|
|
removed: Some(true),
|
|
|
|
reason,
|
|
|
|
expires: None,
|
|
|
|
};
|
2022-11-09 10:05:00 +00:00
|
|
|
ModRemoveCommunity::create(context.pool(), &form).await?;
|
2023-06-06 16:27:22 +00:00
|
|
|
Community::update(
|
2022-11-09 10:05:00 +00:00
|
|
|
context.pool(),
|
|
|
|
community.id,
|
|
|
|
&CommunityUpdateForm::builder().removed(Some(true)).build(),
|
|
|
|
)
|
|
|
|
.await?;
|
2021-08-17 18:04:58 +00:00
|
|
|
}
|
|
|
|
DeletableObjects::Post(post) => {
|
|
|
|
let form = ModRemovePostForm {
|
|
|
|
mod_person_id: actor.id,
|
|
|
|
post_id: post.id,
|
|
|
|
removed: Some(true),
|
|
|
|
reason,
|
|
|
|
};
|
2022-11-09 10:05:00 +00:00
|
|
|
ModRemovePost::create(context.pool(), &form).await?;
|
2023-06-06 16:27:22 +00:00
|
|
|
Post::update(
|
2022-11-09 10:05:00 +00:00
|
|
|
context.pool(),
|
|
|
|
post.id,
|
|
|
|
&PostUpdateForm::builder().removed(Some(true)).build(),
|
|
|
|
)
|
|
|
|
.await?;
|
2021-08-17 18:04:58 +00:00
|
|
|
}
|
|
|
|
DeletableObjects::Comment(comment) => {
|
|
|
|
let form = ModRemoveCommentForm {
|
|
|
|
mod_person_id: actor.id,
|
|
|
|
comment_id: comment.id,
|
|
|
|
removed: Some(true),
|
|
|
|
reason,
|
|
|
|
};
|
2022-11-09 10:05:00 +00:00
|
|
|
ModRemoveComment::create(context.pool(), &form).await?;
|
2023-06-06 16:27:22 +00:00
|
|
|
Comment::update(
|
2022-11-09 10:05:00 +00:00
|
|
|
context.pool(),
|
|
|
|
comment.id,
|
|
|
|
&CommentUpdateForm::builder().removed(Some(true)).build(),
|
|
|
|
)
|
|
|
|
.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(())
|
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
|
|
|
}
|