fix: AD lookup by email/UPN instead of sAMAccountName to prevent wrong requester email
This commit is contained in:
@@ -112,7 +112,7 @@ async def instruct_router_handler(msg: Message):
|
|||||||
subject = f"Запрос доступа к Trueconf"
|
subject = f"Запрос доступа к Trueconf"
|
||||||
description = f"Пользователь {cn} ({user_id}) запросил инструкцию по Trueconf, но не имеет группы 2FA. Требуется выдача доступа."
|
description = f"Пользователь {cn} ({user_id}) запросил инструкцию по Trueconf, но не имеет группы 2FA. Требуется выдача доступа."
|
||||||
# Ищем email пользователя в AD, как в service_desk
|
# Ищем email пользователя в AD, как в service_desk
|
||||||
ad_user = await asyncio.to_thread(get_ad_user_sync, login)
|
ad_user = await asyncio.to_thread(get_ad_user_sync, user_id)
|
||||||
requester_email = ad_user.get("mail") if ad_user and ad_user.get("mail") else DEFAULT_REQUESTER
|
requester_email = ad_user.get("mail") if ad_user and ad_user.get("mail") else DEFAULT_REQUESTER
|
||||||
ticket_id = await create_ticket_in_sd(requester_email, subject, description, "Кемерово")
|
ticket_id = await create_ticket_in_sd(requester_email, subject, description, "Кемерово")
|
||||||
logger.info(f"SD ticket created for {cn}: #{ticket_id}")
|
logger.info(f"SD ticket created for {cn}: #{ticket_id}")
|
||||||
|
|||||||
@@ -70,15 +70,18 @@ sd_sessions = {}
|
|||||||
# ================================================
|
# ================================================
|
||||||
# БИЗНЕС-ЛОГИКА
|
# БИЗНЕС-ЛОГИКА
|
||||||
# ================================================
|
# ================================================
|
||||||
def get_ad_user_sync(login: str):
|
def get_ad_user_sync(user_id: str):
|
||||||
|
"""Ищем по email/UPN (search_by_user_id), НЕ по sAMAccountName.
|
||||||
|
user_id из TrueConf — обычно email вида 'login@tcs.sibcem.ru'.
|
||||||
|
Функция сама заменит @tcs.sibcem.ru на @sibcem.ru и найдёт правильную учётку."""
|
||||||
try:
|
try:
|
||||||
from utils.ad_search import search_by_login
|
from utils.ad_search import search_by_user_id
|
||||||
entries = search_by_login(login, ["displayName", "mail", "l", "userAccountControl"])
|
entries = search_by_user_id(user_id, ["displayName", "mail", "l", "userAccountControl"])
|
||||||
if entries:
|
if entries:
|
||||||
user = entries[0]
|
user = entries[0]
|
||||||
uac = user.userAccountControl.value if 'userAccountControl' in user else 0
|
uac = user.userAccountControl.value if 'userAccountControl' in user else 0
|
||||||
return {
|
return {
|
||||||
"name": user.displayName.value if 'displayName' in user else login,
|
"name": user.displayName.value if 'displayName' in user else user_id,
|
||||||
"mail": user.mail.value if 'mail' in user else None,
|
"mail": user.mail.value if 'mail' in user else None,
|
||||||
"city": user.l.value if 'l' in user else "Кемерово",
|
"city": user.l.value if 'l' in user else "Кемерово",
|
||||||
"is_disabled": bool(uac & 2)
|
"is_disabled": bool(uac & 2)
|
||||||
@@ -220,7 +223,7 @@ async def _create_ticket_and_attach_files(user_id, msg_text, session, msg, login
|
|||||||
"""Логика генерации темы, отправки в SD и загрузки всех очередей вложений."""
|
"""Логика генерации темы, отправки в SD и загрузки всех очередей вложений."""
|
||||||
session["step"] = "creating_ticket"
|
session["step"] = "creating_ticket"
|
||||||
try:
|
try:
|
||||||
ad_user = await asyncio.to_thread(get_ad_user_sync, login)
|
ad_user = await asyncio.to_thread(get_ad_user_sync, user_id)
|
||||||
sd_workflow_logger.info(f"👤 [AD Lookup] User: {login} -> Found: {ad_user is not None}")
|
sd_workflow_logger.info(f"👤 [AD Lookup] User: {login} -> Found: {ad_user is not None}")
|
||||||
sender_email = ad_user.get("mail") if ad_user else DEFAULT_REQUESTER
|
sender_email = ad_user.get("mail") if ad_user else DEFAULT_REQUESTER
|
||||||
city = ad_user.get("city") if ad_user else "Кемерово"
|
city = ad_user.get("city") if ad_user else "Кемерово"
|
||||||
|
|||||||
Reference in New Issue
Block a user