From 09a2ccc6b458c97af1e5825df0739669d352572f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B5=D0=BD=D0=B8=D1=81=20=D0=9A=D1=80=D0=B8=D0=B2?= =?UTF-8?q?=D0=BE=D1=87=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 29 Jul 2026 00:30:04 +0700 Subject: [PATCH] fix: use UPN as mail fallback in instruct when mail is empty --- instruct/handlers.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/instruct/handlers.py b/instruct/handlers.py index ab8ab64..6c546ac 100644 --- a/instruct/handlers.py +++ b/instruct/handlers.py @@ -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: