From 33cbd95b7ef4febc2be077f0cc0c4c2aaa781512 Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com> Date: Thu, 26 Sep 2024 08:24:51 +0000 Subject: [PATCH] Add skip_serialize_none to OAuth structs with option fields (#5046) * Add skip_serialize_none to OAuth structs with option fields * PR feedback * Remove serde and ts export from SSO db-only structs --- crates/api_common/src/oauth_provider.rs | 7 ++++--- crates/db_schema/src/source/oauth_provider.rs | 19 +++++-------------- .../up.sql | 2 +- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/crates/api_common/src/oauth_provider.rs b/crates/api_common/src/oauth_provider.rs index c51edc7a4..4719480cc 100644 --- a/crates/api_common/src/oauth_provider.rs +++ b/crates/api_common/src/oauth_provider.rs @@ -19,11 +19,12 @@ pub struct CreateOAuthProvider { pub client_id: String, pub client_secret: String, pub scopes: String, - pub auto_verify_email: bool, - pub account_linking_enabled: bool, - pub enabled: bool, + pub auto_verify_email: Option, + pub account_linking_enabled: Option, + pub enabled: Option, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] diff --git a/crates/db_schema/src/source/oauth_provider.rs b/crates/db_schema/src/source/oauth_provider.rs index 40046c83c..75b989805 100644 --- a/crates/db_schema/src/source/oauth_provider.rs +++ b/crates/db_schema/src/source/oauth_provider.rs @@ -87,39 +87,30 @@ impl Serialize for PublicOAuthProvider { } #[derive(Debug, Clone)] -#[cfg_attr(feature = "full", derive(Insertable, AsChangeset, TS))] +#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = oauth_provider))] -#[cfg_attr(feature = "full", ts(export))] pub struct OAuthProviderInsertForm { pub display_name: String, - #[cfg_attr(feature = "full", ts(type = "string"))] pub issuer: DbUrl, - #[cfg_attr(feature = "full", ts(type = "string"))] pub authorization_endpoint: DbUrl, - #[cfg_attr(feature = "full", ts(type = "string"))] pub token_endpoint: DbUrl, - #[cfg_attr(feature = "full", ts(type = "string"))] pub userinfo_endpoint: DbUrl, pub id_claim: String, pub client_id: String, pub client_secret: String, pub scopes: String, - pub auto_verify_email: bool, - pub account_linking_enabled: bool, - pub enabled: bool, + pub auto_verify_email: Option, + pub account_linking_enabled: Option, + pub enabled: Option, } #[derive(Debug, Clone)] -#[cfg_attr(feature = "full", derive(Insertable, AsChangeset, TS))] +#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = oauth_provider))] -#[cfg_attr(feature = "full", ts(export))] pub struct OAuthProviderUpdateForm { pub display_name: Option, - #[cfg_attr(feature = "full", ts(type = "string"))] pub authorization_endpoint: Option, - #[cfg_attr(feature = "full", ts(type = "string"))] pub token_endpoint: Option, - #[cfg_attr(feature = "full", ts(type = "string"))] pub userinfo_endpoint: Option, pub id_claim: Option, pub client_secret: Option, diff --git a/migrations/2024-09-16-174833_create_oauth_provider/up.sql b/migrations/2024-09-16-174833_create_oauth_provider/up.sql index a75f01228..308d86cce 100644 --- a/migrations/2024-09-16-174833_create_oauth_provider/up.sql +++ b/migrations/2024-09-16-174833_create_oauth_provider/up.sql @@ -14,7 +14,7 @@ CREATE TABLE oauth_provider ( scopes text NOT NULL, auto_verify_email boolean DEFAULT TRUE NOT NULL, account_linking_enabled boolean DEFAULT FALSE NOT NULL, - enabled boolean DEFAULT FALSE NOT NULL, + enabled boolean DEFAULT TRUE NOT NULL, published timestamp with time zone DEFAULT now() NOT NULL, updated timestamp with time zone );