Skip to content

Commit

Permalink
fix: pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed May 7, 2024
1 parent d068388 commit 52e2db2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
}
}

0 comments on commit 52e2db2

Please sign in to comment.