commit 18dd2f70ed5d87f4bcdb36028571bb5976387230
parent c64828e98d72b28a7f1137c9f21fd3fe3a3c9048
Author: Florian Dold <florian.dold@gmail.com>
Date: Sun, 24 May 2020 23:11:19 +0530
transactions belong to the bank account, not the user
Diffstat:
3 files changed, 10 insertions(+), 35 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
@@ -91,7 +91,6 @@ class TalerIncomingPaymentEntity(id: EntityID<Long>) : LongEntity(id) {
* CAMT message.
*/
object RawBankTransactionsTable : LongIdTable() {
- val nexusUser = reference("nexusUser", NexusUsersTable)
val unstructuredRemittanceInformation = text("unstructuredRemittanceInformation")
val transactionType = text("transactionType") /* DBIT or CRDT */
val currency = text("currency")
@@ -115,7 +114,6 @@ class RawBankTransactionEntity(id: EntityID<Long>) : LongEntity(id) {
var counterpartBic by RawBankTransactionsTable.counterpartBic
var counterpartName by RawBankTransactionsTable.counterpartName
var bookingDate by RawBankTransactionsTable.bookingDate
- var nexusUser by NexusUserEntity referencedOn RawBankTransactionsTable.nexusUser
var status by RawBankTransactionsTable.status
var bankAccount by BankAccountEntity referencedOn RawBankTransactionsTable.bankAccount
}
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
@@ -104,20 +104,16 @@ fun getEbicsSubscriberDetails(userId: String, transportId: String): EbicsClientS
// FIXME(dold): This should put stuff under *fixed* bank account, not some we find via the IBAN.
fun processCamtMessage(
- userId: String,
+ bankAccountId: String,
camt53doc: Document
) {
transaction {
- val user = NexusUserEntity.findById(userId)
- if (user == null) {
+ val acct = BankAccountEntity.findById(bankAccountId)
+ if (acct == null) {
throw NexusError(HttpStatusCode.NotFound, "user not found")
}
RawBankTransactionEntity.new {
- bankAccount = getBankAccountFromIban(
- camt53doc.pickString(
- "//*[local-name()='Stmt']/*[local-name()='Acct']/*[local-name()='Id']/*[local-name()='IBAN']"
- )
- )
+ bankAccount = acct
unstructuredRemittanceInformation =
camt53doc.pickString("//*[local-name()='Ntry']//*[local-name()='Ustrd']")
transactionType = camt53doc.pickString("//*[local-name()='Ntry']//*[local-name()='CdtDbtInd']")
@@ -126,7 +122,6 @@ fun processCamtMessage(
status = camt53doc.pickString("//*[local-name()='Ntry']//*[local-name()='Sts']")
bookingDate =
parseDashedDate(camt53doc.pickString("//*[local-name()='BookgDt']//*[local-name()='Dt']")).millis
- nexusUser = user
counterpartIban =
camt53doc.pickString("//*[local-name()='${if (this.transactionType == "DBIT") "CdtrAcct" else "DbtrAcct"}']//*[local-name()='IBAN']")
counterpartName =
@@ -139,7 +134,8 @@ fun processCamtMessage(
suspend fun downloadAndPersistC5xEbics(
historyType: String,
client: HttpClient,
- userId: String,
+ bankAccountId: String,
+ bankConnectionId: String,
start: String?, // dashed date YYYY-MM(01-12)-DD(01-31)
end: String?, // dashed date YYYY-MM(01-12)-DD(01-31)
subscriberDetails: EbicsClientSubscriberDetails
@@ -163,7 +159,7 @@ suspend fun downloadAndPersistC5xEbics(
response.orderData.unzipWithLambda {
logger.debug("Camt entry: ${it.second}")
val camt53doc = XMLUtil.parseStringIntoDom(it.second)
- processCamtMessage(userId, camt53doc)
+ processCamtMessage(bankAccountId, camt53doc)
}
}
is EbicsDownloadBankErrorResult -> {
@@ -400,21 +396,3 @@ fun authenticateRequest(request: ApplicationRequest): NexusUserEntity {
}
return user
}
-
-
-fun getBankAccountFromIban(iban: String): BankAccountEntity {
- return transaction {
- BankAccountEntity.find {
- BankAccountsTable.iban eq iban
- }.firstOrNull() ?: throw NexusError(
- HttpStatusCode.NotFound,
- "Bank account with IBAN '$iban' not found"
- )
- }
-}
-
-/** Check if the nexus user is allowed to use the claimed bank account. */
-fun userHasRights(nexusUser: NexusUserEntity, iban: String): Boolean {
- // FIXME: implement permissions
- return true
-}
-\ No newline at end of file
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -534,7 +534,8 @@ fun serverMain() {
downloadAndPersistC5xEbics(
"C53",
client,
- res.userId,
+ accountid,
+ res.connectionName,
body.start,
body.end,
res.subscriberDetails
@@ -560,8 +561,7 @@ fun serverMain() {
transaction {
val userId = transaction { authenticateRequest(call.request).id.value }
RawBankTransactionEntity.find {
- RawBankTransactionsTable.nexusUser eq userId and
- (RawBankTransactionsTable.bankAccount eq bankAccount) and
+ (RawBankTransactionsTable.bankAccount eq bankAccount) and
RawBankTransactionsTable.bookingDate.between(
parseDashedDate(start ?: "1970-01-01").millis,
parseDashedDate(end ?: DateTime.now().toDashedDate()).millis