fixed user references
This commit is contained in:
parent
24f0c3e2eb
commit
8221a0da3e
2 changed files with 3 additions and 37 deletions
|
|
@ -121,27 +121,6 @@ def getModelFields(model_class) -> Dict[str, str]:
|
||||||
return fields
|
return fields
|
||||||
|
|
||||||
|
|
||||||
def _get_fk_sort_meta(model_class) -> Dict[str, Dict[str, str]]:
|
|
||||||
"""Map FK field name -> {model, labelField} from json_schema_extra (``fk_model`` + ``fk_label_field``).
|
|
||||||
|
|
||||||
``fk_model`` may be omitted if ``fk_target.table`` is set (table name = resolver / JOIN key).
|
|
||||||
"""
|
|
||||||
result: Dict[str, Dict[str, str]] = {}
|
|
||||||
for name, field_info in model_class.model_fields.items():
|
|
||||||
extra = field_info.json_schema_extra
|
|
||||||
if not extra or not isinstance(extra, dict):
|
|
||||||
continue
|
|
||||||
fk_model = extra.get("fk_model")
|
|
||||||
tgt = extra.get("fk_target")
|
|
||||||
if not fk_model and isinstance(tgt, dict) and tgt.get("table"):
|
|
||||||
fk_model = tgt["table"]
|
|
||||||
label_field = extra.get("fk_label_field")
|
|
||||||
if fk_model and label_field:
|
|
||||||
result[name] = {"model": str(fk_model), "labelField": str(label_field)}
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def parseRecordFields(record: Dict[str, Any], fields: Dict[str, str], context: str = "") -> None:
|
def parseRecordFields(record: Dict[str, Any], fields: Dict[str, str], context: str = "") -> None:
|
||||||
"""Parse record fields in-place: numeric typing, vector parsing, JSONB deserialization."""
|
"""Parse record fields in-place: numeric typing, vector parsing, JSONB deserialization."""
|
||||||
import json as _json
|
import json as _json
|
||||||
|
|
|
||||||
|
|
@ -66,24 +66,12 @@ def resolveUserLabels(ids: List[str]) -> Dict[str, Optional[str]]:
|
||||||
"""Resolve user IDs to display names. Returns None for unresolvable."""
|
"""Resolve user IDs to display names. Returns None for unresolvable."""
|
||||||
from modules.interfaces.interfaceDbApp import getRootInterface
|
from modules.interfaces.interfaceDbApp import getRootInterface
|
||||||
rootIface = getRootInterface()
|
rootIface = getRootInterface()
|
||||||
from modules.datamodels.datamodelUam import User as _User
|
from modules.datamodels.datamodelUam import UserInDB as _UserInDB
|
||||||
uniqueIds = list(set(ids))
|
uniqueIds = list(set(ids))
|
||||||
users = rootIface.db.getRecordset(
|
users = rootIface.db.getRecordset(
|
||||||
_User,
|
_UserInDB,
|
||||||
recordFilter={"id": uniqueIds},
|
recordFilter={"id": uniqueIds},
|
||||||
)
|
)
|
||||||
if not users and uniqueIds:
|
|
||||||
logger.warning(
|
|
||||||
"resolveUserLabels: query returned 0 users for %d ids (db=%s, table=%s). "
|
|
||||||
"Attempting full table scan...",
|
|
||||||
len(uniqueIds), getattr(rootIface.db, 'dbDatabase', '?'), _User.__name__,
|
|
||||||
)
|
|
||||||
allUsers = rootIface.db.getRecordset(_User)
|
|
||||||
logger.warning(
|
|
||||||
"resolveUserLabels: full scan found %d users total. Looking for ids: %s",
|
|
||||||
len(allUsers or []), uniqueIds[:3],
|
|
||||||
)
|
|
||||||
users = [u for u in (allUsers or []) if u.get("id") in set(uniqueIds)]
|
|
||||||
result: Dict[str, Optional[str]] = {}
|
result: Dict[str, Optional[str]] = {}
|
||||||
found: Dict[str, dict] = {}
|
found: Dict[str, dict] = {}
|
||||||
for u in (users or []):
|
for u in (users or []):
|
||||||
|
|
@ -92,9 +80,8 @@ def resolveUserLabels(ids: List[str]) -> Dict[str, Optional[str]]:
|
||||||
for uid in ids:
|
for uid in ids:
|
||||||
u = found.get(uid)
|
u = found.get(uid)
|
||||||
if u:
|
if u:
|
||||||
result[uid] = u.get("username") or u.get("email") or None
|
result[uid] = u.get("displayName") or u.get("username") or u.get("email") or None
|
||||||
else:
|
else:
|
||||||
logger.warning("resolveUserLabels: user not found for id=%s", uid)
|
|
||||||
result[uid] = None
|
result[uid] = None
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue