From 9f5183fe983014d0cf9f0959ff1e17230d35af0e Mon Sep 17 00:00:00 2001 From: Nutomic Date: Wed, 23 Feb 2022 16:40:36 +0000 Subject: [PATCH] Add site option for default theme (#2104) --- config/defaults.hjson | 1 + crates/api_common/src/site.rs | 2 ++ crates/api_crud/src/site/create.rs | 1 + crates/api_crud/src/site/read.rs | 1 + crates/api_crud/src/site/update.rs | 1 + crates/db_schema/src/schema.rs | 1 + crates/db_schema/src/source/site.rs | 2 ++ crates/utils/src/settings/structs.rs | 2 ++ migrations/2022-02-18-210946_default_theme/down.sql | 1 + migrations/2022-02-18-210946_default_theme/up.sql | 1 + 10 files changed, 13 insertions(+) create mode 100644 migrations/2022-02-18-210946_default_theme/down.sql create mode 100644 migrations/2022-02-18-210946_default_theme/up.sql diff --git a/config/defaults.hjson b/config/defaults.hjson index cf8b55731..c30c33ac8 100644 --- a/config/defaults.hjson +++ b/config/defaults.hjson @@ -101,6 +101,7 @@ require_application: true application_question: "string" private_instance: true + default_theme: "string" } # the domain name of your instance (mandatory) hostname: "unset" diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index a707dd656..df752c00c 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -106,6 +106,7 @@ pub struct CreateSite { pub require_application: Option, pub application_question: Option, pub private_instance: Option, + pub default_theme: Option, pub auth: Sensitive, } @@ -124,6 +125,7 @@ pub struct EditSite { pub require_application: Option, pub application_question: Option, pub private_instance: Option, + pub default_theme: Option, pub auth: Sensitive, } diff --git a/crates/api_crud/src/site/create.rs b/crates/api_crud/src/site/create.rs index d714afea7..4d51504f7 100644 --- a/crates/api_crud/src/site/create.rs +++ b/crates/api_crud/src/site/create.rs @@ -80,6 +80,7 @@ impl PerformCrud for CreateSite { inbox_url, private_key: Some(Some(keypair.private_key)), public_key: Some(keypair.public_key), + default_theme: data.default_theme.clone(), ..SiteForm::default() }; diff --git a/crates/api_crud/src/site/read.rs b/crates/api_crud/src/site/read.rs index ee777d2d7..d214f7b6e 100644 --- a/crates/api_crud/src/site/read.rs +++ b/crates/api_crud/src/site/read.rs @@ -68,6 +68,7 @@ impl PerformCrud for GetSite { require_application: setup.require_application, application_question: setup.application_question.to_owned(), private_instance: setup.private_instance, + default_theme: setup.default_theme.to_owned(), auth: admin_jwt, }; create_site.perform(context, websocket_id).await?; diff --git a/crates/api_crud/src/site/update.rs b/crates/api_crud/src/site/update.rs index c6f595230..7696711c6 100644 --- a/crates/api_crud/src/site/update.rs +++ b/crates/api_crud/src/site/update.rs @@ -69,6 +69,7 @@ impl PerformCrud for EditSite { require_application: data.require_application, application_question, private_instance: data.private_instance, + default_theme: data.default_theme.clone(), ..SiteForm::default() }; diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 811e8b09a..390a8e723 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -460,6 +460,7 @@ table! { inbox_url -> Text, private_key -> Nullable, public_key -> Text, + default_theme -> Text, } } diff --git a/crates/db_schema/src/source/site.rs b/crates/db_schema/src/source/site.rs index 25bed1c24..6a0558420 100644 --- a/crates/db_schema/src/source/site.rs +++ b/crates/db_schema/src/source/site.rs @@ -25,6 +25,7 @@ pub struct Site { pub inbox_url: DbUrl, pub private_key: Option, pub public_key: String, + pub default_theme: String, } #[derive(Insertable, AsChangeset, Default)] @@ -50,4 +51,5 @@ pub struct SiteForm { pub inbox_url: Option, pub private_key: Option>, pub public_key: Option, + pub default_theme: Option, } diff --git a/crates/utils/src/settings/structs.rs b/crates/utils/src/settings/structs.rs index 0aaae87ce..16ead8637 100644 --- a/crates/utils/src/settings/structs.rs +++ b/crates/utils/src/settings/structs.rs @@ -205,4 +205,6 @@ pub struct SetupConfig { pub application_question: Option, #[default(None)] pub private_instance: Option, + #[default(None)] + pub default_theme: Option, } diff --git a/migrations/2022-02-18-210946_default_theme/down.sql b/migrations/2022-02-18-210946_default_theme/down.sql new file mode 100644 index 000000000..fc57669a8 --- /dev/null +++ b/migrations/2022-02-18-210946_default_theme/down.sql @@ -0,0 +1 @@ +alter table site drop column default_theme; \ No newline at end of file diff --git a/migrations/2022-02-18-210946_default_theme/up.sql b/migrations/2022-02-18-210946_default_theme/up.sql new file mode 100644 index 000000000..dd6faad48 --- /dev/null +++ b/migrations/2022-02-18-210946_default_theme/up.sql @@ -0,0 +1 @@ +alter table site add column default_theme text not null default 'browser'; \ No newline at end of file