From 52e2db25a8ef8f052e46cf65ebba1c999450d109 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Tue, 7 May 2024 13:23:08 +0530 Subject: [PATCH] fix: pr comments --- .../annotations/ConfigDescription.java | 11 ++- .../multitenancy/TenantConfig.java | 82 +++++++++++-------- 2 files changed, 55 insertions(+), 38 deletions(-) diff --git a/src/main/java/io/supertokens/pluginInterface/annotations/ConfigDescription.java b/src/main/java/io/supertokens/pluginInterface/annotations/ConfigDescription.java index 0b5d3a42..160b583c 100644 --- a/src/main/java/io/supertokens/pluginInterface/annotations/ConfigDescription.java +++ b/src/main/java/io/supertokens/pluginInterface/annotations/ConfigDescription.java @@ -21,9 +21,12 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) +/** + * Annotation to provide a description for a configuration fields. To be used on the fields of `CoreConfig` and config + * class in the plugin like `PostgreSQLConfig`, `MysqlConfig`, etc. + */ +@Retention(RetentionPolicy.RUNTIME) // Make annotation accessible at runtime so that config descriptions can be read from API +@Target(ElementType.FIELD) // Annotation can only be applied to fields public @interface ConfigDescription { - String value() default ""; + String value(); // String value that provides a description for the configuration field } - \ No newline at end of file diff --git a/src/main/java/io/supertokens/pluginInterface/multitenancy/TenantConfig.java b/src/main/java/io/supertokens/pluginInterface/multitenancy/TenantConfig.java index 915db255..b5f8bbbe 100644 --- a/src/main/java/io/supertokens/pluginInterface/multitenancy/TenantConfig.java +++ b/src/main/java/io/supertokens/pluginInterface/multitenancy/TenantConfig.java @@ -119,8 +119,54 @@ public int hashCode() { return tenantIdentifier.hashCode(); } - public JsonObject toJson(boolean shouldProtectDbConfig, Storage storage, String[] protectedCoreConfigs, - boolean computeRecipeEnabledUsingFirstFactors) { + public JsonObject toJson3_0(boolean shouldProtectDbConfig, Storage storage, String[] protectedCoreConfigs) { + JsonObject tenantConfigObject = toJson5_0(shouldProtectDbConfig, storage, protectedCoreConfigs); + + tenantConfigObject.remove("firstFactors"); + tenantConfigObject.remove("requiredSecondaryFactors"); + + return tenantConfigObject; + } + + public JsonObject toJson5_0(boolean shouldProtectDbConfig, Storage storage, String[] protectedCoreConfigs) { + JsonObject tenantConfigObject = toJson5_1(shouldProtectDbConfig, storage, protectedCoreConfigs); + tenantConfigObject.remove("useFirstFactorsFromStaticConfigIfEmpty"); + tenantConfigObject.get("thirdParty").getAsJsonObject().remove("useThirdPartyProvidersFromStaticConfigIfEmpty"); + + // as per https://github.com/supertokens/supertokens-core/issues/979#issuecomment-2058528228 + tenantConfigObject.get("emailPassword").getAsJsonObject().addProperty( + "enabled", + this.emailPasswordConfig.enabled && ( + (this.firstFactors == null && + this.useFirstFactorsFromStaticConfigIfEmpty) || + (this.firstFactors != null && List.of(this.firstFactors).contains("emailpassword")) + ) + ); + tenantConfigObject.get("thirdParty").getAsJsonObject().addProperty( + "enabled", + this.thirdPartyConfig.enabled && ( + (this.firstFactors == null && + this.useFirstFactorsFromStaticConfigIfEmpty) || + (this.firstFactors != null && List.of(this.firstFactors).contains("thirdparty")) + ) + ); + tenantConfigObject.get("passwordless").getAsJsonObject().addProperty( + "enabled", + this.passwordlessConfig.enabled && ( + (this.firstFactors == null && + this.useFirstFactorsFromStaticConfigIfEmpty) || + (this.firstFactors != null && + (List.of(this.firstFactors).contains("otp-email") || + List.of(this.firstFactors).contains("otp-phone") || + List.of(this.firstFactors).contains("link-email") || + List.of(this.firstFactors).contains("link-phone"))) + ) + ); + + return tenantConfigObject; + } + + public JsonObject toJson5_1(boolean shouldProtectDbConfig, Storage storage, String[] protectedCoreConfigs) { Gson gson = new Gson(); JsonObject tenantConfigObject = gson.toJsonTree(this).getAsJsonObject(); @@ -152,38 +198,6 @@ public JsonObject toJson(boolean shouldProtectDbConfig, Storage storage, String[ } } - if (computeRecipeEnabledUsingFirstFactors) { - // as per https://github.com/supertokens/supertokens-core/issues/979#issuecomment-2058528228 - tenantConfigObject.get("emailPassword").getAsJsonObject().addProperty( - "enabled", - this.emailPasswordConfig.enabled && ( - (this.firstFactors == null && - this.useFirstFactorsFromStaticConfigIfEmpty) || - (this.firstFactors != null && List.of(this.firstFactors).contains("emailpassword")) - ) - ); - tenantConfigObject.get("thirdParty").getAsJsonObject().addProperty( - "enabled", - this.thirdPartyConfig.enabled && ( - (this.firstFactors == null && - this.useFirstFactorsFromStaticConfigIfEmpty) || - (this.firstFactors != null && List.of(this.firstFactors).contains("thirdparty")) - ) - ); - tenantConfigObject.get("passwordless").getAsJsonObject().addProperty( - "enabled", - this.passwordlessConfig.enabled && ( - (this.firstFactors == null && - this.useFirstFactorsFromStaticConfigIfEmpty) || - (this.firstFactors != null && - (List.of(this.firstFactors).contains("otp-email") || - List.of(this.firstFactors).contains("otp-phone") || - List.of(this.firstFactors).contains("link-email") || - List.of(this.firstFactors).contains("link-phone"))) - ) - ); - } - return tenantConfigObject; } }