From c12a75f87f9327b066fa0217a4a3e88db211d73d Mon Sep 17 00:00:00 2001
From: ValueOn AG
Date: Sat, 28 Mar 2026 23:56:28 +0100
Subject: [PATCH] fix user name resolution
---
modules/routes/routeBilling.py | 62 +++++++++++++++-------------------
1 file changed, 27 insertions(+), 35 deletions(-)
diff --git a/modules/routes/routeBilling.py b/modules/routes/routeBilling.py
index 4062163e..37674e53 100644
--- a/modules/routes/routeBilling.py
+++ b/modules/routes/routeBilling.py
@@ -1320,6 +1320,31 @@ def getUsersForMandate(
raise HTTPException(status_code=500, detail=str(e))
+def _attachCreatedByUserNamesToTransactionRows(rows: List[Dict[str, Any]]) -> None:
+ """Resolve createdByUserId to userName using root app interface (sysadmin transaction views)."""
+ try:
+ from modules.interfaces.interfaceDbApp import getRootInterface
+
+ appRoot = getRootInterface()
+ userNames: Dict[str, str] = {}
+ for row in rows:
+ uid = row.get("createdByUserId")
+ if not uid:
+ row["userName"] = ""
+ continue
+ if uid not in userNames:
+ try:
+ u = appRoot.getUser(uid)
+ userNames[uid] = u.username if u else uid[:8]
+ except Exception:
+ userNames[uid] = uid[:8]
+ row["userName"] = userNames.get(uid, "")
+ except Exception:
+ for row in rows:
+ uid = row.get("createdByUserId")
+ row["userName"] = uid[:8] if uid else ""
+
+
def _enrichTransactionRows(transactions) -> List[Dict[str, Any]]:
"""Convert raw transaction dicts to enriched TransactionResponse rows with resolved usernames."""
result = []
@@ -1341,23 +1366,7 @@ def _enrichTransactionRows(transactions) -> List[Dict[str, Any]]:
)
result.append(row.model_dump())
- try:
- from modules.interfaces.interfaceDbUam import _getRootInterface as getUamRoot
- uamInterface = getUamRoot()
- userNames: Dict[str, str] = {}
- for row in result:
- uid = row.get("createdByUserId")
- if uid and uid not in userNames:
- try:
- user = uamInterface.getUser(uid)
- userNames[uid] = user.get("username", uid[:8]) if user else uid[:8]
- except Exception:
- userNames[uid] = uid[:8]
- row["userName"] = userNames.get(uid, "") if uid else ""
- except Exception:
- for row in result:
- row["userName"] = row.get("createdByUserId", "")[:8] if row.get("createdByUserId") else ""
-
+ _attachCreatedByUserNamesToTransactionRows(result)
return result
@@ -1385,24 +1394,7 @@ def _buildTransactionsList(ctx: RequestContext, targetMandateId: str) -> List[Di
)
result.append(row.model_dump())
- # Resolve user names
- try:
- from modules.interfaces.interfaceDbUam import _getRootInterface as getUamRoot
- uamInterface = getUamRoot()
- userNames: Dict[str, str] = {}
- for row in result:
- uid = row.get("createdByUserId")
- if uid and uid not in userNames:
- try:
- user = uamInterface.getUser(uid)
- userNames[uid] = user.get("username", uid[:8]) if user else uid[:8]
- except Exception:
- userNames[uid] = uid[:8]
- row["userName"] = userNames.get(uid, "") if uid else ""
- except Exception:
- for row in result:
- row["userName"] = row.get("createdByUserId", "")[:8] if row.get("createdByUserId") else ""
-
+ _attachCreatedByUserNamesToTransactionRows(result)
return result