From 2423b89ced5c2d110c1284777407682f748a068f Mon Sep 17 00:00:00 2001 From: Nutomic Date: Wed, 7 Jun 2023 21:18:17 +0200 Subject: [PATCH] Activitypub breaking changes for Lemmy 0.18 (#2705) * Remove deprecated field `group.moderators` * Drop column local_site.federation_debug * Remove backwards compatibility code for feature/lock post https://github.com/LemmyNet/lemmy/pull/2716 --------- Co-authored-by: Dessalines --- crates/api_crud/src/site/create.rs | 1 - crates/api_crud/src/site/update.rs | 1 - .../community/update_community.json | 2 +- .../create_or_update/create_page.json | 1 - .../create_or_update/update_page.json | 1 - .../collections/group_featured_posts.json | 2 -- crates/apub/assets/lemmy/objects/group.json | 1 - crates/apub/assets/lemmy/objects/page.json | 1 - .../activities/community/collection_add.rs | 14 +--------- .../src/activities/community/lock_page.rs | 14 +--------- .../src/activities/create_or_update/post.rs | 13 ++++------ crates/apub/src/objects/community.rs | 4 +-- crates/apub/src/objects/post.rs | 19 +++----------- crates/apub/src/protocol/objects/group.rs | 6 ++--- crates/apub/src/protocol/objects/page.rs | 26 +++---------------- crates/db_schema/src/schema.rs | 1 - crates/db_schema/src/source/local_site.rs | 3 --- .../down.sql | 1 + .../up.sql | 1 + 19 files changed, 21 insertions(+), 91 deletions(-) create mode 100644 migrations/2023-02-05-102549_drop-site-federation-debug/down.sql create mode 100644 migrations/2023-02-05-102549_drop-site-federation-debug/up.sql diff --git a/crates/api_crud/src/site/create.rs b/crates/api_crud/src/site/create.rs index c16f3bc56..af8540669 100644 --- a/crates/api_crud/src/site/create.rs +++ b/crates/api_crud/src/site/create.rs @@ -115,7 +115,6 @@ impl PerformCrud for CreateSite { .slur_filter_regex(diesel_option_overwrite(&data.slur_filter_regex)) .actor_name_max_length(data.actor_name_max_length) .federation_enabled(data.federation_enabled) - .federation_debug(data.federation_debug) .federation_worker_count(data.federation_worker_count) .captcha_enabled(data.captcha_enabled) .captcha_difficulty(data.captcha_difficulty.clone()) diff --git a/crates/api_crud/src/site/update.rs b/crates/api_crud/src/site/update.rs index b1b298167..b3e865759 100644 --- a/crates/api_crud/src/site/update.rs +++ b/crates/api_crud/src/site/update.rs @@ -113,7 +113,6 @@ impl PerformCrud for EditSite { .slur_filter_regex(diesel_option_overwrite(&data.slur_filter_regex)) .actor_name_max_length(data.actor_name_max_length) .federation_enabled(data.federation_enabled) - .federation_debug(data.federation_debug) .federation_worker_count(data.federation_worker_count) .captcha_enabled(data.captcha_enabled) .captcha_difficulty(data.captcha_difficulty.clone()) diff --git a/crates/apub/assets/lemmy/activities/community/update_community.json b/crates/apub/assets/lemmy/activities/community/update_community.json index 88129282e..873b03b76 100644 --- a/crates/apub/assets/lemmy/activities/community/update_community.json +++ b/crates/apub/assets/lemmy/activities/community/update_community.json @@ -12,11 +12,11 @@ "mediaType": "text/markdown" }, "sensitive": false, - "moderators": "http://enterprise.lemmy.ml/c/main/moderators", "postingRestrictedToMods": false, "inbox": "http://enterprise.lemmy.ml/c/main/inbox", "outbox": "http://enterprise.lemmy.ml/c/main/outbox", "followers": "http://enterprise.lemmy.ml/c/main/followers", + "attributedTo": "https://enterprise.lemmy.ml/c/main/moderators", "endpoints": { "sharedInbox": "http://enterprise.lemmy.ml/inbox" }, diff --git a/crates/apub/assets/lemmy/activities/create_or_update/create_page.json b/crates/apub/assets/lemmy/activities/create_or_update/create_page.json index 2f345245b..1729a8bdd 100644 --- a/crates/apub/assets/lemmy/activities/create_or_update/create_page.json +++ b/crates/apub/assets/lemmy/activities/create_or_update/create_page.json @@ -25,7 +25,6 @@ ], "commentsEnabled": true, "sensitive": false, - "stickied": false, "language": { "identifier": "ko", "name": "한국어" diff --git a/crates/apub/assets/lemmy/activities/create_or_update/update_page.json b/crates/apub/assets/lemmy/activities/create_or_update/update_page.json index 606904fc4..2e1007638 100644 --- a/crates/apub/assets/lemmy/activities/create_or_update/update_page.json +++ b/crates/apub/assets/lemmy/activities/create_or_update/update_page.json @@ -25,7 +25,6 @@ ], "commentsEnabled": true, "sensitive": false, - "stickied": false, "published": "2021-10-29T15:10:51.557399+00:00", "updated": "2021-10-29T15:11:35.976374+00:00" }, diff --git a/crates/apub/assets/lemmy/collections/group_featured_posts.json b/crates/apub/assets/lemmy/collections/group_featured_posts.json index c5bc5fd9f..227c6f877 100644 --- a/crates/apub/assets/lemmy/collections/group_featured_posts.json +++ b/crates/apub/assets/lemmy/collections/group_featured_posts.json @@ -17,7 +17,6 @@ "attachment": [], "commentsEnabled": true, "sensitive": false, - "stickied": true, "published": "2023-02-06T06:42:41.939437+00:00", "language": { "identifier": "de", @@ -39,7 +38,6 @@ "attachment": [], "commentsEnabled": true, "sensitive": false, - "stickied": true, "published": "2023-02-06T06:42:37.119567+00:00", "language": { "identifier": "de", diff --git a/crates/apub/assets/lemmy/objects/group.json b/crates/apub/assets/lemmy/objects/group.json index 10c46640c..66dfe144b 100644 --- a/crates/apub/assets/lemmy/objects/group.json +++ b/crates/apub/assets/lemmy/objects/group.json @@ -19,7 +19,6 @@ }, "inbox": "https://enterprise.lemmy.ml/c/tenforward/inbox", "followers": "https://enterprise.lemmy.ml/c/tenforward/followers", - "moderators": "https://enterprise.lemmy.ml/c/tenforward/moderators", "attributedTo": "https://enterprise.lemmy.ml/c/tenforward/moderators", "featured": "https://enterprise.lemmy.ml/c/tenforward//featured", "postingRestrictedToMods": false, diff --git a/crates/apub/assets/lemmy/objects/page.json b/crates/apub/assets/lemmy/objects/page.json index bbe7e6d27..b3e9b480b 100644 --- a/crates/apub/assets/lemmy/objects/page.json +++ b/crates/apub/assets/lemmy/objects/page.json @@ -26,7 +26,6 @@ }, "sensitive": false, "commentsEnabled": true, - "stickied": true, "language": { "identifier": "fr", "name": "Français" diff --git a/crates/apub/src/activities/community/collection_add.rs b/crates/apub/src/activities/community/collection_add.rs index afe8387f2..be5dd0fe3 100644 --- a/crates/apub/src/activities/community/collection_add.rs +++ b/crates/apub/src/activities/community/collection_add.rs @@ -10,11 +10,7 @@ use crate::{ insert_activity, objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost}, protocol::{ - activities::{ - community::{collection_add::CollectionAdd, collection_remove::CollectionRemove}, - create_or_update::page::CreateOrUpdatePage, - CreateOrUpdateType, - }, + activities::community::{collection_add::CollectionAdd, collection_remove::CollectionRemove}, InCommunity, }, SendActivity, @@ -214,14 +210,6 @@ impl SendActivity for FeaturePost { context: &Data, ) -> Result<(), LemmyError> { let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; - // Deprecated, for backwards compatibility with 0.17 - CreateOrUpdatePage::send( - &response.post_view.post, - local_user_view.person.id, - CreateOrUpdateType::Update, - context, - ) - .await?; let community = Community::read(context.pool(), response.post_view.community.id) .await? .into(); diff --git a/crates/apub/src/activities/community/lock_page.rs b/crates/apub/src/activities/community/lock_page.rs index 26326efcb..5e4eefb81 100644 --- a/crates/apub/src/activities/community/lock_page.rs +++ b/crates/apub/src/activities/community/lock_page.rs @@ -10,11 +10,7 @@ use crate::{ activity_lists::AnnouncableActivities, insert_activity, protocol::{ - activities::{ - community::lock_page::{LockPage, LockType, UndoLockPage}, - create_or_update::page::CreateOrUpdatePage, - CreateOrUpdateType, - }, + activities::community::lock_page::{LockPage, LockType, UndoLockPage}, InCommunity, }, SendActivity, @@ -116,14 +112,6 @@ impl SendActivity for LockPost { context: &Data, ) -> Result<(), LemmyError> { let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; - // For backwards compat with 0.17 - CreateOrUpdatePage::send( - &response.post_view.post, - local_user_view.person.id, - CreateOrUpdateType::Update, - context, - ) - .await?; let id = generate_activity_id( LockType::Lock, &context.settings().get_protocol_and_hostname(), diff --git a/crates/apub/src/activities/create_or_update/post.rs b/crates/apub/src/activities/create_or_update/post.rs index b545f5239..f2923bfbd 100644 --- a/crates/apub/src/activities/create_or_update/post.rs +++ b/crates/apub/src/activities/create_or_update/post.rs @@ -152,16 +152,13 @@ impl ActivityHandler for CreateOrUpdatePage { CreateOrUpdateType::Create => { verify_domains_match(self.actor.inner(), self.object.id.inner())?; verify_urls_match(self.actor.inner(), self.object.creator()?.inner())?; - // Check that the post isnt locked or stickied, as that isnt possible for newly created posts. + // Check that the post isnt locked, as that isnt possible for newly created posts. // However, when fetching a remote post we generate a new create activity with the current - // locked/stickied value, so this check may fail. So only check if its a local community, + // locked value, so this check may fail. So only check if its a local community, // because then we will definitely receive all create and update activities separately. - let is_featured_or_locked = - self.object.stickied == Some(true) || self.object.comments_enabled == Some(false); - if community.local && is_featured_or_locked { - return Err(LemmyError::from_message( - "New post cannot be stickied or locked", - )); + let is_locked = self.object.comments_enabled == Some(false); + if community.local && is_locked { + return Err(LemmyError::from_message("New post cannot be locked")); } } CreateOrUpdateType::Update => { diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index 396c2af87..6526d2d26 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -96,7 +96,6 @@ impl Object for ApubCommunity { icon: self.icon.clone().map(ImageObject::new), image: self.banner.clone().map(ImageObject::new), sensitive: Some(self.nsfw), - moderators: Some(generate_moderators_url(&self.actor_id)?.into()), featured: Some(generate_featured_url(&self.actor_id)?.into()), inbox: self.inbox_url.clone().into(), outbox: generate_outbox_url(&self.actor_id)?.into(), @@ -148,7 +147,7 @@ impl Object for ApubCommunity { .map_err(|e| debug!("{}", e)) .ok(); - if let Some(moderators) = group.attributed_to.or(group.moderators) { + if let Some(moderators) = group.attributed_to { moderators .dereference(&community, context) .await @@ -231,7 +230,6 @@ pub(crate) mod tests { let context2 = context.reset_request_count(); let mut json: Group = file_to_json_object("assets/lemmy/objects/group.json").unwrap(); // change these links so they dont fetch over the network - json.moderators = None; json.attributed_to = None; json.outbox = CollectionId::parse("https://enterprise.lemmy.ml/c/tenforward/not_outbox").unwrap(); diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index 5b1583a27..b255ffb9b 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -32,7 +32,7 @@ use lemmy_db_schema::{ source::{ community::Community, local_site::LocalSite, - moderator::{ModFeaturePost, ModFeaturePostForm, ModLockPost, ModLockPostForm}, + moderator::{ModLockPost, ModLockPostForm}, person::Person, post::{Post, PostInsertForm, PostUpdateForm}, }, @@ -121,7 +121,6 @@ impl Object for ApubPost { image: self.thumbnail_url.clone().map(ImageObject::new), comments_enabled: Some(!self.locked), sensitive: Some(self.nsfw), - stickied: Some(self.featured_community), language, published: Some(convert_datetime(self.published)), updated: self.updated.map(convert_datetime), @@ -236,7 +235,7 @@ impl Object for ApubPost { ap_id: Some(page.id.clone().into()), local: Some(false), language_id, - featured_community: page.stickied, + featured_community: None, featured_local: None, } } else { @@ -247,23 +246,13 @@ impl Object for ApubPost { .community_id(community.id) .ap_id(Some(page.id.clone().into())) .locked(page.comments_enabled.map(|e| !e)) - .featured_community(page.stickied) .updated(page.updated.map(|u| u.naive_local())) .build() }; let post = Post::create(context.pool(), &form).await?; - // write mod log entries for feature/lock - if Page::is_featured_changed(&old_post, &page.stickied) { - let form = ModFeaturePostForm { - mod_person_id: creator.id, - post_id: post.id, - featured: post.featured_community, - is_featured_community: true, - }; - ModFeaturePost::create(context.pool(), &form).await?; - } + // write mod log entry for lock if Page::is_locked_changed(&old_post, &page.comments_enabled) { let form = ModLockPostForm { mod_person_id: creator.id, @@ -309,7 +298,7 @@ mod tests { assert!(post.body.is_some()); assert_eq!(post.body.as_ref().unwrap().len(), 45); assert!(!post.locked); - assert!(post.featured_community); + assert!(!post.featured_community); assert_eq!(context.request_count(), 0); Post::delete(context.pool(), post.id).await.unwrap(); diff --git a/crates/apub/src/protocol/objects/group.rs b/crates/apub/src/protocol/objects/group.rs index 520070cc6..8149e6712 100644 --- a/crates/apub/src/protocol/objects/group.rs +++ b/crates/apub/src/protocol/objects/group.rs @@ -61,8 +61,6 @@ pub struct Group { pub(crate) image: Option, // lemmy extension pub(crate) sensitive: Option, - // deprecated, use attributed_to instead - pub(crate) moderators: Option>, #[serde(deserialize_with = "deserialize_skip_error", default)] pub(crate) attributed_to: Option>, // lemmy extension @@ -122,7 +120,7 @@ impl Group { followers_url: Some(self.followers.into()), inbox_url: Some(self.inbox.into()), shared_inbox_url: self.endpoints.map(|e| e.shared_inbox.into()), - moderators_url: self.moderators.map(Into::into), + moderators_url: self.attributed_to.map(Into::into), posting_restricted_to_mods: self.posting_restricted_to_mods, instance_id, featured_url: self.featured.map(Into::into), @@ -153,7 +151,7 @@ impl Group { followers_url: Some(self.followers.into()), inbox_url: Some(self.inbox.into()), shared_inbox_url: Some(self.endpoints.map(|e| e.shared_inbox.into())), - moderators_url: self.moderators.map(Into::into), + moderators_url: self.attributed_to.map(Into::into), posting_restricted_to_mods: self.posting_restricted_to_mods, featured_url: self.featured.map(Into::into), } diff --git a/crates/apub/src/protocol/objects/page.rs b/crates/apub/src/protocol/objects/page.rs index 9bf8dbe59..ad89cf35b 100644 --- a/crates/apub/src/protocol/objects/page.rs +++ b/crates/apub/src/protocol/objects/page.rs @@ -63,8 +63,6 @@ pub struct Page { pub(crate) image: Option, pub(crate) comments_enabled: Option, pub(crate) sensitive: Option, - /// Deprecated, for compatibility with Lemmy 0.17 - pub(crate) stickied: Option, pub(crate) published: Option>, pub(crate) updated: Option>, pub(crate) language: Option, @@ -131,32 +129,16 @@ pub(crate) struct AttributedToPeertube { } impl Page { - /// Only mods can change the post's stickied/locked status. So if either of these is changed from - /// the current value, it is a mod action and needs to be verified as such. + /// Only mods can change the post's locked status. So if it is changed from the default value, + /// it is a mod action and needs to be verified as such. /// - /// Both stickied and locked need to be false on a newly created post (verified in [[CreatePost]]. + /// Locked needs to be false on a newly created post (verified in [[CreatePost]]. pub(crate) async fn is_mod_action( &self, context: &Data, ) -> Result { let old_post = self.id.clone().dereference_local(context).await; - - let featured_changed = Page::is_featured_changed(&old_post, &self.stickied); - let locked_changed = Page::is_locked_changed(&old_post, &self.comments_enabled); - Ok(featured_changed || locked_changed) - } - - pub(crate) fn is_featured_changed( - old_post: &Result, - new_featured_community: &Option, - ) -> bool { - if let Some(new_featured_community) = new_featured_community { - if let Ok(old_post) = old_post { - return new_featured_community != &old_post.featured_community; - } - } - - false + Ok(Page::is_locked_changed(&old_post, &self.comments_enabled)) } pub(crate) fn is_locked_changed( diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 2753a0d64..6fe139126 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -337,7 +337,6 @@ diesel::table! { slur_filter_regex -> Nullable, actor_name_max_length -> Int4, federation_enabled -> Bool, - federation_debug -> Bool, federation_worker_count -> Int4, captcha_enabled -> Bool, #[max_length = 255] diff --git a/crates/db_schema/src/source/local_site.rs b/crates/db_schema/src/source/local_site.rs index 948c9734a..e65a61535 100644 --- a/crates/db_schema/src/source/local_site.rs +++ b/crates/db_schema/src/source/local_site.rs @@ -50,7 +50,6 @@ pub struct LocalSite { pub actor_name_max_length: i32, /// Whether federation is enabled. pub federation_enabled: bool, - pub federation_debug: bool, /// The number of concurrent federation http workers. pub federation_worker_count: i32, /// Whether captcha is enabled. @@ -86,7 +85,6 @@ pub struct LocalSiteInsertForm { pub slur_filter_regex: Option, pub actor_name_max_length: Option, pub federation_enabled: Option, - pub federation_debug: Option, pub federation_worker_count: Option, pub captcha_enabled: Option, pub captcha_difficulty: Option, @@ -114,7 +112,6 @@ pub struct LocalSiteUpdateForm { pub slur_filter_regex: Option>, pub actor_name_max_length: Option, pub federation_enabled: Option, - pub federation_debug: Option, pub federation_worker_count: Option, pub captcha_enabled: Option, pub captcha_difficulty: Option, diff --git a/migrations/2023-02-05-102549_drop-site-federation-debug/down.sql b/migrations/2023-02-05-102549_drop-site-federation-debug/down.sql new file mode 100644 index 000000000..1ac320f2f --- /dev/null +++ b/migrations/2023-02-05-102549_drop-site-federation-debug/down.sql @@ -0,0 +1 @@ +alter table local_site add column federation_debug int default 0; \ No newline at end of file diff --git a/migrations/2023-02-05-102549_drop-site-federation-debug/up.sql b/migrations/2023-02-05-102549_drop-site-federation-debug/up.sql new file mode 100644 index 000000000..c7286d09c --- /dev/null +++ b/migrations/2023-02-05-102549_drop-site-federation-debug/up.sql @@ -0,0 +1 @@ +alter table local_site drop column federation_debug; \ No newline at end of file