From: Felix Ableitner Date: Mon, 13 Jul 2020 13:56:58 +0000 (+0200) Subject: Make reads from activitypub objects immutable X-Git-Url: http://these/git/%7B%24%7B%60data:application/%22%7Burl%7D/%7Bthis.state.url%7D?a=commitdiff_plain;h=bb3e29e5c4abf1a5b572899fe2d2da4a4f865f2e;p=lemmy.git Make reads from activitypub objects immutable --- diff --git a/server/lemmy_db/src/lib.rs b/server/lemmy_db/src/lib.rs index b34919cd..5cf20bb3 100644 --- a/server/lemmy_db/src/lib.rs +++ b/server/lemmy_db/src/lib.rs @@ -181,7 +181,7 @@ mod tests { pub fn establish_unpooled_connection() -> PgConnection { let db_url = match get_database_url_from_env() { Ok(url) => url, - Err(_) => panic!("Failed to read database URL from env var LEMMY_DATABASE_URL"), + Err(e) => panic!("Failed to read database URL from env var LEMMY_DATABASE_URL: {}", e), }; PgConnection::establish(&db_url).unwrap_or_else(|_| panic!("Error connecting to {}", db_url)) } diff --git a/server/src/apub/comment.rs b/server/src/apub/comment.rs index af3581cb..84d11275 100644 --- a/server/src/apub/comment.rs +++ b/server/src/apub/comment.rs @@ -1,25 +1,16 @@ use crate::{ apub::{ activities::{populate_object_props, send_activity_to_community}, - create_apub_response, - create_apub_tombstone_response, - create_tombstone, - fetch_webfinger_url, + create_apub_response, create_apub_tombstone_response, create_tombstone, fetch_webfinger_url, fetcher::{ - get_or_fetch_and_insert_remote_comment, - get_or_fetch_and_insert_remote_post, + get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post, get_or_fetch_and_upsert_remote_user, }, - ActorType, - ApubLikeableType, - ApubObjectType, - FromApub, - ToApub, + ActorType, ApubLikeableType, ApubObjectType, FromApub, ToApub, }, blocking, routes::DbPoolParam, - DbPool, - LemmyError, + DbPool, LemmyError, }; use activitystreams::{ activity::{Create, Delete, Dislike, Like, Remove, Undo, Update}, @@ -121,7 +112,7 @@ impl FromApub for CommentForm { /// Parse an ActivityPub note received from another instance into a Lemmy comment async fn from_apub( - note: &mut Note, + note: &Note, client: &Client, pool: &DbPool, ) -> Result { diff --git a/server/src/apub/community.rs b/server/src/apub/community.rs index 8b623e71..587977a3 100644 --- a/server/src/apub/community.rs +++ b/server/src/apub/community.rs @@ -1,28 +1,18 @@ use crate::{ apub::{ activities::{populate_object_props, send_activity}, - create_apub_response, - create_apub_tombstone_response, - create_tombstone, + create_apub_response, create_apub_tombstone_response, create_tombstone, extensions::group_extensions::GroupExtension, fetcher::get_or_fetch_and_upsert_remote_user, - get_shared_inbox, - insert_activity, - ActorType, - FromApub, - GroupExt, - ToApub, + get_shared_inbox, insert_activity, ActorType, FromApub, GroupExt, ToApub, }, blocking, routes::DbPoolParam, - DbPool, - LemmyError, + DbPool, LemmyError, }; use activitystreams::{ activity::{Accept, Announce, Delete, Remove, Undo}, - Activity, - Base, - BaseBox, + Activity, Base, BaseBox, }; use activitystreams_ext::Ext2; use activitystreams_new::{ @@ -367,13 +357,8 @@ impl FromApub for CommunityForm { type ApubType = GroupExt; /// Parse an ActivityPub group received from another instance into a Lemmy community. - async fn from_apub( - group: &mut GroupExt, - client: &Client, - pool: &DbPool, - ) -> Result { - // TODO: this is probably gonna cause problems cause fetcher:292 also calls take_attributed_to() - let creator_and_moderator_uris = group.clone().take_attributed_to().unwrap(); + async fn from_apub(group: &GroupExt, client: &Client, pool: &DbPool) -> Result { + let creator_and_moderator_uris = group.attributed_to().unwrap(); let creator_uri = creator_and_moderator_uris .as_many() .unwrap() @@ -386,27 +371,20 @@ impl FromApub for CommunityForm { let creator = get_or_fetch_and_upsert_remote_user(creator_uri.as_str(), client, pool).await?; Ok(CommunityForm { - name: group - .take_name() - .unwrap() - .as_single_xsd_string() - .unwrap() - .into(), - title: group.inner.take_preferred_username().unwrap(), + name: group.name().unwrap().as_single_xsd_string().unwrap().into(), + title: group.inner.preferred_username().unwrap().to_string(), // TODO: should be parsed as html and tags like