fix user name resolution
This commit is contained in:
parent
1fdf238aaf
commit
c12a75f87f
1 changed files with 27 additions and 35 deletions
|
|
@ -1320,6 +1320,31 @@ def getUsersForMandate(
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
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]]:
|
def _enrichTransactionRows(transactions) -> List[Dict[str, Any]]:
|
||||||
"""Convert raw transaction dicts to enriched TransactionResponse rows with resolved usernames."""
|
"""Convert raw transaction dicts to enriched TransactionResponse rows with resolved usernames."""
|
||||||
result = []
|
result = []
|
||||||
|
|
@ -1341,23 +1366,7 @@ def _enrichTransactionRows(transactions) -> List[Dict[str, Any]]:
|
||||||
)
|
)
|
||||||
result.append(row.model_dump())
|
result.append(row.model_dump())
|
||||||
|
|
||||||
try:
|
_attachCreatedByUserNamesToTransactionRows(result)
|
||||||
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 ""
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1385,24 +1394,7 @@ def _buildTransactionsList(ctx: RequestContext, targetMandateId: str) -> List[Di
|
||||||
)
|
)
|
||||||
result.append(row.model_dump())
|
result.append(row.model_dump())
|
||||||
|
|
||||||
# Resolve user names
|
_attachCreatedByUserNamesToTransactionRows(result)
|
||||||
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 ""
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue