From 969f8b2ce9cd80492eb5e556ce3bda95c9b892b3 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 8 Aug 2023 02:41:41 -0700 Subject: [PATCH] Replace TypedBuilder with Default in update forms (#3814) * Update comment.rs * Update community.rs * Update local_site.rs * Update local_site_rate_limit.rs * Update local_user.rs * Update person.rs * Update comment.rs * Update community.rs * Update local_site.rs * Update local_site_rate_limit.rs * Update local_user.rs * Update post.rs * Update private_message.rs * Update site.rs * Update post.rs * Update person.rs * Update private_message.rs * Update comment.rs * Update create.rs * Update leave_admin.rs * Update update.rs * Update remove.rs * Update add_admin.rs * Update verify_email.rs * Update mod.rs * Update mod.rs * Update undo_delete.rs * Update undo_delete.rs * Update utils.rs * Update feature.rs * Update delete.rs * Update lock.rs * Update create.rs * Update approve.rs * Update update.rs * Update lock_page.rs * Update block_user.rs * Update delete.rs * Update undo_block_user.rs * Update collection_remove.rs * Update post.rs * Update hide.rs * Update person.rs * Update remove.rs * Update post_view.rs * Update create.rs * Update remove.rs * Update collection_add.rs * Update community.rs * Update update.rs * Update post_aggregates.rs * Update update.rs * Update comment.rs * Update code_migrations.rs * Update registration_application_view.rs * Update update.rs * Update ban_person.rs * Update community.rs * Update delete.rs * Update delete.rs * Update delete.rs * Update person_aggregates.rs * Update save_settings.rs * Update distinguish.rs * Update mark_read.rs * Update site_aggregates.rs * Update create.rs * Fix * rerun ci * Update comment.rs * rerun ci * Update create.rs * Update create.rs * Update post_view.rs * rerun ci * Update undo_delete.rs * rerun ci --- crates/api/src/comment/distinguish.rs | 7 +- crates/api/src/community/hide.rs | 7 +- crates/api/src/local_user/add_admin.rs | 5 +- crates/api/src/local_user/ban_person.rs | 9 +- crates/api/src/local_user/save_settings.rs | 58 +++++------ crates/api/src/local_user/verify_email.rs | 9 +- crates/api/src/post/feature.rs | 14 +-- crates/api/src/post/lock.rs | 5 +- crates/api/src/private_message/mark_read.rs | 5 +- crates/api/src/site/leave_admin.rs | 5 +- .../site/registration_applications/approve.rs | 7 +- crates/api_common/src/utils.rs | 28 ++++-- crates/api_crud/src/comment/create.rs | 5 +- crates/api_crud/src/comment/delete.rs | 5 +- crates/api_crud/src/comment/remove.rs | 5 +- crates/api_crud/src/comment/update.rs | 11 ++- crates/api_crud/src/community/delete.rs | 7 +- crates/api_crud/src/community/remove.rs | 7 +- crates/api_crud/src/community/update.rs | 19 ++-- crates/api_crud/src/post/create.rs | 5 +- crates/api_crud/src/post/delete.rs | 7 +- crates/api_crud/src/post/remove.rs | 5 +- crates/api_crud/src/post/update.rs | 25 ++--- crates/api_crud/src/private_message/create.rs | 7 +- crates/api_crud/src/private_message/delete.rs | 7 +- crates/api_crud/src/private_message/update.rs | 9 +- crates/api_crud/src/site/create.rs | 97 ++++++++++--------- crates/api_crud/src/site/update.rs | 89 +++++++++-------- .../apub/src/activities/block/block_user.rs | 9 +- .../src/activities/block/undo_block_user.rs | 9 +- .../activities/community/collection_add.rs | 7 +- .../activities/community/collection_remove.rs | 7 +- .../src/activities/community/lock_page.rs | 10 +- crates/apub/src/activities/deletion/delete.rs | 15 ++- crates/apub/src/activities/deletion/mod.rs | 24 +++-- .../src/activities/deletion/undo_delete.rs | 15 ++- crates/apub/src/objects/comment.rs | 5 +- crates/apub/src/objects/community.rs | 5 +- crates/apub/src/objects/person.rs | 5 +- crates/apub/src/objects/post.rs | 5 +- .../src/aggregates/person_aggregates.rs | 10 +- .../src/aggregates/post_aggregates.rs | 20 +++- .../src/aggregates/site_aggregates.rs | 20 +++- crates/db_schema/src/impls/comment.rs | 7 +- crates/db_schema/src/impls/community.rs | 7 +- crates/db_schema/src/impls/person.rs | 7 +- crates/db_schema/src/impls/post.rs | 7 +- crates/db_schema/src/impls/private_message.rs | 19 ++-- crates/db_schema/src/source/comment.rs | 3 +- crates/db_schema/src/source/community.rs | 3 +- crates/db_schema/src/source/local_site.rs | 3 +- .../src/source/local_site_rate_limit.rs | 3 +- crates/db_schema/src/source/local_user.rs | 3 +- crates/db_schema/src/source/person.rs | 3 +- crates/db_schema/src/source/post.rs | 3 +- .../db_schema/src/source/private_message.rs | 3 +- crates/db_schema/src/source/site.rs | 3 +- crates/db_views/src/post_view.rs | 31 +++--- .../src/registration_application_view.rs | 7 +- src/code_migrations.rs | 78 ++++++++------- 60 files changed, 492 insertions(+), 333 deletions(-) diff --git a/crates/api/src/comment/distinguish.rs b/crates/api/src/comment/distinguish.rs index 367ffcbf..7db9a58f 100644 --- a/crates/api/src/comment/distinguish.rs +++ b/crates/api/src/comment/distinguish.rs @@ -38,9 +38,10 @@ pub async fn distinguish_comment( // Update the Comment let comment_id = data.comment_id; - let form = CommentUpdateForm::builder() - .distinguished(Some(data.distinguished)) - .build(); + let form = CommentUpdateForm { + distinguished: Some(data.distinguished), + ..Default::default() + }; Comment::update(&mut context.pool(), comment_id, &form) .await .with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?; diff --git a/crates/api/src/community/hide.rs b/crates/api/src/community/hide.rs index ce437ad9..10ca6372 100644 --- a/crates/api/src/community/hide.rs +++ b/crates/api/src/community/hide.rs @@ -25,9 +25,10 @@ pub async fn hide_community( let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?; is_admin(&local_user_view)?; - let community_form = CommunityUpdateForm::builder() - .hidden(Some(data.hidden)) - .build(); + let community_form = CommunityUpdateForm { + hidden: Some(data.hidden), + ..Default::default() + }; let mod_hide_community_form = ModHideCommunityForm { community_id: data.community_id, diff --git a/crates/api/src/local_user/add_admin.rs b/crates/api/src/local_user/add_admin.rs index 0b478ea9..81ec588f 100644 --- a/crates/api/src/local_user/add_admin.rs +++ b/crates/api/src/local_user/add_admin.rs @@ -32,7 +32,10 @@ impl Perform for AddAdmin { let added_admin = Person::update( &mut context.pool(), added_person_id, - &PersonUpdateForm::builder().admin(Some(added)).build(), + &PersonUpdateForm { + admin: Some(added), + ..Default::default() + }, ) .await .with_lemmy_type(LemmyErrorType::CouldntUpdateUser)?; diff --git a/crates/api/src/local_user/ban_person.rs b/crates/api/src/local_user/ban_person.rs index 6e99ef25..490a5144 100644 --- a/crates/api/src/local_user/ban_person.rs +++ b/crates/api/src/local_user/ban_person.rs @@ -35,10 +35,11 @@ pub async fn ban_from_site( let person = Person::update( &mut context.pool(), data.person_id, - &PersonUpdateForm::builder() - .banned(Some(data.ban)) - .ban_expires(Some(expires)) - .build(), + &PersonUpdateForm { + banned: Some(data.ban), + ban_expires: Some(expires), + ..Default::default() + }, ) .await .with_lemmy_type(LemmyErrorType::CouldntUpdateUser)?; diff --git a/crates/api/src/local_user/save_settings.rs b/crates/api/src/local_user/save_settings.rs index 152c11ad..946b5e8b 100644 --- a/crates/api/src/local_user/save_settings.rs +++ b/crates/api/src/local_user/save_settings.rs @@ -90,14 +90,15 @@ impl Perform for SaveUserSettings { let default_sort_type = data.default_sort_type; let theme = sanitize_html_opt(&data.theme); - let person_form = PersonUpdateForm::builder() - .display_name(display_name) - .bio(bio) - .matrix_user_id(matrix_user_id) - .bot_account(data.bot_account) - .avatar(avatar) - .banner(banner) - .build(); + let person_form = PersonUpdateForm { + display_name, + bio, + matrix_user_id, + bot_account: data.bot_account, + avatar, + banner, + ..Default::default() + }; Person::update(&mut context.pool(), person_id, &person_form) .await @@ -121,26 +122,27 @@ impl Perform for SaveUserSettings { (None, None) }; - let local_user_form = LocalUserUpdateForm::builder() - .email(email) - .show_avatars(data.show_avatars) - .show_read_posts(data.show_read_posts) - .show_new_post_notifs(data.show_new_post_notifs) - .send_notifications_to_email(data.send_notifications_to_email) - .show_nsfw(data.show_nsfw) - .blur_nsfw(data.blur_nsfw) - .auto_expand(data.auto_expand) - .show_bot_accounts(data.show_bot_accounts) - .show_scores(data.show_scores) - .default_sort_type(default_sort_type) - .default_listing_type(default_listing_type) - .theme(theme) - .interface_language(data.interface_language.clone()) - .totp_2fa_secret(totp_2fa_secret) - .totp_2fa_url(totp_2fa_url) - .open_links_in_new_tab(data.open_links_in_new_tab) - .infinite_scroll_enabled(data.infinite_scroll_enabled) - .build(); + let local_user_form = LocalUserUpdateForm { + email, + show_avatars: data.show_avatars, + show_read_posts: data.show_read_posts, + show_new_post_notifs: data.show_new_post_notifs, + send_notifications_to_email: data.send_notifications_to_email, + show_nsfw: data.show_nsfw, + blur_nsfw: data.blur_nsfw, + auto_expand: data.auto_expand, + show_bot_accounts: data.show_bot_accounts, + show_scores: data.show_scores, + default_sort_type, + default_listing_type, + theme, + interface_language: data.interface_language.clone(), + totp_2fa_secret, + totp_2fa_url, + open_links_in_new_tab: data.open_links_in_new_tab, + infinite_scroll_enabled: data.infinite_scroll_enabled, + ..Default::default() + }; let local_user_res = LocalUser::update(&mut context.pool(), local_user_id, &local_user_form).await; diff --git a/crates/api/src/local_user/verify_email.rs b/crates/api/src/local_user/verify_email.rs index a0c4763a..a15743ea 100644 --- a/crates/api/src/local_user/verify_email.rs +++ b/crates/api/src/local_user/verify_email.rs @@ -23,12 +23,13 @@ impl Perform for VerifyEmail { .await .with_lemmy_type(LemmyErrorType::TokenNotFound)?; - let form = LocalUserUpdateForm::builder() + let form = LocalUserUpdateForm { // necessary in case this is a new signup - .email_verified(Some(true)) + email_verified: Some(true), // necessary in case email of an existing user was changed - .email(Some(Some(verification.email))) - .build(); + email: Some(Some(verification.email)), + ..Default::default() + }; let local_user_id = verification.local_user_id; LocalUser::update(&mut context.pool(), local_user_id, &form).await?; diff --git a/crates/api/src/post/feature.rs b/crates/api/src/post/feature.rs index 5e18c2b6..02b9551a 100644 --- a/crates/api/src/post/feature.rs +++ b/crates/api/src/post/feature.rs @@ -56,13 +56,15 @@ pub async fn feature_post( // Update the post let post_id = data.post_id; let new_post: PostUpdateForm = if data.feature_type == PostFeatureType::Community { - PostUpdateForm::builder() - .featured_community(Some(data.featured)) - .build() + PostUpdateForm { + featured_community: Some(data.featured), + ..Default::default() + } } else { - PostUpdateForm::builder() - .featured_local(Some(data.featured)) - .build() + PostUpdateForm { + featured_local: Some(data.featured), + ..Default::default() + } }; let post = Post::update(&mut context.pool(), post_id, &new_post).await?; diff --git a/crates/api/src/post/lock.rs b/crates/api/src/post/lock.rs index 45ec3317..b2ba9b3d 100644 --- a/crates/api/src/post/lock.rs +++ b/crates/api/src/post/lock.rs @@ -53,7 +53,10 @@ pub async fn lock_post( let post = Post::update( &mut context.pool(), post_id, - &PostUpdateForm::builder().locked(Some(locked)).build(), + &PostUpdateForm { + locked: Some(locked), + ..Default::default() + }, ) .await?; diff --git a/crates/api/src/private_message/mark_read.rs b/crates/api/src/private_message/mark_read.rs index cca37fde..54fb4790 100644 --- a/crates/api/src/private_message/mark_read.rs +++ b/crates/api/src/private_message/mark_read.rs @@ -38,7 +38,10 @@ impl Perform for MarkPrivateMessageAsRead { PrivateMessage::update( &mut context.pool(), private_message_id, - &PrivateMessageUpdateForm::builder().read(Some(read)).build(), + &PrivateMessageUpdateForm { + read: Some(read), + ..Default::default() + }, ) .await .with_lemmy_type(LemmyErrorType::CouldntUpdatePrivateMessage)?; diff --git a/crates/api/src/site/leave_admin.rs b/crates/api/src/site/leave_admin.rs index 3781c73f..570f9d52 100644 --- a/crates/api/src/site/leave_admin.rs +++ b/crates/api/src/site/leave_admin.rs @@ -43,7 +43,10 @@ impl Perform for LeaveAdmin { Person::update( &mut context.pool(), person_id, - &PersonUpdateForm::builder().admin(Some(false)).build(), + &PersonUpdateForm { + admin: Some(false), + ..Default::default() + }, ) .await?; diff --git a/crates/api/src/site/registration_applications/approve.rs b/crates/api/src/site/registration_applications/approve.rs index 227f9324..eb0fb032 100644 --- a/crates/api/src/site/registration_applications/approve.rs +++ b/crates/api/src/site/registration_applications/approve.rs @@ -40,9 +40,10 @@ impl Perform for ApproveRegistrationApplication { RegistrationApplication::update(&mut context.pool(), app_id, &app_form).await?; // Update the local_user row - let local_user_form = LocalUserUpdateForm::builder() - .accepted_application(Some(data.approve)) - .build(); + let local_user_form = LocalUserUpdateForm { + accepted_application: Some(data.approve), + ..Default::default() + }; let approved_user_id = registration_application.local_user_id; LocalUser::update(&mut context.pool(), approved_user_id, &local_user_form).await?; diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index 78d7b4ca..4d434afc 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -596,10 +596,11 @@ pub async fn remove_user_data( Person::update( pool, banned_person_id, - &PersonUpdateForm::builder() - .avatar(Some(None)) - .banner(Some(None)) - .build(), + &PersonUpdateForm { + avatar: Some(None), + banner: Some(None), + ..Default::default() + }, ) .await?; @@ -625,7 +626,10 @@ pub async fn remove_user_data( Community::update( pool, community_id, - &CommunityUpdateForm::builder().removed(Some(true)).build(), + &CommunityUpdateForm { + removed: Some(true), + ..Default::default() + }, ) .await?; @@ -642,10 +646,11 @@ pub async fn remove_user_data( Community::update( pool, community_id, - &CommunityUpdateForm::builder() - .icon(Some(None)) - .banner(Some(None)) - .build(), + &CommunityUpdateForm { + icon: Some(None), + banner: Some(None), + ..Default::default() + }, ) .await?; } @@ -679,7 +684,10 @@ pub async fn remove_user_data_in_community( Comment::update( pool, comment_id, - &CommentUpdateForm::builder().removed(Some(true)).build(), + &CommentUpdateForm { + removed: Some(true), + ..Default::default() + }, ) .await?; } diff --git a/crates/api_crud/src/comment/create.rs b/crates/api_crud/src/comment/create.rs index 678bcfb0..33e480a9 100644 --- a/crates/api_crud/src/comment/create.rs +++ b/crates/api_crud/src/comment/create.rs @@ -129,7 +129,10 @@ pub async fn create_comment( let updated_comment = Comment::update( &mut context.pool(), inserted_comment_id, - &CommentUpdateForm::builder().ap_id(Some(apub_id)).build(), + &CommentUpdateForm { + ap_id: Some(apub_id), + ..Default::default() + }, ) .await .with_lemmy_type(LemmyErrorType::CouldntCreateComment)?; diff --git a/crates/api_crud/src/comment/delete.rs b/crates/api_crud/src/comment/delete.rs index 81a0116a..96c22b60 100644 --- a/crates/api_crud/src/comment/delete.rs +++ b/crates/api_crud/src/comment/delete.rs @@ -49,7 +49,10 @@ pub async fn delete_comment( let updated_comment = Comment::update( &mut context.pool(), comment_id, - &CommentUpdateForm::builder().deleted(Some(deleted)).build(), + &CommentUpdateForm { + deleted: Some(deleted), + ..Default::default() + }, ) .await .with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?; diff --git a/crates/api_crud/src/comment/remove.rs b/crates/api_crud/src/comment/remove.rs index b3afcc75..2bb5c75f 100644 --- a/crates/api_crud/src/comment/remove.rs +++ b/crates/api_crud/src/comment/remove.rs @@ -48,7 +48,10 @@ pub async fn remove_comment( let updated_comment = Comment::update( &mut context.pool(), comment_id, - &CommentUpdateForm::builder().removed(Some(removed)).build(), + &CommentUpdateForm { + removed: Some(removed), + ..Default::default() + }, ) .await .with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?; diff --git a/crates/api_crud/src/comment/update.rs b/crates/api_crud/src/comment/update.rs index e170f2e0..a07ee454 100644 --- a/crates/api_crud/src/comment/update.rs +++ b/crates/api_crud/src/comment/update.rs @@ -71,11 +71,12 @@ pub async fn update_comment( let content = sanitize_html_opt(&content); let comment_id = data.comment_id; - let form = CommentUpdateForm::builder() - .content(content) - .language_id(data.language_id) - .updated(Some(Some(naive_now()))) - .build(); + let form = CommentUpdateForm { + content, + language_id: data.language_id, + updated: Some(Some(naive_now())), + ..Default::default() + }; let updated_comment = Comment::update(&mut context.pool(), comment_id, &form) .await .with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?; diff --git a/crates/api_crud/src/community/delete.rs b/crates/api_crud/src/community/delete.rs index e23b1f40..9c8db512 100644 --- a/crates/api_crud/src/community/delete.rs +++ b/crates/api_crud/src/community/delete.rs @@ -35,9 +35,10 @@ pub async fn delete_community( let community = Community::update( &mut context.pool(), community_id, - &CommunityUpdateForm::builder() - .deleted(Some(deleted)) - .build(), + &CommunityUpdateForm { + deleted: Some(deleted), + ..Default::default() + }, ) .await .with_lemmy_type(LemmyErrorType::CouldntUpdateCommunity)?; diff --git a/crates/api_crud/src/community/remove.rs b/crates/api_crud/src/community/remove.rs index b79b2a66..f0bee639 100644 --- a/crates/api_crud/src/community/remove.rs +++ b/crates/api_crud/src/community/remove.rs @@ -35,9 +35,10 @@ pub async fn remove_community( let community = Community::update( &mut context.pool(), community_id, - &CommunityUpdateForm::builder() - .removed(Some(removed)) - .build(), + &CommunityUpdateForm { + removed: Some(removed), + ..Default::default() + }, ) .await .with_lemmy_type(LemmyErrorType::CouldntUpdateCommunity)?; diff --git a/crates/api_crud/src/community/update.rs b/crates/api_crud/src/community/update.rs index baa4e1bd..cf53ff89 100644 --- a/crates/api_crud/src/community/update.rs +++ b/crates/api_crud/src/community/update.rs @@ -65,15 +65,16 @@ pub async fn update_community( CommunityLanguage::update(&mut context.pool(), languages, community_id).await?; } - let community_form = CommunityUpdateForm::builder() - .title(title) - .description(description) - .icon(icon) - .banner(banner) - .nsfw(data.nsfw) - .posting_restricted_to_mods(data.posting_restricted_to_mods) - .updated(Some(Some(naive_now()))) - .build(); + let community_form = CommunityUpdateForm { + title, + description, + icon, + banner, + nsfw: data.nsfw, + posting_restricted_to_mods: data.posting_restricted_to_mods, + updated: Some(Some(naive_now())), + ..Default::default() + }; let community_id = data.community_id; let community = Community::update(&mut context.pool(), community_id, &community_form) diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index dd88204a..07e2cc27 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -148,7 +148,10 @@ pub async fn create_post( let updated_post = Post::update( &mut context.pool(), inserted_post_id, - &PostUpdateForm::builder().ap_id(Some(apub_id)).build(), + &PostUpdateForm { + ap_id: Some(apub_id), + ..Default::default() + }, ) .await .with_lemmy_type(LemmyErrorType::CouldntCreatePost)?; diff --git a/crates/api_crud/src/post/delete.rs b/crates/api_crud/src/post/delete.rs index 0d5eea88..79c8af0f 100644 --- a/crates/api_crud/src/post/delete.rs +++ b/crates/api_crud/src/post/delete.rs @@ -45,9 +45,10 @@ pub async fn delete_post( let post = Post::update( &mut context.pool(), data.post_id, - &PostUpdateForm::builder() - .deleted(Some(data.deleted)) - .build(), + &PostUpdateForm { + deleted: Some(data.deleted), + ..Default::default() + }, ) .await?; diff --git a/crates/api_crud/src/post/remove.rs b/crates/api_crud/src/post/remove.rs index 4a87eb78..ee100cfd 100644 --- a/crates/api_crud/src/post/remove.rs +++ b/crates/api_crud/src/post/remove.rs @@ -47,7 +47,10 @@ pub async fn remove_post( let post = Post::update( &mut context.pool(), post_id, - &PostUpdateForm::builder().removed(Some(removed)).build(), + &PostUpdateForm { + removed: Some(removed), + ..Default::default() + }, ) .await?; diff --git a/crates/api_crud/src/post/update.rs b/crates/api_crud/src/post/update.rs index c831c88f..a0f56aeb 100644 --- a/crates/api_crud/src/post/update.rs +++ b/crates/api_crud/src/post/update.rs @@ -93,18 +93,19 @@ pub async fn update_post( ) .await?; - let post_form = PostUpdateForm::builder() - .name(name) - .url(url) - .body(body) - .nsfw(data.nsfw) - .embed_title(embed_title) - .embed_description(embed_description) - .embed_video_url(embed_video_url) - .language_id(data.language_id) - .thumbnail_url(Some(thumbnail_url)) - .updated(Some(Some(naive_now()))) - .build(); + let post_form = PostUpdateForm { + name, + url, + body, + nsfw: data.nsfw, + embed_title, + embed_description, + embed_video_url, + language_id: data.language_id, + thumbnail_url: Some(thumbnail_url), + updated: Some(Some(naive_now())), + ..Default::default() + }; let post_id = data.post_id; let updated_post = Post::update(&mut context.pool(), post_id, &post_form) diff --git a/crates/api_crud/src/private_message/create.rs b/crates/api_crud/src/private_message/create.rs index b9ac916f..f5e4b15a 100644 --- a/crates/api_crud/src/private_message/create.rs +++ b/crates/api_crud/src/private_message/create.rs @@ -67,9 +67,10 @@ pub async fn create_private_message( PrivateMessage::update( &mut context.pool(), inserted_private_message.id, - &PrivateMessageUpdateForm::builder() - .ap_id(Some(apub_id)) - .build(), + &PrivateMessageUpdateForm { + ap_id: Some(apub_id), + ..Default::default() + }, ) .await .with_lemmy_type(LemmyErrorType::CouldntCreatePrivateMessage)?; diff --git a/crates/api_crud/src/private_message/delete.rs b/crates/api_crud/src/private_message/delete.rs index 7657a7ff..2a50dc0a 100644 --- a/crates/api_crud/src/private_message/delete.rs +++ b/crates/api_crud/src/private_message/delete.rs @@ -33,9 +33,10 @@ pub async fn delete_private_message( let private_message = PrivateMessage::update( &mut context.pool(), private_message_id, - &PrivateMessageUpdateForm::builder() - .deleted(Some(deleted)) - .build(), + &PrivateMessageUpdateForm { + deleted: Some(deleted), + ..Default::default() + }, ) .await .with_lemmy_type(LemmyErrorType::CouldntUpdatePrivateMessage)?; diff --git a/crates/api_crud/src/private_message/update.rs b/crates/api_crud/src/private_message/update.rs index eb24d7c1..d9e53776 100644 --- a/crates/api_crud/src/private_message/update.rs +++ b/crates/api_crud/src/private_message/update.rs @@ -44,10 +44,11 @@ pub async fn update_private_message( PrivateMessage::update( &mut context.pool(), private_message_id, - &PrivateMessageUpdateForm::builder() - .content(Some(content)) - .updated(Some(Some(naive_now()))) - .build(), + &PrivateMessageUpdateForm { + content: Some(content), + updated: Some(Some(naive_now())), + ..Default::default() + }, ) .await .with_lemmy_type(LemmyErrorType::CouldntUpdatePrivateMessage)?; diff --git a/crates/api_crud/src/site/create.rs b/crates/api_crud/src/site/create.rs index f7beb254..38d6111c 100644 --- a/crates/api_crud/src/site/create.rs +++ b/crates/api_crud/src/site/create.rs @@ -60,18 +60,19 @@ pub async fn create_site( let sidebar = sanitize_html_opt(&data.sidebar); let description = sanitize_html_opt(&data.description); - let site_form = SiteUpdateForm::builder() - .name(Some(name)) - .sidebar(diesel_option_overwrite(sidebar)) - .description(diesel_option_overwrite(description)) - .icon(diesel_option_overwrite_to_url(&data.icon)?) - .banner(diesel_option_overwrite_to_url(&data.banner)?) - .actor_id(Some(actor_id)) - .last_refreshed_at(Some(naive_now())) - .inbox_url(inbox_url) - .private_key(Some(Some(keypair.private_key))) - .public_key(Some(keypair.public_key)) - .build(); + let site_form = SiteUpdateForm { + name: Some(name), + sidebar: diesel_option_overwrite(sidebar), + description: diesel_option_overwrite(description), + icon: diesel_option_overwrite_to_url(&data.icon)?, + banner: diesel_option_overwrite_to_url(&data.banner)?, + actor_id: Some(actor_id), + last_refreshed_at: Some(naive_now()), + inbox_url, + private_key: Some(Some(keypair.private_key)), + public_key: Some(keypair.public_key), + ..Default::default() + }; let site_id = local_site.site_id; @@ -81,45 +82,47 @@ pub async fn create_site( let default_theme = sanitize_html_opt(&data.default_theme); let legal_information = sanitize_html_opt(&data.legal_information); - let local_site_form = LocalSiteUpdateForm::builder() + let local_site_form = LocalSiteUpdateForm { // Set the site setup to true - .site_setup(Some(true)) - .enable_downvotes(data.enable_downvotes) - .registration_mode(data.registration_mode) - .enable_nsfw(data.enable_nsfw) - .community_creation_admin_only(data.community_creation_admin_only) - .require_email_verification(data.require_email_verification) - .application_question(diesel_option_overwrite(application_question)) - .private_instance(data.private_instance) - .default_theme(default_theme) - .default_post_listing_type(data.default_post_listing_type) - .legal_information(diesel_option_overwrite(legal_information)) - .application_email_admins(data.application_email_admins) - .hide_modlog_mod_names(data.hide_modlog_mod_names) - .updated(Some(Some(naive_now()))) - .slur_filter_regex(diesel_option_overwrite(data.slur_filter_regex.clone())) - .actor_name_max_length(data.actor_name_max_length) - .federation_enabled(data.federation_enabled) - .captcha_enabled(data.captcha_enabled) - .captcha_difficulty(data.captcha_difficulty.clone()) - .build(); + site_setup: Some(true), + enable_downvotes: data.enable_downvotes, + registration_mode: data.registration_mode, + enable_nsfw: data.enable_nsfw, + community_creation_admin_only: data.community_creation_admin_only, + require_email_verification: data.require_email_verification, + application_question: diesel_option_overwrite(application_question), + private_instance: data.private_instance, + default_theme, + default_post_listing_type: data.default_post_listing_type, + legal_information: diesel_option_overwrite(legal_information), + application_email_admins: data.application_email_admins, + hide_modlog_mod_names: data.hide_modlog_mod_names, + updated: Some(Some(naive_now())), + slur_filter_regex: diesel_option_overwrite(data.slur_filter_regex.clone()), + actor_name_max_length: data.actor_name_max_length, + federation_enabled: data.federation_enabled, + captcha_enabled: data.captcha_enabled, + captcha_difficulty: data.captcha_difficulty.clone(), + ..Default::default() + }; LocalSite::update(&mut context.pool(), &local_site_form).await?; - let local_site_rate_limit_form = LocalSiteRateLimitUpdateForm::builder() - .message(data.rate_limit_message) - .message_per_second(data.rate_limit_message_per_second) - .post(data.rate_limit_post) - .post_per_second(data.rate_limit_post_per_second) - .register(data.rate_limit_register) - .register_per_second(data.rate_limit_register_per_second) - .image(data.rate_limit_image) - .image_per_second(data.rate_limit_image_per_second) - .comment(data.rate_limit_comment) - .comment_per_second(data.rate_limit_comment_per_second) - .search(data.rate_limit_search) - .search_per_second(data.rate_limit_search_per_second) - .build(); + let local_site_rate_limit_form = LocalSiteRateLimitUpdateForm { + message: data.rate_limit_message, + message_per_second: data.rate_limit_message_per_second, + post: data.rate_limit_post, + post_per_second: data.rate_limit_post_per_second, + register: data.rate_limit_register, + register_per_second: data.rate_limit_register_per_second, + image: data.rate_limit_image, + image_per_second: data.rate_limit_image_per_second, + comment: data.rate_limit_comment, + comment_per_second: data.rate_limit_comment_per_second, + search: data.rate_limit_search, + search_per_second: data.rate_limit_search_per_second, + ..Default::default() + }; LocalSiteRateLimit::update(&mut context.pool(), &local_site_rate_limit_form).await?; diff --git a/crates/api_crud/src/site/update.rs b/crates/api_crud/src/site/update.rs index f560c729..6148d546 100644 --- a/crates/api_crud/src/site/update.rs +++ b/crates/api_crud/src/site/update.rs @@ -63,14 +63,15 @@ pub async fn update_site( let sidebar = sanitize_html_opt(&data.sidebar); let description = sanitize_html_opt(&data.description); - let site_form = SiteUpdateForm::builder() - .name(name) - .sidebar(diesel_option_overwrite(sidebar)) - .description(diesel_option_overwrite(description)) - .icon(diesel_option_overwrite_to_url(&data.icon)?) - .banner(diesel_option_overwrite_to_url(&data.banner)?) - .updated(Some(Some(naive_now()))) - .build(); + let site_form = SiteUpdateForm { + name, + sidebar: diesel_option_overwrite(sidebar), + description: diesel_option_overwrite(description), + icon: diesel_option_overwrite_to_url(&data.icon)?, + banner: diesel_option_overwrite_to_url(&data.banner)?, + updated: Some(Some(naive_now())), + ..Default::default() + }; Site::update(&mut context.pool(), site.id, &site_form) .await @@ -82,46 +83,48 @@ pub async fn update_site( let default_theme = sanitize_html_opt(&data.default_theme); let legal_information = sanitize_html_opt(&data.legal_information); - let local_site_form = LocalSiteUpdateForm::builder() - .enable_downvotes(data.enable_downvotes) - .registration_mode(data.registration_mode) - .enable_nsfw(data.enable_nsfw) - .community_creation_admin_only(data.community_creation_admin_only) - .require_email_verification(data.require_email_verification) - .application_question(diesel_option_overwrite(application_question)) - .private_instance(data.private_instance) - .default_theme(default_theme) - .default_post_listing_type(data.default_post_listing_type) - .legal_information(diesel_option_overwrite(legal_information)) - .application_email_admins(data.application_email_admins) - .hide_modlog_mod_names(data.hide_modlog_mod_names) - .updated(Some(Some(naive_now()))) - .slur_filter_regex(diesel_option_overwrite(data.slur_filter_regex.clone())) - .actor_name_max_length(data.actor_name_max_length) - .federation_enabled(data.federation_enabled) - .captcha_enabled(data.captcha_enabled) - .captcha_difficulty(data.captcha_difficulty.clone()) - .reports_email_admins(data.reports_email_admins) - .build(); + let local_site_form = LocalSiteUpdateForm { + enable_downvotes: data.enable_downvotes, + registration_mode: data.registration_mode, + enable_nsfw: data.enable_nsfw, + community_creation_admin_only: data.community_creation_admin_only, + require_email_verification: data.require_email_verification, + application_question: diesel_option_overwrite(application_question), + private_instance: data.private_instance, + default_theme, + default_post_listing_type: data.default_post_listing_type, + legal_information: diesel_option_overwrite(legal_information), + application_email_admins: data.application_email_admins, + hide_modlog_mod_names: data.hide_modlog_mod_names, + updated: Some(Some(naive_now())), + slur_filter_regex: diesel_option_overwrite(data.slur_filter_regex.clone()), + actor_name_max_length: data.actor_name_max_length, + federation_enabled: data.federation_enabled, + captcha_enabled: data.captcha_enabled, + captcha_difficulty: data.captcha_difficulty.clone(), + reports_email_admins: data.reports_email_admins, + ..Default::default() + }; let update_local_site = LocalSite::update(&mut context.pool(), &local_site_form) .await .ok(); - let local_site_rate_limit_form = LocalSiteRateLimitUpdateForm::builder() - .message(data.rate_limit_message) - .message_per_second(data.rate_limit_message_per_second) - .post(data.rate_limit_post) - .post_per_second(data.rate_limit_post_per_second) - .register(data.rate_limit_register) - .register_per_second(data.rate_limit_register_per_second) - .image(data.rate_limit_image) - .image_per_second(data.rate_limit_image_per_second) - .comment(data.rate_limit_comment) - .comment_per_second(data.rate_limit_comment_per_second) - .search(data.rate_limit_search) - .search_per_second(data.rate_limit_search_per_second) - .build(); + let local_site_rate_limit_form = LocalSiteRateLimitUpdateForm { + message: data.rate_limit_message, + message_per_second: data.rate_limit_message_per_second, + post: data.rate_limit_post, + post_per_second: data.rate_limit_post_per_second, + register: data.rate_limit_register, + register_per_second: data.rate_limit_register_per_second, + image: data.rate_limit_image, + image_per_second: data.rate_limit_image_per_second, + comment: data.rate_limit_comment, + comment_per_second: data.rate_limit_comment_per_second, + search: data.rate_limit_search, + search_per_second: data.rate_limit_search_per_second, + ..Default::default() + }; LocalSiteRateLimit::update(&mut context.pool(), &local_site_rate_limit_form) .await diff --git a/crates/apub/src/activities/block/block_user.rs b/crates/apub/src/activities/block/block_user.rs index abfab845..b4fb53c7 100644 --- a/crates/apub/src/activities/block/block_user.rs +++ b/crates/apub/src/activities/block/block_user.rs @@ -157,10 +157,11 @@ impl ActivityHandler for BlockUser { let blocked_person = Person::update( &mut context.pool(), blocked_person.id, - &PersonUpdateForm::builder() - .banned(Some(true)) - .ban_expires(Some(expires)) - .build(), + &PersonUpdateForm { + banned: Some(true), + ban_expires: Some(expires), + ..Default::default() + }, ) .await?; if self.remove_data.unwrap_or(false) { diff --git a/crates/apub/src/activities/block/undo_block_user.rs b/crates/apub/src/activities/block/undo_block_user.rs index 2ebd053b..91cafa0a 100644 --- a/crates/apub/src/activities/block/undo_block_user.rs +++ b/crates/apub/src/activities/block/undo_block_user.rs @@ -105,10 +105,11 @@ impl ActivityHandler for UndoBlockUser { let blocked_person = Person::update( &mut context.pool(), blocked_person.id, - &PersonUpdateForm::builder() - .banned(Some(false)) - .ban_expires(Some(expires)) - .build(), + &PersonUpdateForm { + banned: Some(false), + ban_expires: Some(expires), + ..Default::default() + }, ) .await?; diff --git a/crates/apub/src/activities/community/collection_add.rs b/crates/apub/src/activities/community/collection_add.rs index e03ded2b..3d2daf4c 100644 --- a/crates/apub/src/activities/community/collection_add.rs +++ b/crates/apub/src/activities/community/collection_add.rs @@ -153,9 +153,10 @@ impl ActivityHandler for CollectionAdd { let post = ObjectId::::from(self.object) .dereference(context) .await?; - let form = PostUpdateForm::builder() - .featured_community(Some(true)) - .build(); + let form = PostUpdateForm { + featured_community: Some(true), + ..Default::default() + }; Post::update(&mut context.pool(), post.id, &form).await?; } } diff --git a/crates/apub/src/activities/community/collection_remove.rs b/crates/apub/src/activities/community/collection_remove.rs index 28214284..38ed9568 100644 --- a/crates/apub/src/activities/community/collection_remove.rs +++ b/crates/apub/src/activities/community/collection_remove.rs @@ -141,9 +141,10 @@ impl ActivityHandler for CollectionRemove { let post = ObjectId::::from(self.object) .dereference(context) .await?; - let form = PostUpdateForm::builder() - .featured_community(Some(false)) - .build(); + let form = PostUpdateForm { + featured_community: Some(false), + ..Default::default() + }; Post::update(&mut context.pool(), post.id, &form).await?; } } diff --git a/crates/apub/src/activities/community/lock_page.rs b/crates/apub/src/activities/community/lock_page.rs index 2ceb1838..446b7824 100644 --- a/crates/apub/src/activities/community/lock_page.rs +++ b/crates/apub/src/activities/community/lock_page.rs @@ -56,7 +56,10 @@ impl ActivityHandler for LockPage { } async fn receive(self, context: &Data) -> Result<(), Self::Error> { - let form = PostUpdateForm::builder().locked(Some(true)).build(); + let form = PostUpdateForm { + locked: Some(true), + ..Default::default() + }; let post = self.object.dereference(context).await?; Post::update(&mut context.pool(), post.id, &form).await?; Ok(()) @@ -93,7 +96,10 @@ impl ActivityHandler for UndoLockPage { } async fn receive(self, context: &Data) -> Result<(), Self::Error> { - let form = PostUpdateForm::builder().locked(Some(false)).build(); + let form = PostUpdateForm { + locked: Some(false), + ..Default::default() + }; let post = self.object.object.dereference(context).await?; Post::update(&mut context.pool(), post.id, &form).await?; Ok(()) diff --git a/crates/apub/src/activities/deletion/delete.rs b/crates/apub/src/activities/deletion/delete.rs index 06f7463a..7a35ec50 100644 --- a/crates/apub/src/activities/deletion/delete.rs +++ b/crates/apub/src/activities/deletion/delete.rs @@ -123,7 +123,10 @@ pub(in crate::activities) async fn receive_remove_action( Community::update( &mut context.pool(), community.id, - &CommunityUpdateForm::builder().removed(Some(true)).build(), + &CommunityUpdateForm { + removed: Some(true), + ..Default::default() + }, ) .await?; } @@ -138,7 +141,10 @@ pub(in crate::activities) async fn receive_remove_action( Post::update( &mut context.pool(), post.id, - &PostUpdateForm::builder().removed(Some(true)).build(), + &PostUpdateForm { + removed: Some(true), + ..Default::default() + }, ) .await?; } @@ -153,7 +159,10 @@ pub(in crate::activities) async fn receive_remove_action( Comment::update( &mut context.pool(), comment.id, - &CommentUpdateForm::builder().removed(Some(true)).build(), + &CommentUpdateForm { + removed: Some(true), + ..Default::default() + }, ) .await?; } diff --git a/crates/apub/src/activities/deletion/mod.rs b/crates/apub/src/activities/deletion/mod.rs index e03074f1..23ecd3bd 100644 --- a/crates/apub/src/activities/deletion/mod.rs +++ b/crates/apub/src/activities/deletion/mod.rs @@ -258,9 +258,10 @@ async fn receive_delete_action( Community::update( &mut context.pool(), community.id, - &CommunityUpdateForm::builder() - .deleted(Some(deleted)) - .build(), + &CommunityUpdateForm { + deleted: Some(deleted), + ..Default::default() + }, ) .await?; } @@ -269,7 +270,10 @@ async fn receive_delete_action( Post::update( &mut context.pool(), post.id, - &PostUpdateForm::builder().deleted(Some(deleted)).build(), + &PostUpdateForm { + deleted: Some(deleted), + ..Default::default() + }, ) .await?; } @@ -279,7 +283,10 @@ async fn receive_delete_action( Comment::update( &mut context.pool(), comment.id, - &CommentUpdateForm::builder().deleted(Some(deleted)).build(), + &CommentUpdateForm { + deleted: Some(deleted), + ..Default::default() + }, ) .await?; } @@ -288,9 +295,10 @@ async fn receive_delete_action( PrivateMessage::update( &mut context.pool(), pm.id, - &PrivateMessageUpdateForm::builder() - .deleted(Some(deleted)) - .build(), + &PrivateMessageUpdateForm { + deleted: Some(deleted), + ..Default::default() + }, ) .await?; } diff --git a/crates/apub/src/activities/deletion/undo_delete.rs b/crates/apub/src/activities/deletion/undo_delete.rs index 541a7455..4d782204 100644 --- a/crates/apub/src/activities/deletion/undo_delete.rs +++ b/crates/apub/src/activities/deletion/undo_delete.rs @@ -113,7 +113,10 @@ impl UndoDelete { Community::update( &mut context.pool(), community.id, - &CommunityUpdateForm::builder().removed(Some(false)).build(), + &CommunityUpdateForm { + removed: Some(false), + ..Default::default() + }, ) .await?; } @@ -128,7 +131,10 @@ impl UndoDelete { Post::update( &mut context.pool(), post.id, - &PostUpdateForm::builder().removed(Some(false)).build(), + &PostUpdateForm { + removed: Some(false), + ..Default::default() + }, ) .await?; } @@ -143,7 +149,10 @@ impl UndoDelete { Comment::update( &mut context.pool(), comment.id, - &CommentUpdateForm::builder().removed(Some(false)).build(), + &CommentUpdateForm { + removed: Some(false), + ..Default::default() + }, ) .await?; } diff --git a/crates/apub/src/objects/comment.rs b/crates/apub/src/objects/comment.rs index 3b05ed39..1b772443 100644 --- a/crates/apub/src/objects/comment.rs +++ b/crates/apub/src/objects/comment.rs @@ -78,7 +78,10 @@ impl Object for ApubComment { #[tracing::instrument(skip_all)] async fn delete(self, context: &Data) -> Result<(), LemmyError> { if !self.deleted { - let form = CommentUpdateForm::builder().deleted(Some(true)).build(); + let form = CommentUpdateForm { + deleted: Some(true), + ..Default::default() + }; Comment::update(&mut context.pool(), self.id, &form).await?; } Ok(()) diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index 75eb941b..10d5ddd4 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -74,7 +74,10 @@ impl Object for ApubCommunity { #[tracing::instrument(skip_all)] async fn delete(self, context: &Data) -> Result<(), LemmyError> { - let form = CommunityUpdateForm::builder().deleted(Some(true)).build(); + let form = CommunityUpdateForm { + deleted: Some(true), + ..Default::default() + }; Community::update(&mut context.pool(), self.id, &form).await?; Ok(()) } diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index 2c238fb5..907fd5f8 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -77,7 +77,10 @@ impl Object for ApubPerson { #[tracing::instrument(skip_all)] async fn delete(self, context: &Data) -> Result<(), LemmyError> { - let form = PersonUpdateForm::builder().deleted(Some(true)).build(); + let form = PersonUpdateForm { + deleted: Some(true), + ..Default::default() + }; DbPerson::update(&mut context.pool(), self.id, &form).await?; Ok(()) } diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index f04e07de..df3aefed 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -99,7 +99,10 @@ impl Object for ApubPost { #[tracing::instrument(skip_all)] async fn delete(self, context: &Data) -> Result<(), LemmyError> { if !self.deleted { - let form = PostUpdateForm::builder().deleted(Some(true)).build(); + let form = PostUpdateForm { + deleted: Some(true), + ..Default::default() + }; Post::update(&mut context.pool(), self.id, &form).await?; } Ok(()) diff --git a/crates/db_schema/src/aggregates/person_aggregates.rs b/crates/db_schema/src/aggregates/person_aggregates.rs index 2e71844f..e6195de2 100644 --- a/crates/db_schema/src/aggregates/person_aggregates.rs +++ b/crates/db_schema/src/aggregates/person_aggregates.rs @@ -145,14 +145,20 @@ mod tests { Comment::update( pool, inserted_comment.id, - &CommentUpdateForm::builder().removed(Some(true)).build(), + &CommentUpdateForm { + removed: Some(true), + ..Default::default() + }, ) .await .unwrap(); Comment::update( pool, inserted_child_comment.id, - &CommentUpdateForm::builder().removed(Some(true)).build(), + &CommentUpdateForm { + removed: Some(true), + ..Default::default() + }, ) .await .unwrap(); diff --git a/crates/db_schema/src/aggregates/post_aggregates.rs b/crates/db_schema/src/aggregates/post_aggregates.rs index 02037082..7847f394 100644 --- a/crates/db_schema/src/aggregates/post_aggregates.rs +++ b/crates/db_schema/src/aggregates/post_aggregates.rs @@ -235,7 +235,10 @@ mod tests { Comment::update( pool, inserted_comment.id, - &CommentUpdateForm::builder().removed(Some(true)).build(), + &CommentUpdateForm { + removed: Some(true), + ..Default::default() + }, ) .await .unwrap(); @@ -246,7 +249,10 @@ mod tests { Comment::update( pool, inserted_comment.id, - &CommentUpdateForm::builder().removed(Some(false)).build(), + &CommentUpdateForm { + removed: Some(false), + ..Default::default() + }, ) .await .unwrap(); @@ -254,7 +260,10 @@ mod tests { Comment::update( pool, inserted_comment.id, - &CommentUpdateForm::builder().deleted(Some(true)).build(), + &CommentUpdateForm { + deleted: Some(true), + ..Default::default() + }, ) .await .unwrap(); @@ -265,7 +274,10 @@ mod tests { Comment::update( pool, inserted_comment.id, - &CommentUpdateForm::builder().removed(Some(true)).build(), + &CommentUpdateForm { + removed: Some(true), + ..Default::default() + }, ) .await .unwrap(); diff --git a/crates/db_schema/src/aggregates/site_aggregates.rs b/crates/db_schema/src/aggregates/site_aggregates.rs index ea3da85a..4fe57720 100644 --- a/crates/db_schema/src/aggregates/site_aggregates.rs +++ b/crates/db_schema/src/aggregates/site_aggregates.rs @@ -160,7 +160,10 @@ mod tests { Community::update( pool, inserted_community.id, - &CommunityUpdateForm::builder().deleted(Some(true)).build(), + &CommunityUpdateForm { + deleted: Some(true), + ..Default::default() + }, ) .await .unwrap(); @@ -171,7 +174,10 @@ mod tests { Community::update( pool, inserted_community.id, - &CommunityUpdateForm::builder().deleted(Some(false)).build(), + &CommunityUpdateForm { + deleted: Some(false), + ..Default::default() + }, ) .await .unwrap(); @@ -179,7 +185,10 @@ mod tests { Community::update( pool, inserted_community.id, - &CommunityUpdateForm::builder().removed(Some(true)).build(), + &CommunityUpdateForm { + removed: Some(true), + ..Default::default() + }, ) .await .unwrap(); @@ -190,7 +199,10 @@ mod tests { Community::update( pool, inserted_community.id, - &CommunityUpdateForm::builder().deleted(Some(true)).build(), + &CommunityUpdateForm { + deleted: Some(true), + ..Default::default() + }, ) .await .unwrap(); diff --git a/crates/db_schema/src/impls/comment.rs b/crates/db_schema/src/impls/comment.rs index 88757cd0..cab033df 100644 --- a/crates/db_schema/src/impls/comment.rs +++ b/crates/db_schema/src/impls/comment.rs @@ -372,9 +372,10 @@ mod tests { published: inserted_comment_saved.published, }; - let comment_update_form = CommentUpdateForm::builder() - .content(Some("A test comment".into())) - .build(); + let comment_update_form = CommentUpdateForm { + content: Some("A test comment".into()), + ..Default::default() + }; let updated_comment = Comment::update(pool, inserted_comment.id, &comment_update_form) .await diff --git a/crates/db_schema/src/impls/community.rs b/crates/db_schema/src/impls/community.rs index d5d558fa..bedb9820 100644 --- a/crates/db_schema/src/impls/community.rs +++ b/crates/db_schema/src/impls/community.rs @@ -475,9 +475,10 @@ mod tests { let read_community = Community::read(pool, inserted_community.id).await.unwrap(); - let update_community_form = CommunityUpdateForm::builder() - .title(Some("nada".to_owned())) - .build(); + let update_community_form = CommunityUpdateForm { + title: Some("nada".to_owned()), + ..Default::default() + }; let updated_community = Community::update(pool, inserted_community.id, &update_community_form) .await .unwrap(); diff --git a/crates/db_schema/src/impls/person.rs b/crates/db_schema/src/impls/person.rs index 53f4a4df..43bdf5c3 100644 --- a/crates/db_schema/src/impls/person.rs +++ b/crates/db_schema/src/impls/person.rs @@ -253,9 +253,10 @@ mod tests { let read_person = Person::read(pool, inserted_person.id).await.unwrap(); - let update_person_form = PersonUpdateForm::builder() - .actor_id(Some(inserted_person.actor_id.clone())) - .build(); + let update_person_form = PersonUpdateForm { + actor_id: Some(inserted_person.actor_id.clone()), + ..Default::default() + }; let updated_person = Person::update(pool, inserted_person.id, &update_person_form) .await .unwrap(); diff --git a/crates/db_schema/src/impls/post.rs b/crates/db_schema/src/impls/post.rs index 60b8af2c..a798ddcb 100644 --- a/crates/db_schema/src/impls/post.rs +++ b/crates/db_schema/src/impls/post.rs @@ -453,9 +453,10 @@ mod tests { let read_post = Post::read(pool, inserted_post.id).await.unwrap(); - let new_post_update = PostUpdateForm::builder() - .name(Some("A test post".into())) - .build(); + let new_post_update = PostUpdateForm { + name: Some("A test post".into()), + ..Default::default() + }; let updated_post = Post::update(pool, inserted_post.id, &new_post_update) .await .unwrap(); diff --git a/crates/db_schema/src/impls/private_message.rs b/crates/db_schema/src/impls/private_message.rs index d422f0d2..81a4b185 100644 --- a/crates/db_schema/src/impls/private_message.rs +++ b/crates/db_schema/src/impls/private_message.rs @@ -142,9 +142,10 @@ mod tests { .await .unwrap(); - let private_message_update_form = PrivateMessageUpdateForm::builder() - .content(Some("A test private message".into())) - .build(); + let private_message_update_form = PrivateMessageUpdateForm { + content: Some("A test private message".into()), + ..Default::default() + }; let updated_private_message = PrivateMessage::update( pool, inserted_private_message.id, @@ -156,16 +157,20 @@ mod tests { let deleted_private_message = PrivateMessage::update( pool, inserted_private_message.id, - &PrivateMessageUpdateForm::builder() - .deleted(Some(true)) - .build(), + &PrivateMessageUpdateForm { + deleted: Some(true), + ..Default::default() + }, ) .await .unwrap(); let marked_read_private_message = PrivateMessage::update( pool, inserted_private_message.id, - &PrivateMessageUpdateForm::builder().read(Some(true)).build(), + &PrivateMessageUpdateForm { + read: Some(true), + ..Default::default() + }, ) .await .unwrap(); diff --git a/crates/db_schema/src/source/comment.rs b/crates/db_schema/src/source/comment.rs index ecf745ee..f76e2fba 100644 --- a/crates/db_schema/src/source/comment.rs +++ b/crates/db_schema/src/source/comment.rs @@ -66,8 +66,7 @@ pub struct CommentInsertForm { pub language_id: Option, } -#[derive(Debug, Clone, TypedBuilder)] -#[builder(field_defaults(default))] +#[derive(Debug, Clone, Default)] #[cfg_attr(feature = "full", derive(AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = comment))] pub struct CommentUpdateForm { diff --git a/crates/db_schema/src/source/community.rs b/crates/db_schema/src/source/community.rs index 64b30b2a..5d56c36a 100644 --- a/crates/db_schema/src/source/community.rs +++ b/crates/db_schema/src/source/community.rs @@ -97,8 +97,7 @@ pub struct CommunityInsertForm { pub instance_id: InstanceId, } -#[derive(Debug, Clone, TypedBuilder)] -#[builder(field_defaults(default))] +#[derive(Debug, Clone, Default)] #[cfg_attr(feature = "full", derive(AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = community))] pub struct CommunityUpdateForm { diff --git a/crates/db_schema/src/source/local_site.rs b/crates/db_schema/src/source/local_site.rs index be93717a..a57bf503 100644 --- a/crates/db_schema/src/source/local_site.rs +++ b/crates/db_schema/src/source/local_site.rs @@ -89,8 +89,7 @@ pub struct LocalSiteInsertForm { pub reports_email_admins: Option, } -#[derive(Clone, TypedBuilder)] -#[builder(field_defaults(default))] +#[derive(Clone, Default)] #[cfg_attr(feature = "full", derive(AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = local_site))] pub struct LocalSiteUpdateForm { diff --git a/crates/db_schema/src/source/local_site_rate_limit.rs b/crates/db_schema/src/source/local_site_rate_limit.rs index 9d3e3a25..ab14bfd8 100644 --- a/crates/db_schema/src/source/local_site_rate_limit.rs +++ b/crates/db_schema/src/source/local_site_rate_limit.rs @@ -57,8 +57,7 @@ pub struct LocalSiteRateLimitInsertForm { pub search_per_second: Option, } -#[derive(Clone, TypedBuilder)] -#[builder(field_defaults(default))] +#[derive(Clone, Default)] #[cfg_attr(feature = "full", derive(AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = local_site_rate_limit))] pub struct LocalSiteRateLimitUpdateForm { diff --git a/crates/db_schema/src/source/local_user.rs b/crates/db_schema/src/source/local_user.rs index 0d8db669..4e668bdd 100644 --- a/crates/db_schema/src/source/local_user.rs +++ b/crates/db_schema/src/source/local_user.rs @@ -90,8 +90,7 @@ pub struct LocalUserInsertForm { pub infinite_scroll_enabled: Option, } -#[derive(Clone, TypedBuilder)] -#[builder(field_defaults(default))] +#[derive(Clone, Default)] #[cfg_attr(feature = "full", derive(AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = local_user))] pub struct LocalUserUpdateForm { diff --git a/crates/db_schema/src/source/person.rs b/crates/db_schema/src/source/person.rs index 82d6f61a..7772bb11 100644 --- a/crates/db_schema/src/source/person.rs +++ b/crates/db_schema/src/source/person.rs @@ -89,10 +89,9 @@ pub struct PersonInsertForm { pub ban_expires: Option, } -#[derive(Clone, TypedBuilder)] +#[derive(Clone, Default)] #[cfg_attr(feature = "full", derive(AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = person))] -#[builder(field_defaults(default))] pub struct PersonUpdateForm { pub display_name: Option>, pub avatar: Option>, diff --git a/crates/db_schema/src/source/post.rs b/crates/db_schema/src/source/post.rs index 27eac6d9..de56f118 100644 --- a/crates/db_schema/src/source/post.rs +++ b/crates/db_schema/src/source/post.rs @@ -85,8 +85,7 @@ pub struct PostInsertForm { pub featured_local: Option, } -#[derive(Debug, Clone, TypedBuilder)] -#[builder(field_defaults(default))] +#[derive(Debug, Clone, Default)] #[cfg_attr(feature = "full", derive(AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = post))] pub struct PostUpdateForm { diff --git a/crates/db_schema/src/source/private_message.rs b/crates/db_schema/src/source/private_message.rs index 0ceaf762..bd8c73e3 100644 --- a/crates/db_schema/src/source/private_message.rs +++ b/crates/db_schema/src/source/private_message.rs @@ -49,8 +49,7 @@ pub struct PrivateMessageInsertForm { pub local: Option, } -#[derive(Clone, TypedBuilder)] -#[builder(field_defaults(default))] +#[derive(Clone, Default)] #[cfg_attr(feature = "full", derive(AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = private_message))] pub struct PrivateMessageUpdateForm { diff --git a/crates/db_schema/src/source/site.rs b/crates/db_schema/src/source/site.rs index 12b30c58..e45ece70 100644 --- a/crates/db_schema/src/source/site.rs +++ b/crates/db_schema/src/source/site.rs @@ -59,8 +59,7 @@ pub struct SiteInsertForm { pub instance_id: InstanceId, } -#[derive(Clone, TypedBuilder)] -#[builder(field_defaults(default))] +#[derive(Clone, Default)] #[cfg_attr(feature = "full", derive(AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = site))] pub struct SiteUpdateForm { diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 5fcb73f6..7d461d14 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -608,9 +608,10 @@ mod tests { let pool = &mut pool.into(); let mut data = init_data(pool).await; - let local_user_form = LocalUserUpdateForm::builder() - .show_bot_accounts(Some(false)) - .build(); + let local_user_form = LocalUserUpdateForm { + show_bot_accounts: Some(false), + ..Default::default() + }; let inserted_local_user = LocalUser::update(pool, data.local_user_view.local_user.id, &local_user_form) .await @@ -648,9 +649,10 @@ mod tests { post_listing_single_with_person ); - let local_user_form = LocalUserUpdateForm::builder() - .show_bot_accounts(Some(true)) - .build(); + let local_user_form = LocalUserUpdateForm { + show_bot_accounts: Some(true), + ..Default::default() + }; let inserted_local_user = LocalUser::update(pool, data.local_user_view.local_user.id, &local_user_form) .await @@ -780,9 +782,10 @@ mod tests { expected_post_with_upvote.counts.upvotes = 1; assert_eq!(expected_post_with_upvote, post_listing_single_with_person); - let local_user_form = LocalUserUpdateForm::builder() - .show_bot_accounts(Some(false)) - .build(); + let local_user_form = LocalUserUpdateForm { + show_bot_accounts: Some(false), + ..Default::default() + }; let inserted_local_user = LocalUser::update(pool, data.local_user_view.local_user.id, &local_user_form) .await @@ -925,7 +928,10 @@ mod tests { Post::update( pool, data.inserted_post.id, - &PostUpdateForm::builder().removed(Some(true)).build(), + &PostUpdateForm { + removed: Some(true), + ..Default::default() + }, ) .await .unwrap(); @@ -968,7 +974,10 @@ mod tests { Post::update( pool, data.inserted_post.id, - &PostUpdateForm::builder().deleted(Some(true)).build(), + &PostUpdateForm { + deleted: Some(true), + ..Default::default() + }, ) .await .unwrap(); diff --git a/crates/db_views/src/registration_application_view.rs b/crates/db_views/src/registration_application_view.rs index 6064bf05..bdea385c 100644 --- a/crates/db_views/src/registration_application_view.rs +++ b/crates/db_views/src/registration_application_view.rs @@ -350,9 +350,10 @@ mod tests { .unwrap(); // Update the local_user row - let approve_local_user_form = LocalUserUpdateForm::builder() - .accepted_application(Some(true)) - .build(); + let approve_local_user_form = LocalUserUpdateForm { + accepted_application: Some(true), + ..Default::default() + }; LocalUser::update(pool, inserted_sara_local_user.id, &approve_local_user_form) .await diff --git a/src/code_migrations.rs b/src/code_migrations.rs index ae7df397..51302524 100644 --- a/src/code_migrations.rs +++ b/src/code_migrations.rs @@ -77,16 +77,17 @@ async fn user_updates_2020_04_02( for cperson in &incorrect_persons { let keypair = generate_actor_keypair()?; - let form = PersonUpdateForm::builder() - .actor_id(Some(generate_local_apub_endpoint( + let form = PersonUpdateForm { + actor_id: Some(generate_local_apub_endpoint( EndpointType::Person, &cperson.name, protocol_and_hostname, - )?)) - .private_key(Some(Some(keypair.private_key))) - .public_key(Some(keypair.public_key)) - .last_refreshed_at(Some(naive_now())) - .build(); + )?), + private_key: Some(Some(keypair.private_key)), + public_key: Some(keypair.public_key), + last_refreshed_at: Some(naive_now()), + ..Default::default() + }; Person::update(pool, cperson.id, &form).await?; } @@ -120,12 +121,13 @@ async fn community_updates_2020_04_02( protocol_and_hostname, )?; - let form = CommunityUpdateForm::builder() - .actor_id(Some(community_actor_id.clone())) - .private_key(Some(Some(keypair.private_key))) - .public_key(Some(keypair.public_key)) - .last_refreshed_at(Some(naive_now())) - .build(); + let form = CommunityUpdateForm { + actor_id: Some(community_actor_id.clone()), + private_key: Some(Some(keypair.private_key)), + public_key: Some(keypair.public_key), + last_refreshed_at: Some(naive_now()), + ..Default::default() + }; Community::update(pool, ccommunity.id, &form).await?; } @@ -160,7 +162,10 @@ async fn post_updates_2020_04_03( Post::update( pool, cpost.id, - &PostUpdateForm::builder().ap_id(Some(apub_id)).build(), + &PostUpdateForm { + ap_id: Some(apub_id), + ..Default::default() + }, ) .await?; } @@ -195,7 +200,10 @@ async fn comment_updates_2020_04_03( Comment::update( pool, ccomment.id, - &CommentUpdateForm::builder().ap_id(Some(apub_id)).build(), + &CommentUpdateForm { + ap_id: Some(apub_id), + ..Default::default() + }, ) .await?; } @@ -230,9 +238,10 @@ async fn private_message_updates_2020_05_05( PrivateMessage::update( pool, cpm.id, - &PrivateMessageUpdateForm::builder() - .ap_id(Some(apub_id)) - .build(), + &PrivateMessageUpdateForm { + ap_id: Some(apub_id), + ..Default::default() + }, ) .await?; } @@ -344,13 +353,14 @@ async fn instance_actor_2022_01_28( } let key_pair = generate_actor_keypair()?; let actor_id = Url::parse(protocol_and_hostname)?; - let site_form = SiteUpdateForm::builder() - .actor_id(Some(actor_id.clone().into())) - .last_refreshed_at(Some(naive_now())) - .inbox_url(Some(generate_site_inbox_url(&actor_id.into())?)) - .private_key(Some(Some(key_pair.private_key))) - .public_key(Some(key_pair.public_key)) - .build(); + let site_form = SiteUpdateForm { + actor_id: Some(actor_id.clone().into()), + last_refreshed_at: Some(naive_now()), + inbox_url: Some(generate_site_inbox_url(&actor_id.into())?), + private_key: Some(Some(key_pair.private_key)), + public_key: Some(key_pair.public_key), + ..Default::default() + }; Site::update(pool, site.id, &site_form).await?; } Ok(()) @@ -379,10 +389,11 @@ async fn regenerate_public_keys_2022_07_05(pool: &mut DbPool<'_>) -> Result<(), community_.name ); let key_pair = generate_actor_keypair()?; - let form = CommunityUpdateForm::builder() - .public_key(Some(key_pair.public_key)) - .private_key(Some(Some(key_pair.private_key))) - .build(); + let form = CommunityUpdateForm { + public_key: Some(key_pair.public_key), + private_key: Some(Some(key_pair.private_key)), + ..Default::default() + }; Community::update(&mut conn.into(), community_.id, &form).await?; } } @@ -401,10 +412,11 @@ async fn regenerate_public_keys_2022_07_05(pool: &mut DbPool<'_>) -> Result<(), person_.name ); let key_pair = generate_actor_keypair()?; - let form = PersonUpdateForm::builder() - .public_key(Some(key_pair.public_key)) - .private_key(Some(Some(key_pair.private_key))) - .build(); + let form = PersonUpdateForm { + public_key: Some(key_pair.public_key), + private_key: Some(Some(key_pair.private_key)), + ..Default::default() + }; Person::update(pool, person_.id, &form).await?; } } -- 2.44.1