gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: Avoid separate endpoint for public his


From: gnunet
Subject: [libeufin] branch master updated: Avoid separate endpoint for public histories.
Date: Wed, 20 Oct 2021 22:20:07 +0200

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new de9a4f8  Avoid separate endpoint for public histories.
de9a4f8 is described below

commit de9a4f848c88d719baabac6df366fee8e5551e1c
Author: ms <ms@taler.net>
AuthorDate: Wed Oct 20 22:19:55 2021 +0200

    Avoid separate endpoint for public histories.
---
 .../tech/libeufin/sandbox/EbicsProtocolBackend.kt  | 23 ----------------
 .../main/kotlin/tech/libeufin/sandbox/Helpers.kt   | 27 +++++++++++++++++++
 .../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
index 7a54d64..73ea9ba 100644
--- 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
index 6e290f7..75c876e 100644
--- 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
index ce0ebdf..487c71f 100644
--- 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
                 }
             }
-
         }
     }
 }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]