add: department exclusion check for auto-approval

This commit is contained in:
ohmo
2026-07-04 16:36:32 +07:00
parent 65837e2899
commit d1991a173e
+7 -3
View File
@@ -172,6 +172,7 @@ def find_user_in_ad(requester, caller_phone=None, ticket_id=None):
conn = Connection(server, user=AD_USER, password=AD_PASSWORD, auto_bind=True, receive_timeout=AD_RECEIVE_TIMEOUT)
conn.search(search_base=AD_BASE, search_filter=ldap_filter, attributes=["l", "company", "manager"])
conn.search(search_base=AD_BASE, search_filter=ldap_filter, attributes=["l", "company", "manager", "department"])
if not conn.entries:
log_to_file(f" [AD] ❌ Объект ({search_by}) не найден in AD!", ticket_id)
return None
@@ -196,6 +197,8 @@ def find_user_in_ad(requester, caller_phone=None, ticket_id=None):
department = user.department.value if "department" in user and user.department.value else None
return {"city": city, "company": company, "ad_path": ad_path, "manager_email": manager_email, "source": f"AD ({search_by})"}
return {"city": city, "company": company, "department": department, "ad_path": ad_path, "manager_email": manager_email, "source": f"AD ({search_by})"}
log_to_file(f"❌ Ошибка LDAP или таймаут сети AD: {e}", ticket_id)
return None
def resolve_support_group(qdrant_group, city, company, ad_path):
@@ -761,8 +764,8 @@ def process_ticket_logic(req_id):
company = user_info["company"] if user_info else None
ad_path = user_info["ad_path"] if user_info else None
manager_email = user_info["manager_email"] if user_info else None
user_department = user_info["department"] if user_info else None
info_source = user_info["source"] if user_info else "Не определен"
user_department = user_info["department"] if user_info else None
prefix_used = False
if caller_phone and not user_info:
@@ -877,7 +880,6 @@ def process_ticket_logic(req_id):
cat_name = cat_obj.get("name", "") if isinstance(cat_obj, dict) else ""
subcat_name = subcat_obj.get("name", "") if isinstance(subcat_obj, dict) else ""
is_city_ok = False
is_city_ok = False
if city:
for c in APPROVAL_CITIES:
@@ -902,10 +904,12 @@ def process_ticket_logic(req_id):
if is_excluded:
t_log(" ⏭ Пропуск: пользователь в исключённом отделе.")
continue
t_log(f"✔ Условия совпали. Запуск процесса согласования для {manager_email}...")
if is_city_ok and (is_group_ok or is_cat_ok):
if manager_email:
t_log(f"✔ Условия совпали. Запуск процесса согласования для {manager_email}...")
ai_was_used = True
share_success, share_log = share_ticket_for_approval(req_id, manager_email)
t_log(share_log)