From d18ac067c58fb9514152adad5cac1eb41bca3b45 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 23 Jan 2024 12:20:15 +0100 Subject: [PATCH] add auto_expand_images site setting --- crates/api_common/src/site.rs | 7 +++++++ crates/api_crud/src/site/create.rs | 4 ++++ crates/api_crud/src/site/update.rs | 4 ++++ crates/db_schema/src/schema.rs | 1 + crates/db_schema/src/source/local_site.rs | 6 +++++- migrations/2024-01-22-105746_lemmynsfw-changes/down.sql | 3 +++ migrations/2024-01-22-105746_lemmynsfw-changes/up.sql | 3 +++ 7 files changed, 27 insertions(+), 1 deletion(-) diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index 2d83a12a4..c1c6fbf32 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -187,6 +187,8 @@ pub struct CreateSite { pub blocked_instances: Option>, pub taglines: Option>, pub registration_mode: Option, + pub content_warning: Option, + pub auto_expand_images: Option, } #[skip_serializing_none] @@ -265,6 +267,11 @@ pub struct EditSite { pub registration_mode: Option, /// Whether to email admins for new reports. pub reports_email_admins: Option, + /// If present, nsfw content is visible by default. Should be displayed by frontends/clients + /// when the site is first opened by a user. + pub content_warning: Option, + /// Automatically expand images to full size in the website without manual user action + pub auto_expand_images: Option, } #[derive(Debug, Serialize, Deserialize, Clone)] diff --git a/crates/api_crud/src/site/create.rs b/crates/api_crud/src/site/create.rs index 06ddfd534..3807f3397 100644 --- a/crates/api_crud/src/site/create.rs +++ b/crates/api_crud/src/site/create.rs @@ -89,6 +89,8 @@ pub async fn create_site( federation_enabled: data.federation_enabled, captcha_enabled: data.captcha_enabled, captcha_difficulty: data.captcha_difficulty.clone(), + content_warning: diesel_option_overwrite(data.content_warning.clone()), + auto_expand_images: data.auto_expand_images, ..Default::default() }; @@ -556,6 +558,8 @@ mod tests { blocked_instances: None, taglines: None, registration_mode: site_registration_mode, + content_warning: None, + auto_expand_images: None, } } } diff --git a/crates/api_crud/src/site/update.rs b/crates/api_crud/src/site/update.rs index 62db5bb83..0685ad82f 100644 --- a/crates/api_crud/src/site/update.rs +++ b/crates/api_crud/src/site/update.rs @@ -90,6 +90,8 @@ pub async fn update_site( captcha_enabled: data.captcha_enabled, captcha_difficulty: data.captcha_difficulty.clone(), reports_email_admins: data.reports_email_admins, + content_warning: diesel_option_overwrite(data.content_warning.clone()), + auto_expand_images: data.auto_expand_images, ..Default::default() }; @@ -555,6 +557,8 @@ mod tests { taglines: None, registration_mode: site_registration_mode, reports_email_admins: None, + content_warning: None, + auto_expand_images: None, } } } diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index fbd6b8507..3b8ff85c8 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -373,6 +373,7 @@ diesel::table! { reports_email_admins -> Bool, federation_signed_fetch -> Bool, content_warning -> Nullable, + auto_expand_images -> Bool, } } diff --git a/crates/db_schema/src/source/local_site.rs b/crates/db_schema/src/source/local_site.rs index 4dc86345c..980761339 100644 --- a/crates/db_schema/src/source/local_site.rs +++ b/crates/db_schema/src/source/local_site.rs @@ -67,6 +67,8 @@ pub struct LocalSite { /// If present, nsfw content is visible by default. Should be displayed by frontends/clients /// when the site is first opened by a user. pub content_warning: Option, + /// Automatically expand images to full size in the website without manual user action + pub auto_expand_images: bool, } #[derive(Clone, TypedBuilder)] @@ -97,6 +99,7 @@ pub struct LocalSiteInsertForm { pub reports_email_admins: Option, pub federation_signed_fetch: Option, pub content_warning: Option, + pub auto_expand_images: Option, } #[derive(Clone, Default)] @@ -124,5 +127,6 @@ pub struct LocalSiteUpdateForm { pub reports_email_admins: Option, pub updated: Option>>, pub federation_signed_fetch: Option, - pub content_warning: Option, + pub content_warning: Option>, + pub auto_expand_images: Option, } diff --git a/migrations/2024-01-22-105746_lemmynsfw-changes/down.sql b/migrations/2024-01-22-105746_lemmynsfw-changes/down.sql index df1342a03..7ae867084 100644 --- a/migrations/2024-01-22-105746_lemmynsfw-changes/down.sql +++ b/migrations/2024-01-22-105746_lemmynsfw-changes/down.sql @@ -1,6 +1,9 @@ ALTER TABLE local_site DROP COLUMN content_warning; +ALTER TABLE local_site + DROP COLUMN auto_expand_images; + ALTER TABLE community DROP COLUMN only_followers_can_vote; diff --git a/migrations/2024-01-22-105746_lemmynsfw-changes/up.sql b/migrations/2024-01-22-105746_lemmynsfw-changes/up.sql index f77e7e802..4f7dae210 100644 --- a/migrations/2024-01-22-105746_lemmynsfw-changes/up.sql +++ b/migrations/2024-01-22-105746_lemmynsfw-changes/up.sql @@ -1,6 +1,9 @@ ALTER TABLE local_site ADD COLUMN content_warning text; +ALTER TABLE local_site + ADD COLUMN auto_expand_images boolean NOT NULL DEFAULT FALSE; + ALTER TABLE community ADD COLUMN only_followers_can_vote boolean NOT NULL DEFAULT FALSE;