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::{
- CommentView,
- CustomEmojiView,
- LocalUserView,
- PostView,
- RegistrationApplicationView,
- SiteView,
+ CommentView, CustomEmojiView, LocalUserView, PostView, RegistrationApplicationView, SiteView,
};
use lemmy_db_views_actor::structs::{
- CommunityBlockView,
- CommunityFollowerView,
- CommunityModeratorView,
- CommunityView,
- PersonBlockView,
- PersonView,
+ CommunityBlockView, CommunityFollowerView, CommunityModeratorView, CommunityView,
+ PersonBlockView, PersonView,
};
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;
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 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.
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::{
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,
},
},
};
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);
// 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,
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,
icon: None,
banner: None,
enable_downvotes: None,
+ enable_federated_downvotes: None,
enable_nsfw: None,
community_creation_admin_only: None,
require_email_verification: None,
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,
},
};
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,
},
},
};
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,
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,
icon: None,
banner: None,
enable_downvotes: None,
+ enable_federated_downvotes: None,
enable_nsfw: None,
community_creation_admin_only: None,
require_email_verification: None,
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,
.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(())
// @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! {
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,
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,
);
use crate::schema::local_site;
use crate::{
newtypes::{LocalSiteId, SiteId},
- ListingType,
- RegistrationMode,
+ ListingType, RegistrationMode,
};
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
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.
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 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>,
--- /dev/null
+alter table local_site drop column enable_federated_downvotes;
--- /dev/null
+alter table local_site
+ add column enable_federated_downvotes boolean default true not null;