diff options
author | MS <ms@taler.net> | 2023-04-07 17:14:50 +0200 |
---|---|---|
committer | MS <ms@taler.net> | 2023-04-07 17:14:50 +0200 |
commit | 101fa06fd5fa863a90eb4cbc0b4fcd2e28fda583 (patch) | |
tree | e175248e9a8b325be1b32fc5d699e6ba66bdb3ad /sandbox/src/main/kotlin/tech/libeufin | |
parent | f2710520b2a162b7c162e5f375cb08f952f2b739 (diff) | |
download | libeufin-101fa06fd5fa863a90eb4cbc0b4fcd2e28fda583.tar.gz libeufin-101fa06fd5fa863a90eb4cbc0b4fcd2e28fda583.tar.bz2 libeufin-101fa06fd5fa863a90eb4cbc0b4fcd2e28fda583.zip |
Addressing #7788
Diffstat (limited to 'sandbox/src/main/kotlin/tech/libeufin')
3 files changed, 40 insertions, 12 deletions
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt index d9008fb6..d63dac33 100644 --- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt +++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt @@ -6,6 +6,8 @@ import io.ktor.http.* import io.ktor.server.request.* import io.ktor.server.response.* import io.ktor.server.routing.* +import org.jetbrains.exposed.sql.* +import org.jetbrains.exposed.sql.SqlExpressionBuilder.like import org.jetbrains.exposed.sql.transactions.transaction import tech.libeufin.sandbox.CashoutOperationsTable.uuid import tech.libeufin.util.* @@ -79,7 +81,7 @@ data class CircuitContactData( data class CircuitAccountReconfiguration( val contact_data: CircuitContactData, - val cashout_address: String, + val cashout_address: String?, val name: String? = null ) @@ -96,7 +98,7 @@ data class CircuitAccountInfo( val iban: String, val contact_data: CircuitContactData, val name: String, - val cashout_address: String + val cashout_address: String? ) data class CashoutOperationInfo( @@ -631,11 +633,12 @@ fun circuitApi(circuitRoute: Route) { * that the customer was indeed added via the Circuit API, as opposed * to the Access API. */ - val maybeError = "$resourceName not managed by the Circuit API." call.respond(CircuitAccountInfo( username = customer.username, - name = customer.name ?: throw notFound(maybeError), - cashout_address = customer.cashout_address ?: throw notFound(maybeError), + name = customer.name ?: throw internalServerError( + "Account '$resourceName' was found without owner's name." + ), + cashout_address = customer.cashout_address, contact_data = CircuitContactData( email = customer.email, phone = customer.phone @@ -659,10 +662,22 @@ fun circuitApi(circuitRoute: Route) { val customers = mutableListOf<Any>() val demobank = ensureDemobank(call) transaction { - DemobankCustomerEntity.find{ - // like() is case insensitive. - DemobankCustomersTable.name.like(filter) - }.forEach { + /** + * This block builds the DB query so that IF the %-wildcard was + * given, then BOTH name and name-less accounts are returned. + */ + val query: Op<Boolean> = SqlExpressionBuilder.run { + val like = DemobankCustomersTable.name.like(filter) + /** + * This IF statement is needed because Postgres would NOT + * match a null column even with the %-wildcard. + */ + if (filter == "%") { + return@run like.or(DemobankCustomersTable.name.isNull()) + } + return@run like + } + DemobankCustomerEntity.find { query }.forEach { customers.add(object { val username = it.username val name = it.name @@ -676,6 +691,7 @@ fun circuitApi(circuitRoute: Route) { ) }) } + StdOutSqlLogger } if (customers.size == 0) { call.respond(HttpStatusCode.NoContent) @@ -727,7 +743,7 @@ fun circuitApi(circuitRoute: Route) { throw badRequest("Invalid e-mail address: ${req.contact_data.email}") if ((req.contact_data.phone != null) && (!checkPhoneNumber(req.contact_data.phone))) throw badRequest("Invalid phone number: ${req.contact_data.phone}") - try { parsePayto(req.cashout_address) } + try { if (req.cashout_address != null) parsePayto(req.cashout_address) } catch (e: InvalidPaytoError) { throw badRequest("Invalid cash-out address: ${req.cashout_address}") } diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt index 5d492914..54519bbb 100644 --- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt +++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt @@ -80,7 +80,7 @@ data class AccountPair( ) fun insertNewAccount(username: String, password: String, - name: String? = null, // tests do not usually give one. + name: String? = null, // tests and access API may not give one. iban: String? = null, demobank: String = "default", isPublic: Boolean = false): AccountPair { diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt index 2ebe5fc2..e6559897 100644 --- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt +++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt @@ -111,7 +111,19 @@ fun getBalance(accountLabel: String, HttpStatusCode.InternalServerError, "Demobank '$demobankName' not found" ) - val account = getBankAccountFromLabel(accountLabel, demobank) + + /** + * Setting withBankFault to true for the following reason: + * when asking for a balance, the bank should have made sure + * that the user has a bank account (together with a customer profile). + * If that's not the case, it's bank's fault, since it didn't check + * earlier. + */ + val account = getBankAccountFromLabel( + accountLabel, + demobank, + withBankFault = true + ) return getBalance(account, withPending) } |