[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: accounts name filter
From: |
gnunet |
Subject: |
[libeufin] branch master updated: accounts name filter |
Date: |
Fri, 10 Feb 2023 16:17:18 +0100 |
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 ed0c2fcc accounts name filter
ed0c2fcc is described below
commit ed0c2fcc5dca5d4abb978686619c0afcc0a09d3c
Author: MS <ms@taler.net>
AuthorDate: Fri Feb 10 16:16:52 2023 +0100
accounts name filter
---
nexus/src/test/kotlin/MakeEnv.kt | 4 +++-
nexus/src/test/kotlin/SandboxCircuitApiTest.kt | 19 +++++++++++++++++++
.../main/kotlin/tech/libeufin/sandbox/CircuitApi.kt | 16 +++++++++++++++-
3 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/nexus/src/test/kotlin/MakeEnv.kt b/nexus/src/test/kotlin/MakeEnv.kt
index 269a6380..d2a2b480 100644
--- a/nexus/src/test/kotlin/MakeEnv.kt
+++ b/nexus/src/test/kotlin/MakeEnv.kt
@@ -22,6 +22,8 @@ data class EbicsKeys(
)
const val TEST_DB_FILE = "/tmp/nexus-test.sqlite3"
const val TEST_DB_CONN = "jdbc:sqlite:$TEST_DB_FILE"
+// Convenience DB connection to switch to Postgresql:
+// const val TEST_DB_CONN = "jdbc:postgresql://localhost:5432/talercheck?user="
val BANK_IBAN = getIban()
val FOO_USER_IBAN = getIban()
val BAR_USER_IBAN = getIban()
@@ -63,7 +65,7 @@ fun withTestDatabase(f: () -> Unit) {
it.delete()
}
}
- Database.connect("jdbc:sqlite:$TEST_DB_FILE")
+ Database.connect(TEST_DB_CONN)
TransactionManager.manager.defaultIsolationLevel =
java.sql.Connection.TRANSACTION_SERIALIZABLE
dbDropTables(TEST_DB_CONN)
tech.libeufin.sandbox.dbDropTables(TEST_DB_CONN)
diff --git a/nexus/src/test/kotlin/SandboxCircuitApiTest.kt
b/nexus/src/test/kotlin/SandboxCircuitApiTest.kt
index decadf3b..86bd90f0 100644
--- a/nexus/src/test/kotlin/SandboxCircuitApiTest.kt
+++ b/nexus/src/test/kotlin/SandboxCircuitApiTest.kt
@@ -5,7 +5,9 @@ import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.server.testing.*
import kotlinx.coroutines.runBlocking
+import org.jetbrains.exposed.sql.lowerCase
import org.jetbrains.exposed.sql.transactions.transaction
+import org.junit.Ignore
import org.junit.Test
import tech.libeufin.sandbox.*
import java.io.File
@@ -427,6 +429,23 @@ class SandboxCircuitApiTest {
}
}
+ // Tests the database RegEx filter on customer names.
+ @Ignore // Since no assert takes place.
+ @Test
+ fun customerFilter() {
+ withTestDatabase {
+ prepSandboxDb()
+ testApplication {
+ application(sandboxApp)
+ val R =
client.get("/demobanks/default/circuit-api/accounts?filter=b") {
+ basicAuth("admin", "foo")
+ expectSuccess = true
+ }
+ println(R.bodyAsText())
+ }
+ }
+ }
+
@Test
fun tanCommandTest() {
/**
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt
index a21820a6..0b655de4 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.deleteAll
+import org.jetbrains.exposed.sql.lowerCase
import org.jetbrains.exposed.sql.transactions.transaction
import tech.libeufin.sandbox.CashoutOperationsTable.uuid
import tech.libeufin.util.*
@@ -505,12 +507,24 @@ fun circuitApi(circuitRoute: Route) {
))
return@get
}
+
// Get summary of all the accounts.
circuitRoute.get("/accounts") {
call.request.basicAuth(onlyAdmin = true)
+ val maybeFilter: String? = call.request.queryParameters["filter"]
+ /**
+ * Equip the given filter with left and right catch-all wildcards,
+ * otherwise use one catch-all wildcard.
+ */
+ val filter = if (maybeFilter != null) {
+ "%${maybeFilter}%"
+ } else "%"
val customers = mutableListOf<Any>()
transaction {
- DemobankCustomerEntity.all().forEach {
+ DemobankCustomerEntity.find{
+ // like() is case insensitive.
+ DemobankCustomersTable.name.like(filter)
+ }.forEach {
if (it.cashout_address == null) {
logger.debug("Not listing account '${it.username}', as
that" +
" misses the cash-out address " +
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libeufin] branch master updated: accounts name filter,
gnunet <=