add: department exclusion check for auto-approval
This commit is contained in:
+17
-13
@@ -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 = 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"])
|
||||||
conn.search(search_base=AD_BASE, search_filter=ldap_filter, attributes=["l", "company", "manager", "department"])
|
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)
|
log_to_file(f" [AD] ❌ Объект ({search_by}) не найден in AD!", ticket_id)
|
||||||
return None
|
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
|
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, "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
|
return None
|
||||||
|
|
||||||
def resolve_support_group(qdrant_group, city, company, ad_path):
|
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
|
company = user_info["company"] if user_info else None
|
||||||
ad_path = user_info["ad_path"] 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
|
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 "Не определен"
|
info_source = user_info["source"] if user_info else "Не определен"
|
||||||
|
user_department = user_info["department"] if user_info else None
|
||||||
|
|
||||||
prefix_used = False
|
prefix_used = False
|
||||||
if caller_phone and not user_info:
|
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 ""
|
cat_name = cat_obj.get("name", "") if isinstance(cat_obj, dict) else ""
|
||||||
subcat_name = subcat_obj.get("name", "") if isinstance(subcat_obj, dict) else ""
|
subcat_name = subcat_obj.get("name", "") if isinstance(subcat_obj, dict) else ""
|
||||||
|
|
||||||
is_city_ok = False
|
|
||||||
is_city_ok = False
|
is_city_ok = False
|
||||||
if city:
|
if city:
|
||||||
for c in APPROVAL_CITIES:
|
for c in APPROVAL_CITIES:
|
||||||
@@ -902,20 +904,22 @@ def process_ticket_logic(req_id):
|
|||||||
if is_excluded:
|
if is_excluded:
|
||||||
t_log(" ⏭ Пропуск: пользователь в исключённом отделе.")
|
t_log(" ⏭ Пропуск: пользователь в исключённом отделе.")
|
||||||
continue
|
continue
|
||||||
t_log(f"✔ Условия совпали. Запуск процесса согласования для {manager_email}...")
|
|
||||||
if is_city_ok and (is_group_ok or is_cat_ok):
|
if is_city_ok and (is_group_ok or is_cat_ok):
|
||||||
t_log(f"✔ Условия совпали. Запуск процесса согласования для {manager_email}...")
|
if manager_email:
|
||||||
ai_was_used = True
|
t_log(f"✔ Условия совпали. Запуск процесса согласования для {manager_email}...")
|
||||||
share_success, share_log = share_ticket_for_approval(req_id, manager_email)
|
ai_was_used = True
|
||||||
t_log(share_log)
|
|
||||||
|
|
||||||
cc_success, cc_log = add_email_to_notify(req_id, manager_email)
|
share_success, share_log = share_ticket_for_approval(req_id, manager_email)
|
||||||
t_log(cc_log)
|
t_log(share_log)
|
||||||
|
|
||||||
success, step_detail = trigger_manager_approval(req_id, manager_email)
|
cc_success, cc_log = add_email_to_notify(req_id, manager_email)
|
||||||
t_log(step_detail)
|
t_log(cc_log)
|
||||||
else:
|
|
||||||
t_log("⚠️ Согласование невозможно: у пользователя не указан руководитель в AD.")
|
success, step_detail = trigger_manager_approval(req_id, manager_email)
|
||||||
|
t_log(step_detail)
|
||||||
|
else:
|
||||||
|
t_log("⚠️ Согласование невозможно: у пользователя не указан руководитель в AD.")
|
||||||
else:
|
else:
|
||||||
if ai_was_used:
|
if ai_was_used:
|
||||||
t_log("\n=== ШАГ 5. АВТОСОГЛАСОВАНИЕ ===")
|
t_log("\n=== ШАГ 5. АВТОСОГЛАСОВАНИЕ ===")
|
||||||
|
|||||||
Reference in New Issue
Block a user