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-07-14 15:17:06 +00:00
|
|
|
insert_received_activity,
|
2023-03-21 15:03:05 +00:00
|
|
|
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-10-11 14:48:19 +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},
|
2024-02-15 13:52:04 +00:00
|
|
|
comment_report::CommentReport,
|
2022-10-27 09:24:07 +00:00
|
|
|
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},
|
2024-02-15 13:52:04 +00:00
|
|
|
post_report::PostReport,
|
2021-08-17 18:04:58 +00:00
|
|
|
},
|
2024-02-15 13:52:04 +00:00
|
|
|
traits::{Crud, Reportable},
|
2021-08-17 18:04:58 +00:00
|
|
|
};
|
2024-04-10 14:14:11 +00:00
|
|
|
use lemmy_utils::error::{LemmyError, LemmyErrorType, LemmyResult};
|
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)]
|
2024-04-10 14:14:11 +00:00
|
|
|
async fn verify(&self, context: &Data<Self::DataType>) -> LemmyResult<()> {
|
2023-03-21 15:03:05 +00:00
|
|
|
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)]
|
2024-04-10 14:14:11 +00:00
|
|
|
async fn receive(self, context: &Data<LemmyContext>) -> LemmyResult<()> {
|
2024-01-11 23:56:19 +00:00
|
|
|
insert_received_activity(&self.id, 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-11-16 13:22:40 +00:00
|
|
|
receive_delete_action(
|
|
|
|
self.object.id(),
|
|
|
|
&self.actor,
|
|
|
|
true,
|
|
|
|
self.remove_data,
|
|
|
|
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>,
|
2024-04-10 14:14:11 +00:00
|
|
|
) -> LemmyResult<Delete> {
|
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()),
|
2023-11-16 13:22:40 +00:00
|
|
|
remove_data: None,
|
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>,
|
2024-04-10 14:14:11 +00:00
|
|
|
) -> LemmyResult<()> {
|
2021-08-17 18:04:58 +00:00
|
|
|
match DeletableObjects::read_from_db(object, context).await? {
|
|
|
|
DeletableObjects::Community(community) => {
|
|
|
|
if community.local {
|
2023-08-31 13:01:08 +00:00
|
|
|
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,
|
|
|
|
};
|
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(true),
|
|
|
|
..Default::default()
|
|
|
|
},
|
2022-11-09 10:05:00 +00:00
|
|
|
)
|
|
|
|
.await?;
|
2021-08-17 18:04:58 +00:00
|
|
|
}
|
|
|
|
DeletableObjects::Post(post) => {
|
2024-02-15 13:52:04 +00:00
|
|
|
PostReport::resolve_all_for_object(&mut context.pool(), post.id, actor.id).await?;
|
2021-08-17 18:04:58 +00:00
|
|
|
let form = ModRemovePostForm {
|
|
|
|
mod_person_id: actor.id,
|
|
|
|
post_id: post.id,
|
|
|
|
removed: Some(true),
|
|
|
|
reason,
|
|
|
|
};
|
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(true),
|
|
|
|
..Default::default()
|
|
|
|
},
|
2022-11-09 10:05:00 +00:00
|
|
|
)
|
|
|
|
.await?;
|
2021-08-17 18:04:58 +00:00
|
|
|
}
|
|
|
|
DeletableObjects::Comment(comment) => {
|
2024-02-15 13:52:04 +00:00
|
|
|
CommentReport::resolve_all_for_object(&mut context.pool(), comment.id, actor.id).await?;
|
2021-08-17 18:04:58 +00:00
|
|
|
let form = ModRemoveCommentForm {
|
|
|
|
mod_person_id: actor.id,
|
|
|
|
comment_id: comment.id,
|
|
|
|
removed: Some(true),
|
|
|
|
reason,
|
|
|
|
};
|
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(true),
|
|
|
|
..Default::default()
|
|
|
|
},
|
2022-11-09 10:05:00 +00:00
|
|
|
)
|
|
|
|
.await?;
|
2021-08-17 18:04:58 +00:00
|
|
|
}
|
2024-08-01 00:28:41 +00:00
|
|
|
// TODO these need to be implemented yet, for now, return errors
|
2024-09-23 15:26:50 +00:00
|
|
|
DeletableObjects::PrivateMessage(_) => Err(LemmyErrorType::NotFound)?,
|
|
|
|
DeletableObjects::Person(_) => Err(LemmyErrorType::NotFound)?,
|
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
|
|
|
}
|