fix: use UPN as mail fallback in instruct when mail is empty

This commit is contained in:
Денис Кривоченко
2026-07-29 00:30:04 +07:00
parent e07b0af6b4
commit 09a2ccc6b4
+6 -1
View File
@@ -86,7 +86,7 @@ def get_ad_user_info(user_id: str) -> dict | None:
try:
search_id = user_id.replace("@tcs.sibcem.ru", "@sibcem.ru")
entries = search_by_user_id(search_id, ["cn", "mail", "l", "userAccountControl"])
entries = search_by_user_id(search_id, ["cn", "mail", "l", "userAccountControl", "userPrincipalName"])
if entries:
entry = entries[0]
@@ -94,6 +94,11 @@ def get_ad_user_info(user_id: str) -> dict | None:
raw_mail = str(entry.mail) if 'mail' in entry else ""
# mail может быть "[]" (пустой LDAP объект), "" или "N/A" — фильтруем
mail = raw_mail if raw_mail and raw_mail not in ("[]", "N/A", "") else None
# Fallback: используем UPN если mail пустой
if not mail:
raw_upn = str(entry.userPrincipalName) if 'userPrincipalName' in entry else ""
if raw_upn and raw_upn not in ("[]", "N/A", ""):
mail = raw_upn
city = str(entry.l) if 'l' in entry and entry.l.value else "Кемерово"
return {"cn": cn, "mail": mail, "city": city}
except Exception as e: