add enable_federated_downvotes site option main
authorself <self@awful.systems>
Tue, 25 Jul 2023 12:17:16 +0000 (05:17 -0700)
committerself <self@awful.systems>
Mon, 21 Aug 2023 18:49:54 +0000 (11:49 -0700)
crates/api_common/src/site.rs
crates/api_crud/src/site/create.rs
crates/api_crud/src/site/update.rs
crates/apub/src/activities/voting/vote.rs
crates/db_schema/src/schema.rs
crates/db_schema/src/source/local_site.rs
migrations/2023-07-25-113818_add_enable_federated_downvotes/down.sql [new file with mode: 0644]
migrations/2023-07-25-113818_add_enable_federated_downvotes/up.sql [new file with mode: 0644]

index 35b6d77ec0db25ae20cba5d78e63d26b429870a2..a5b2afae297fccc7270210bbc7055fe99456751e 100644 (file)
@@ -2,44 +2,20 @@ use crate::sensitive::Sensitive;
 use lemmy_db_schema::{
   newtypes::{CommentId, CommunityId, LanguageId, PersonId, PostId},
   source::{instance::Instance, language::Language, tagline::Tagline},
 use lemmy_db_schema::{
   newtypes::{CommentId, CommunityId, LanguageId, PersonId, PostId},
   source::{instance::Instance, language::Language, tagline::Tagline},
-  ListingType,
-  ModlogActionType,
-  RegistrationMode,
-  SearchType,
-  SortType,
+  ListingType, ModlogActionType, RegistrationMode, SearchType, SortType,
 };
 use lemmy_db_views::structs::{
 };
 use lemmy_db_views::structs::{
-  CommentView,
-  CustomEmojiView,
-  LocalUserView,
-  PostView,
-  RegistrationApplicationView,
-  SiteView,
+  CommentView, CustomEmojiView, LocalUserView, PostView, RegistrationApplicationView, SiteView,
 };
 use lemmy_db_views_actor::structs::{
 };
 use lemmy_db_views_actor::structs::{
-  CommunityBlockView,
-  CommunityFollowerView,
-  CommunityModeratorView,
-  CommunityView,
-  PersonBlockView,
-  PersonView,
+  CommunityBlockView, CommunityFollowerView, CommunityModeratorView, CommunityView,
+  PersonBlockView, PersonView,
 };
 use lemmy_db_views_moderator::structs::{
 };
 use lemmy_db_views_moderator::structs::{
-  AdminPurgeCommentView,
-  AdminPurgeCommunityView,
-  AdminPurgePersonView,
-  AdminPurgePostView,
-  ModAddCommunityView,
-  ModAddView,
-  ModBanFromCommunityView,
-  ModBanView,
-  ModFeaturePostView,
-  ModHideCommunityView,
-  ModLockPostView,
-  ModRemoveCommentView,
-  ModRemoveCommunityView,
-  ModRemovePostView,
-  ModTransferCommunityView,
+  AdminPurgeCommentView, AdminPurgeCommunityView, AdminPurgePersonView, AdminPurgePostView,
+  ModAddCommunityView, ModAddView, ModBanFromCommunityView, ModBanView, ModFeaturePostView,
+  ModHideCommunityView, ModLockPostView, ModRemoveCommentView, ModRemoveCommunityView,
+  ModRemovePostView, ModTransferCommunityView,
 };
 use serde::{Deserialize, Serialize};
 use serde_with::skip_serializing_none;
 };
 use serde::{Deserialize, Serialize};
 use serde_with::skip_serializing_none;
@@ -150,6 +126,7 @@ pub struct CreateSite {
   pub icon: Option<String>,
   pub banner: Option<String>,
   pub enable_downvotes: Option<bool>,
   pub icon: Option<String>,
   pub banner: Option<String>,
   pub enable_downvotes: Option<bool>,
+  pub enable_federated_downvotes: Option<bool>,
   pub enable_nsfw: Option<bool>,
   pub community_creation_admin_only: Option<bool>,
   pub require_email_verification: Option<bool>,
   pub enable_nsfw: Option<bool>,
   pub community_creation_admin_only: Option<bool>,
   pub require_email_verification: Option<bool>,
@@ -202,6 +179,8 @@ pub struct EditSite {
   pub banner: Option<String>,
   /// Whether to enable downvotes.
   pub enable_downvotes: Option<bool>,
   pub banner: Option<String>,
   /// Whether to enable downvotes.
   pub enable_downvotes: Option<bool>,
+  /// Whether to allow downvotes from federated sites.
+  pub enable_federated_downvotes: Option<bool>,
   /// Whether to enable NSFW.
   pub enable_nsfw: Option<bool>,
   /// Limits community creation to admins only.
   /// Whether to enable NSFW.
   pub enable_nsfw: Option<bool>,
   /// Limits community creation to admins only.
index 38d6111ce6f630d284484362ceca3dfeef95ca3f..34e153c59a0642a4687eaf043351a934571e4567 100644 (file)
@@ -5,12 +5,8 @@ use lemmy_api_common::{
   context::LemmyContext,
   site::{CreateSite, SiteResponse},
   utils::{
   context::LemmyContext,
   site::{CreateSite, SiteResponse},
   utils::{
-    generate_site_inbox_url,
-    is_admin,
-    local_site_rate_limit_to_rate_limit_config,
-    local_user_view_from_jwt,
-    sanitize_html,
-    sanitize_html_opt,
+    generate_site_inbox_url, is_admin, local_site_rate_limit_to_rate_limit_config,
+    local_user_view_from_jwt, sanitize_html, sanitize_html_opt,
   },
 };
 use lemmy_db_schema::{
   },
 };
 use lemmy_db_schema::{
@@ -30,11 +26,8 @@ use lemmy_utils::{
   utils::{
     slurs::{check_slurs, check_slurs_opt},
     validation::{
   utils::{
     slurs::{check_slurs, check_slurs_opt},
     validation::{
-      build_and_check_regex,
-      check_site_visibility_valid,
-      is_valid_body_field,
-      site_description_length_check,
-      site_name_length_check,
+      build_and_check_regex, check_site_visibility_valid, is_valid_body_field,
+      site_description_length_check, site_name_length_check,
     },
   },
 };
     },
   },
 };
@@ -77,7 +70,6 @@ pub async fn create_site(
   let site_id = local_site.site_id;
 
   Site::update(&mut context.pool(), site_id, &site_form).await?;
   let site_id = local_site.site_id;
 
   Site::update(&mut context.pool(), site_id, &site_form).await?;
-
   let application_question = sanitize_html_opt(&data.application_question);
   let default_theme = sanitize_html_opt(&data.default_theme);
   let legal_information = sanitize_html_opt(&data.legal_information);
   let application_question = sanitize_html_opt(&data.application_question);
   let default_theme = sanitize_html_opt(&data.default_theme);
   let legal_information = sanitize_html_opt(&data.legal_information);
@@ -86,6 +78,7 @@ pub async fn create_site(
     // Set the site setup to true
     site_setup: Some(true),
     enable_downvotes: data.enable_downvotes,
     // Set the site setup to true
     site_setup: Some(true),
     enable_downvotes: data.enable_downvotes,
+    enable_federated_downvotes: data.enable_federated_downvotes,
     registration_mode: data.registration_mode,
     enable_nsfw: data.enable_nsfw,
     community_creation_admin_only: data.community_creation_admin_only,
     registration_mode: data.registration_mode,
     enable_nsfw: data.enable_nsfw,
     community_creation_admin_only: data.community_creation_admin_only,
@@ -513,6 +506,7 @@ mod tests {
       site_id: Default::default(),
       site_setup,
       enable_downvotes: false,
       site_id: Default::default(),
       site_setup,
       enable_downvotes: false,
+      enable_federated_downvotes: false,
       enable_nsfw: false,
       community_creation_admin_only: false,
       require_email_verification: false,
       enable_nsfw: false,
       community_creation_admin_only: false,
       require_email_verification: false,
@@ -556,6 +550,7 @@ mod tests {
       icon: None,
       banner: None,
       enable_downvotes: None,
       icon: None,
       banner: None,
       enable_downvotes: None,
+      enable_federated_downvotes: None,
       enable_nsfw: None,
       community_creation_admin_only: None,
       require_email_verification: None,
       enable_nsfw: None,
       community_creation_admin_only: None,
       require_email_verification: None,
index 6148d546eb22c6d15563197f81c44430aa5b14ef..83f746429fa02892b79abb806684ff1338efcd11 100644 (file)
@@ -4,9 +4,7 @@ use lemmy_api_common::{
   context::LemmyContext,
   site::{EditSite, SiteResponse},
   utils::{
   context::LemmyContext,
   site::{EditSite, SiteResponse},
   utils::{
-    is_admin,
-    local_site_rate_limit_to_rate_limit_config,
-    local_user_view_from_jwt,
+    is_admin, local_site_rate_limit_to_rate_limit_config, local_user_view_from_jwt,
     sanitize_html_opt,
   },
 };
     sanitize_html_opt,
   },
 };
@@ -31,11 +29,8 @@ use lemmy_utils::{
   utils::{
     slurs::check_slurs_opt,
     validation::{
   utils::{
     slurs::check_slurs_opt,
     validation::{
-      build_and_check_regex,
-      check_site_visibility_valid,
-      is_valid_body_field,
-      site_description_length_check,
-      site_name_length_check,
+      build_and_check_regex, check_site_visibility_valid, is_valid_body_field,
+      site_description_length_check, site_name_length_check,
     },
   },
 };
     },
   },
 };
@@ -85,6 +80,7 @@ pub async fn update_site(
 
   let local_site_form = LocalSiteUpdateForm {
     enable_downvotes: data.enable_downvotes,
 
   let local_site_form = LocalSiteUpdateForm {
     enable_downvotes: data.enable_downvotes,
+    enable_federated_downvotes: data.enable_federated_downvotes,
     registration_mode: data.registration_mode,
     enable_nsfw: data.enable_nsfw,
     community_creation_admin_only: data.community_creation_admin_only,
     registration_mode: data.registration_mode,
     enable_nsfw: data.enable_nsfw,
     community_creation_admin_only: data.community_creation_admin_only,
@@ -511,6 +507,7 @@ mod tests {
       site_id: Default::default(),
       site_setup: true,
       enable_downvotes: false,
       site_id: Default::default(),
       site_setup: true,
       enable_downvotes: false,
+      enable_federated_downvotes: false,
       enable_nsfw: false,
       community_creation_admin_only: false,
       require_email_verification: false,
       enable_nsfw: false,
       community_creation_admin_only: false,
       require_email_verification: false,
@@ -554,6 +551,7 @@ mod tests {
       icon: None,
       banner: None,
       enable_downvotes: None,
       icon: None,
       banner: None,
       enable_downvotes: None,
+      enable_federated_downvotes: None,
       enable_nsfw: None,
       community_creation_admin_only: None,
       require_email_verification: None,
       enable_nsfw: None,
       community_creation_admin_only: None,
       require_email_verification: None,
index ef4572986f0c3d52d15424d7f7b5356bbe72aac5..81bed456f80166f082ef9d1ecc01330c7e705a46 100644 (file)
@@ -1,7 +1,6 @@
 use crate::{
   activities::{
 use crate::{
   activities::{
-    generate_activity_id,
-    verify_person_in_community,
+    generate_activity_id, verify_person_in_community,
     voting::{vote_comment, vote_post},
   },
   insert_received_activity,
     voting::{vote_comment, vote_post},
   },
   insert_received_activity,
@@ -63,7 +62,11 @@ impl ActivityHandler for Vote {
       .await
       .map(|l| l.enable_downvotes)
       .unwrap_or(true);
       .await
       .map(|l| l.enable_downvotes)
       .unwrap_or(true);
-    if self.kind == VoteType::Dislike && !enable_downvotes {
+    let enable_federated_downvotes = LocalSite::read(&mut context.pool())
+      .await
+      .map(|l| l.enable_federated_downvotes)
+      .unwrap_or(true);
+    if self.kind == VoteType::Dislike && (!enable_downvotes || !enable_federated_downvotes) {
       return Err(anyhow!("Downvotes disabled").into());
     }
     Ok(())
       return Err(anyhow!("Downvotes disabled").into());
     }
     Ok(())
index 7106b1c90bed432ef0fc1ab3deea4c4414aae1d5..5aa54c9db4090a0d3fe56f0938832e080eb8c1bd 100644 (file)
@@ -1,17 +1,17 @@
 // @generated automatically by Diesel CLI.
 
 pub mod sql_types {
 // @generated automatically by Diesel CLI.
 
 pub mod sql_types {
-    #[derive(diesel::sql_types::SqlType)]
-    #[diesel(postgres_type(name = "listing_type_enum"))]
-    pub struct ListingTypeEnum;
+  #[derive(diesel::sql_types::SqlType)]
+  #[diesel(postgres_type(name = "listing_type_enum"))]
+  pub struct ListingTypeEnum;
 
 
-    #[derive(diesel::sql_types::SqlType)]
-    #[diesel(postgres_type(name = "registration_mode_enum"))]
-    pub struct RegistrationModeEnum;
+  #[derive(diesel::sql_types::SqlType)]
+  #[diesel(postgres_type(name = "registration_mode_enum"))]
+  pub struct RegistrationModeEnum;
 
 
-    #[derive(diesel::sql_types::SqlType)]
-    #[diesel(postgres_type(name = "sort_type_enum"))]
-    pub struct SortTypeEnum;
+  #[derive(diesel::sql_types::SqlType)]
+  #[diesel(postgres_type(name = "sort_type_enum"))]
+  pub struct SortTypeEnum;
 }
 
 diesel::table! {
 }
 
 diesel::table! {
@@ -324,6 +324,7 @@ diesel::table! {
         site_id -> Int4,
         site_setup -> Bool,
         enable_downvotes -> Bool,
         site_id -> Int4,
         site_setup -> Bool,
         enable_downvotes -> Bool,
+        enable_federated_downvotes -> Bool,
         enable_nsfw -> Bool,
         community_creation_admin_only -> Bool,
         require_email_verification -> Bool,
         enable_nsfw -> Bool,
         community_creation_admin_only -> Bool,
         require_email_verification -> Bool,
@@ -934,68 +935,68 @@ diesel::joinable!(site_language -> site (site_id));
 diesel::joinable!(tagline -> local_site (local_site_id));
 
 diesel::allow_tables_to_appear_in_same_query!(
 diesel::joinable!(tagline -> local_site (local_site_id));
 
 diesel::allow_tables_to_appear_in_same_query!(
-    admin_purge_comment,
-    admin_purge_community,
-    admin_purge_person,
-    admin_purge_post,
-    captcha_answer,
-    comment,
-    comment_aggregates,
-    comment_like,
-    comment_reply,
-    comment_report,
-    comment_saved,
-    community,
-    community_aggregates,
-    community_block,
-    community_follower,
-    community_language,
-    community_moderator,
-    community_person_ban,
-    custom_emoji,
-    custom_emoji_keyword,
-    email_verification,
-    federation_allowlist,
-    federation_blocklist,
-    instance,
-    language,
-    local_site,
-    local_site_rate_limit,
-    local_user,
-    local_user_language,
-    mod_add,
-    mod_add_community,
-    mod_ban,
-    mod_ban_from_community,
-    mod_feature_post,
-    mod_hide_community,
-    mod_lock_post,
-    mod_remove_comment,
-    mod_remove_community,
-    mod_remove_post,
-    mod_transfer_community,
-    password_reset_request,
-    person,
-    person_aggregates,
-    person_ban,
-    person_block,
-    person_follower,
-    person_mention,
-    person_post_aggregates,
-    post,
-    post_aggregates,
-    post_like,
-    post_read,
-    post_report,
-    post_saved,
-    private_message,
-    private_message_report,
-    received_activity,
-    registration_application,
-    secret,
-    sent_activity,
-    site,
-    site_aggregates,
-    site_language,
-    tagline,
+  admin_purge_comment,
+  admin_purge_community,
+  admin_purge_person,
+  admin_purge_post,
+  captcha_answer,
+  comment,
+  comment_aggregates,
+  comment_like,
+  comment_reply,
+  comment_report,
+  comment_saved,
+  community,
+  community_aggregates,
+  community_block,
+  community_follower,
+  community_language,
+  community_moderator,
+  community_person_ban,
+  custom_emoji,
+  custom_emoji_keyword,
+  email_verification,
+  federation_allowlist,
+  federation_blocklist,
+  instance,
+  language,
+  local_site,
+  local_site_rate_limit,
+  local_user,
+  local_user_language,
+  mod_add,
+  mod_add_community,
+  mod_ban,
+  mod_ban_from_community,
+  mod_feature_post,
+  mod_hide_community,
+  mod_lock_post,
+  mod_remove_comment,
+  mod_remove_community,
+  mod_remove_post,
+  mod_transfer_community,
+  password_reset_request,
+  person,
+  person_aggregates,
+  person_ban,
+  person_block,
+  person_follower,
+  person_mention,
+  person_post_aggregates,
+  post,
+  post_aggregates,
+  post_like,
+  post_read,
+  post_report,
+  post_saved,
+  private_message,
+  private_message_report,
+  received_activity,
+  registration_application,
+  secret,
+  sent_activity,
+  site,
+  site_aggregates,
+  site_language,
+  tagline,
 );
 );
index a57bf503c350dd88db6cdccc3b755c595acbd2a2..dfd7b606e155c3868dd7be0fd8608d09ed438672 100644 (file)
@@ -2,8 +2,7 @@
 use crate::schema::local_site;
 use crate::{
   newtypes::{LocalSiteId, SiteId},
 use crate::schema::local_site;
 use crate::{
   newtypes::{LocalSiteId, SiteId},
-  ListingType,
-  RegistrationMode,
+  ListingType, RegistrationMode,
 };
 use serde::{Deserialize, Serialize};
 use serde_with::skip_serializing_none;
 };
 use serde::{Deserialize, Serialize};
 use serde_with::skip_serializing_none;
@@ -25,6 +24,8 @@ pub struct LocalSite {
   pub site_setup: bool,
   /// Whether downvotes are enabled.
   pub enable_downvotes: bool,
   pub site_setup: bool,
   /// Whether downvotes are enabled.
   pub enable_downvotes: bool,
+  /// Whether downvotes are allowed from federated sites.
+  pub enable_federated_downvotes: bool,
   /// Whether NSFW is enabled.
   pub enable_nsfw: bool,
   /// Whether only admins can create communities.
   /// Whether NSFW is enabled.
   pub enable_nsfw: bool,
   /// Whether only admins can create communities.
@@ -70,6 +71,7 @@ pub struct LocalSiteInsertForm {
   pub site_id: SiteId,
   pub site_setup: Option<bool>,
   pub enable_downvotes: Option<bool>,
   pub site_id: SiteId,
   pub site_setup: Option<bool>,
   pub enable_downvotes: Option<bool>,
+  pub enable_federated_downvotes: Option<bool>,
   pub enable_nsfw: Option<bool>,
   pub community_creation_admin_only: Option<bool>,
   pub require_email_verification: Option<bool>,
   pub enable_nsfw: Option<bool>,
   pub community_creation_admin_only: Option<bool>,
   pub require_email_verification: Option<bool>,
@@ -95,6 +97,7 @@ pub struct LocalSiteInsertForm {
 pub struct LocalSiteUpdateForm {
   pub site_setup: Option<bool>,
   pub enable_downvotes: Option<bool>,
 pub struct LocalSiteUpdateForm {
   pub site_setup: Option<bool>,
   pub enable_downvotes: Option<bool>,
+  pub enable_federated_downvotes: Option<bool>,
   pub enable_nsfw: Option<bool>,
   pub community_creation_admin_only: Option<bool>,
   pub require_email_verification: Option<bool>,
   pub enable_nsfw: Option<bool>,
   pub community_creation_admin_only: Option<bool>,
   pub require_email_verification: Option<bool>,
diff --git a/migrations/2023-07-25-113818_add_enable_federated_downvotes/down.sql b/migrations/2023-07-25-113818_add_enable_federated_downvotes/down.sql
new file mode 100644 (file)
index 0000000..8a66868
--- /dev/null
@@ -0,0 +1 @@
+alter table local_site drop column enable_federated_downvotes;
diff --git a/migrations/2023-07-25-113818_add_enable_federated_downvotes/up.sql b/migrations/2023-07-25-113818_add_enable_federated_downvotes/up.sql
new file mode 100644 (file)
index 0000000..8a9d2d7
--- /dev/null
@@ -0,0 +1,2 @@
+alter table local_site
+      add column enable_federated_downvotes boolean default true not null;