diff options
author | ms <ms@taler.net> | 2022-05-05 13:44:47 +0200 |
---|---|---|
committer | ms <ms@taler.net> | 2022-05-05 13:44:47 +0200 |
commit | e4746ba6a85dc2b0f05b76ea7b2542ac4a87fe5a (patch) | |
tree | e2d472045eb08616f40596da0b708655d503a929 | |
parent | eb937c60e48893409012fbe0584a270e91452a79 (diff) | |
download | libeufin-e4746ba6a85dc2b0f05b76ea7b2542ac4a87fe5a.tar.gz libeufin-e4746ba6a85dc2b0f05b76ea7b2542ac4a87fe5a.tar.bz2 libeufin-e4746ba6a85dc2b0f05b76ea7b2542ac4a87fe5a.zip |
Make registrations optional.
That requires to override the --allow-registrations flag
(to be given along the --override flag) passed to the default
demobank, and the injection of a new LIBEUFIN_UI_ALLOW_REGISTRATIONS
value to the SPA.
-rw-r--r-- | sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 26 | ||||
-rw-r--r-- | sandbox/src/test/kotlin/StringsTest.kt | 6 |
2 files changed, 29 insertions, 3 deletions
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt index 4311ab9a..c205bb3d 100644 --- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt +++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt @@ -136,6 +136,9 @@ class Config : CliktCommand( private val nameArgument by argument( "NAME", help = "Name of this configuration" ) + private val overrideOption by option( + "--override", help = "Override an existing demobank." + ).flag("--no-override", default = false) private val currencyOption by option("--currency").default("EUR") private val bankDebtLimitOption by option("--bank-debt-limit").int().default(1000000) private val usersDebtLimitOption by option("--users-debt-limit").int().default(1000) @@ -153,10 +156,18 @@ class Config : CliktCommand( execThrowableOrTerminate { dbCreateTables(dbConnString) transaction { - val checkExist = DemobankConfigEntity.find { + val maybeDemobank = DemobankConfigEntity.find { DemobankConfigsTable.name eq nameArgument }.firstOrNull() - if (checkExist != null) { + if (maybeDemobank != null) { + if (overrideOption) { + maybeDemobank.currency = currencyOption + maybeDemobank.bankDebtLimit = bankDebtLimitOption + maybeDemobank.usersDebtLimit = usersDebtLimitOption + maybeDemobank.allowRegistrations = allowRegistrationsOption + maybeDemobank.withSignupBonus = withSignupBonusOption + return@transaction + } println("Error, demobank ${nameArgument} exists already, not overriding it.") exitProcess(1) } @@ -1006,7 +1017,10 @@ val sandboxApp: Application.() -> Unit = { val surveyUrl = System.getenv( "TALER_ENV_URL_MERCHANT_SURVEY") ?: "https://demo.taler.net/survey/" content = content.replace("%DEMO_SITE_SURVEY_URL%", surveyUrl) - logger.debug("after links replacement + $content") + content = content.replace( + "%LIBEUFIN_UI_ALLOW_REGISTRATIONS%", + demobank.allowRegistrations.toString() + ) call.respondText(content, ContentType.Text.Html) return@get } @@ -1415,6 +1429,12 @@ val sandboxApp: Application.() -> Unit = { post("/testing/register") { // Check demobank was created. val demobank = ensureDemobank(call) + if (!demobank.allowRegistrations) { + throw SandboxError( + HttpStatusCode.UnprocessableEntity, + "The bank doesn't allow new registrations at the moment." + ) + } val req = call.receiveJson<CustomerRegistration>() val checkExist = transaction { DemobankCustomerEntity.find { diff --git a/sandbox/src/test/kotlin/StringsTest.kt b/sandbox/src/test/kotlin/StringsTest.kt index eaec275b..36503f6c 100644 --- a/sandbox/src/test/kotlin/StringsTest.kt +++ b/sandbox/src/test/kotlin/StringsTest.kt @@ -19,4 +19,10 @@ class StringsTest { ) println(content) } + + @Test + fun booleanToString() { + assert(true.toString() == "true") + assert(false.toString() == "false") + } }
\ No newline at end of file |