libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit de9a4f848c88d719baabac6df366fee8e5551e1c
parent 59bda835da5c868f0c8be06df72a30542935d6d8
Author: ms <ms@taler.net>
Date:   Wed, 20 Oct 2021 22:19:55 +0200

Avoid separate endpoint for public histories.

Diffstat:
Msandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt | 23-----------------------
Msandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt | 27+++++++++++++++++++++++++++
Msandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 31+++++++++++++++++++------------
3 files changed, 46 insertions(+), 35 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt @@ -462,29 +462,6 @@ fun buildCamtString( ) } -fun getHistoryElementFromTransactionRow( - dbRow: BankAccountFreshTransactionEntity -): RawPayment { - return RawPayment( - subject = dbRow.transactionRef.subject, - creditorIban = dbRow.transactionRef.creditorIban, - creditorBic = dbRow.transactionRef.creditorBic, - creditorName = dbRow.transactionRef.creditorName, - debtorIban = dbRow.transactionRef.debtorIban, - debtorBic = dbRow.transactionRef.debtorBic, - debtorName = dbRow.transactionRef.debtorName, - date = importDateFromMillis(dbRow.transactionRef.date).toDashedDate(), - amount = dbRow.transactionRef.amount, - currency = dbRow.transactionRef.currency, - // The line below produces a value too long (>35 chars), - // and dbRow makes the document invalid! - // uid = "${dbRow.pmtInfId}-${it.msgId}" - uid = dbRow.transactionRef.accountServicerReference, - direction = dbRow.transactionRef.direction, - pmtInfId = dbRow.transactionRef.pmtInfId - ) -} - fun getLastBalance(bankAccount: BankAccountEntity): BigDecimal { val lastStatement = BankAccountStatementEntity.find { BankAccountStatementsTable.bankAccount eq bankAccount.id diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt @@ -59,6 +59,33 @@ fun getOrderTypeFromTransactionId(transactionID: String): String { return uploadTransaction.orderType } +fun getHistoryElementFromTransactionRow(dbRow: BankAccountTransactionEntity): RawPayment { + return RawPayment( + subject = dbRow.subject, + creditorIban = dbRow.creditorIban, + creditorBic = dbRow.creditorBic, + creditorName = dbRow.creditorName, + debtorIban = dbRow.debtorIban, + debtorBic = dbRow.debtorBic, + debtorName = dbRow.debtorName, + date = importDateFromMillis(dbRow.date).toDashedDate(), + amount = dbRow.amount, + currency = dbRow.currency, + // The line below produces a value too long (>35 chars), + // and dbRow makes the document invalid! + // uid = "${dbRow.pmtInfId}-${it.msgId}" + uid = dbRow.accountServicerReference, + direction = dbRow.direction, + pmtInfId = dbRow.pmtInfId + ) +} + +fun getHistoryElementFromTransactionRow( + dbRow: BankAccountFreshTransactionEntity +): RawPayment { + return getHistoryElementFromTransactionRow(dbRow.transactionRef) +} + /** * Book a CRDT and a DBIT transaction and return the unique reference thereof. * diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt @@ -1095,11 +1095,9 @@ val sandboxApp: Application.() -> Unit = { res } ?: throw notFound("Account '$accountAccessed' not found") // Check rights. - if (WITH_AUTH) { - if (bankAccount.owner != username) throw forbidden( + if (WITH_AUTH && bankAccount.owner != username) throw forbidden( "Customer '$username' cannot access bank account '$accountAccessed'" ) - } val creditDebitIndicator = if (bankAccount.isDebit) { "debit" } else { @@ -1116,10 +1114,24 @@ val sandboxApp: Application.() -> Unit = { return@get } get("/accounts/{account_name}/history") { - // New endpoint, access account history to display in the SPA - // (could be merged with GET /accounts/{account_name} + val bankAccount = getBankAccountFromLabel(call.getUriComponent("account_name")) + val authOk: Boolean = bankAccount.isPublic || (!WITH_AUTH) + if (!authOk && (call.request.basicAuth() != bankAccount.owner)) throw forbidden( + "Cannot access bank account ${bankAccount.label}" + ) + val ret = mutableListOf<RawPayment>() + transaction { + BankAccountTransactionEntity.find { + BankAccountTransactionsTable.account eq bankAccount.id + // FIXME: more criteria to come. + }.forEach { + ret.add(getHistoryElementFromTransactionRow(it)) + } + } + call.respond(ret) + return@get } - get("/accounts/public") { + get("/public-accounts") { val demobank = ensureDemobank(call) val ret = object { val publicAccounts = mutableListOf<PublicAccountInfo>() @@ -1142,10 +1154,6 @@ val sandboxApp: Application.() -> Unit = { call.respond(ret) return@get } - - get("/accounts/public/{account_name}/history") { - // Get transaction history of a public account - } // Keeping the prefix "testing" not to break tests. post("/testing/register") { // Check demobank was created. @@ -1177,11 +1185,10 @@ val sandboxApp: Application.() -> Unit = { passwordHash = CryptoUtil.hashpw(req.password) } } - call.respondText("Registration successful") + call.respond(object {}) return@post } } - } } }