2021-07-17 16:20:44 +00:00
|
|
|
use crate::{
|
2021-10-29 10:32:42 +00:00
|
|
|
activity_lists::SharedInboxActivities,
|
2021-11-05 00:24:10 +00:00
|
|
|
fetcher::user_or_community::UserOrCommunity,
|
2022-06-02 14:33:41 +00:00
|
|
|
protocol::objects::tombstone::Tombstone,
|
|
|
|
CONTEXT,
|
2021-07-17 16:20:44 +00:00
|
|
|
};
|
2022-06-02 14:33:41 +00:00
|
|
|
use activitypub_federation::{
|
2023-03-21 15:03:05 +00:00
|
|
|
actix_web::inbox::receive_activity,
|
|
|
|
config::Data,
|
|
|
|
protocol::context::WithContext,
|
|
|
|
FEDERATION_CONTENT_TYPE,
|
2021-10-06 20:20:05 +00:00
|
|
|
};
|
2023-03-21 15:03:05 +00:00
|
|
|
use actix_web::{web, web::Bytes, HttpRequest, HttpResponse};
|
2022-06-02 14:33:41 +00:00
|
|
|
use http::StatusCode;
|
2022-11-28 14:29:33 +00:00
|
|
|
use lemmy_api_common::context::LemmyContext;
|
2023-07-14 15:17:06 +00:00
|
|
|
use lemmy_db_schema::source::activity::SentActivity;
|
2023-07-10 14:50:07 +00:00
|
|
|
use lemmy_utils::error::{LemmyError, LemmyErrorType, LemmyResult};
|
2023-03-21 15:03:05 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2022-06-02 14:33:41 +00:00
|
|
|
use std::ops::Deref;
|
2021-03-02 12:41:48 +00:00
|
|
|
use url::Url;
|
2020-10-12 14:10:09 +00:00
|
|
|
|
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
|
|
|
mod comment;
|
|
|
|
mod community;
|
|
|
|
mod person;
|
|
|
|
mod post;
|
|
|
|
pub mod routes;
|
2022-02-07 19:23:12 +00:00
|
|
|
pub mod site;
|
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
|
|
|
|
|
|
|
pub async fn shared_inbox(
|
|
|
|
request: HttpRequest,
|
2023-03-21 15:03:05 +00:00
|
|
|
body: Bytes,
|
|
|
|
data: Data<LemmyContext>,
|
2023-04-13 00:17:23 +00:00
|
|
|
) -> LemmyResult<HttpResponse> {
|
2023-03-21 15:03:05 +00:00
|
|
|
receive_activity::<SharedInboxActivities, UserOrCommunity, LemmyContext>(request, body, &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
|
|
|
}
|
2020-10-12 14:10:09 +00:00
|
|
|
|
|
|
|
/// Convert the data to json and turn it into an HTTP Response with the correct ActivityPub
|
|
|
|
/// headers.
|
2023-04-13 00:17:23 +00:00
|
|
|
///
|
|
|
|
/// actix-web doesn't allow pretty-print for json so we need to do this manually.
|
|
|
|
fn create_apub_response<T>(data: &T) -> LemmyResult<HttpResponse>
|
2020-10-12 14:10:09 +00:00
|
|
|
where
|
|
|
|
T: Serialize,
|
|
|
|
{
|
2023-04-13 00:17:23 +00:00
|
|
|
let json = serde_json::to_string_pretty(&WithContext::new(data, CONTEXT.clone()))?;
|
2020-10-12 14:10:09 +00:00
|
|
|
|
2023-04-13 00:17:23 +00:00
|
|
|
Ok(
|
|
|
|
HttpResponse::Ok()
|
|
|
|
.content_type(FEDERATION_CONTENT_TYPE)
|
|
|
|
.body(json),
|
|
|
|
)
|
2021-11-15 20:26:48 +00:00
|
|
|
}
|
|
|
|
|
2023-04-13 00:17:23 +00:00
|
|
|
fn create_apub_tombstone_response<T: Into<Url>>(id: T) -> LemmyResult<HttpResponse> {
|
2022-06-02 14:33:41 +00:00
|
|
|
let tombstone = Tombstone::new(id.into());
|
2023-04-13 00:17:23 +00:00
|
|
|
let json = serde_json::to_string_pretty(&WithContext::new(tombstone, CONTEXT.deref().clone()))?;
|
|
|
|
|
|
|
|
Ok(
|
|
|
|
HttpResponse::Gone()
|
|
|
|
.content_type(FEDERATION_CONTENT_TYPE)
|
|
|
|
.status(StatusCode::GONE)
|
|
|
|
.body(json),
|
|
|
|
)
|
2020-10-12 14:10:09 +00:00
|
|
|
}
|
2020-10-23 13:02:45 +00:00
|
|
|
|
2023-02-08 19:45:29 +00:00
|
|
|
fn err_object_not_local() -> LemmyError {
|
2023-07-10 14:50:07 +00:00
|
|
|
LemmyErrorType::ObjectNotLocal.into()
|
2023-02-08 19:45:29 +00:00
|
|
|
}
|
|
|
|
|
2020-10-23 13:02:45 +00:00
|
|
|
#[derive(Deserialize)]
|
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
|
|
|
pub struct ActivityQuery {
|
2020-10-23 13:02:45 +00:00
|
|
|
type_: String,
|
|
|
|
id: String,
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/// Return the ActivityPub json representation of a local activity over HTTP.
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
2021-03-08 13:40:28 +00:00
|
|
|
pub(crate) async fn get_activity(
|
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
|
|
|
info: web::Path<ActivityQuery>,
|
2020-10-23 13:02:45 +00:00
|
|
|
context: web::Data<LemmyContext>,
|
2021-12-14 13:30:37 +00:00
|
|
|
) -> Result<HttpResponse, LemmyError> {
|
2021-09-22 15:57:09 +00:00
|
|
|
let settings = context.settings();
|
2021-03-02 12:41:48 +00:00
|
|
|
let activity_id = Url::parse(&format!(
|
2020-10-23 13:02:45 +00:00
|
|
|
"{}/activities/{}/{}",
|
|
|
|
settings.get_protocol_and_hostname(),
|
|
|
|
info.type_,
|
|
|
|
info.id
|
2021-03-02 12:41:48 +00:00
|
|
|
))?
|
|
|
|
.into();
|
2023-07-14 15:17:06 +00:00
|
|
|
let activity = SentActivity::read_from_apub_id(&mut context.pool(), &activity_id).await?;
|
2020-10-23 13:02:45 +00:00
|
|
|
|
2023-04-17 19:19:51 +00:00
|
|
|
let sensitive = activity.sensitive;
|
2023-07-14 15:17:06 +00:00
|
|
|
if sensitive {
|
2023-02-08 19:45:29 +00:00
|
|
|
Ok(HttpResponse::Forbidden().finish())
|
2020-11-06 13:06:47 +00:00
|
|
|
} else {
|
2023-04-13 00:17:23 +00:00
|
|
|
create_apub_response(&activity.data)
|
2020-11-06 13:06:47 +00:00
|
|
|
}
|
2020-10-23 13:02:45 +00:00
|
|
|
}
|