From 911c5ab1042dad7207dd0414c6f445b63853bddb Mon Sep 17 00:00:00 2001 From: iSecloud <869820505@qq.com> Date: Wed, 15 Jan 2025 17:20:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(backend):=20=E9=80=9A=E7=9F=A5=E8=A1=A5?= =?UTF-8?q?=E5=85=85=E5=8D=8F=E5=8A=A9=E4=BA=BA=E9=80=BB=E8=BE=91=20#9080?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbm-ui/backend/core/notify/handlers.py | 13 +++++++++---- dbm-ui/backend/core/notify/template.py | 4 ++-- dbm-ui/backend/ticket/models/ticket.py | 4 ++-- dbm-ui/backend/ticket/todos/pipeline_todo.py | 4 ++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/dbm-ui/backend/core/notify/handlers.py b/dbm-ui/backend/core/notify/handlers.py index 20b8d38a51..5e6b824efa 100644 --- a/dbm-ui/backend/core/notify/handlers.py +++ b/dbm-ui/backend/core/notify/handlers.py @@ -76,7 +76,8 @@ def get_msg_type(cls): @staticmethod def get_actions(msg_type, ticket): """获取bkchat操作按钮""" - if ticket.status not in [TicketStatus.APPROVE, TicketStatus.TODO]: + # TODO: 暂时去掉[待确认]按钮 + if ticket.status not in [TicketStatus.APPROVE]: return [] todo = ticket.todo_of_ticket.filter(status=TodoStatus.TODO).first() @@ -133,10 +134,12 @@ def render_title_content(self, msg_type, title, content, ticket, phase, receiver def send_msg(self, msg_type, context): ticket, phase, receivers = context["ticket"], context["phase"], context["receivers"] title, content = self.render_title_content(msg_type, self.title, self.content, ticket, phase, receivers) + ticket_operators = ticket.get_current_operators() + approvers = list(dict.fromkeys(ticket_operators["operators"] + ticket_operators["helpers"])) msg_info = { "title": title, # 处理人 - "approvers": ticket.get_current_operators(), + "approvers": approvers, # 微信消息时 receiver生效,不发群消息,群消息时,receive_group,不发送个人消息 "receiver": self.receivers if msg_type == MsgType.RTX else [], "receive_group": self.receivers if msg_type == MsgType.WECOM_ROBOT else [], @@ -247,7 +250,7 @@ def __init__(self, ticket_id: int, flow_id: int = None): def get_support_msg_types(cls): # 获取当前环境下支持的通知类型 # 所有的拓展方式都需要接入CMSI,所以直接返回CMSI支持方式即可 - # 暂不暴露微信的通知方式 + # TODO: 暂不暴露微信的通知方式 msg_types = CmsiApi.get_msg_type() msg_type_map = {msg["type"]: msg for msg in msg_types} msg_type_map[MsgType.WEIXIN.value]["is_active"] = False @@ -298,6 +301,7 @@ def render_msg_template(self, msg_type: str): template = jinja_env.from_string(TODO_TEMPLATE) biz_name = AppCache.get_biz_name(self.bk_biz_id) + ticket_operators = self.ticket.get_current_operators() payload = { "ticket_type": TicketType.get_choice_label(self.ticket.ticket_type), "biz_name": f"{biz_name}(#{self.bk_biz_id}, {biz_name})", @@ -307,7 +311,8 @@ def render_msg_template(self, msg_type: str): "submit_time": self.ticket.create_at.astimezone().strftime("%Y-%m-%d %H:%M:%S%z"), "update_time": self.ticket.update_at.astimezone().strftime("%Y-%m-%d %H:%M:%S%z"), "status": TicketStatus.get_choice_label(self.phase), - "operators": ",".join(self.ticket.get_current_operators()), + "operators": ",".join(ticket_operators["operators"]), + "helpers": ",".join(ticket_operators["helpers"]), "detail_address": self.ticket.url, "terminate_reason": self.ticket.get_terminate_reason(), } diff --git a/dbm-ui/backend/core/notify/template.py b/dbm-ui/backend/core/notify/template.py index d1b60f9453..d7348e658f 100644 --- a/dbm-ui/backend/core/notify/template.py +++ b/dbm-ui/backend/core/notify/template.py @@ -19,7 +19,7 @@ 业务: {{biz_name}} 域名: {{cluster_domains}} 备注: {{remark}} - 当前处理人: {{operators}} + 当前处理人: {{operators}},当前协助人: {{helpers}} 查看详情: {{detail_address}}\ """ ) @@ -44,7 +44,7 @@ 业务: {{biz_name}} 域名: {{cluster_domains}} 失败时间: {{update_time}} - 当前当前处理人: {{operators}} + 当前处理人: {{operators}},当前协助人: {{helpers}} 查看详情: {{detail_address}}\ """ ) diff --git a/dbm-ui/backend/ticket/models/ticket.py b/dbm-ui/backend/ticket/models/ticket.py index d1c9456aa4..bc072b95ef 100644 --- a/dbm-ui/backend/ticket/models/ticket.py +++ b/dbm-ui/backend/ticket/models/ticket.py @@ -154,11 +154,11 @@ def get_terminate_reason(self): return reason def get_current_operators(self): - # 获取当前流程处理人 + # 获取当前流程处理人和协助人 running_todo = self.todo_of_ticket.filter(status=TodoStatus.TODO).first() if not running_todo: return [] - return running_todo.operators + return {"operators": running_todo.operators, "helpers": running_todo.helpers} def update_details(self, **kwargs): self.details.update(kwargs) diff --git a/dbm-ui/backend/ticket/todos/pipeline_todo.py b/dbm-ui/backend/ticket/todos/pipeline_todo.py index ace2ad5d0b..f9d259d4d8 100644 --- a/dbm-ui/backend/ticket/todos/pipeline_todo.py +++ b/dbm-ui/backend/ticket/todos/pipeline_todo.py @@ -17,7 +17,7 @@ from backend.core import notify from backend.flow.engine.bamboo.engine import BambooEngine from backend.ticket import todos -from backend.ticket.constants import TodoStatus, TodoType +from backend.ticket.constants import TODO_RUNNING_STATUS, TodoStatus, TodoType from backend.ticket.models import Flow, TodoHistory from backend.ticket.todos import ActionType, BaseTodoContext @@ -73,7 +73,7 @@ def create(cls, ticket, flow, root_id, node_id): flow = Flow.objects.select_for_update().get(id=flow.id) # 当前不存在待确认的todo,则发送通知 - if not flow.todo_of_flow.filter(type=TodoType.INNER_APPROVE).count(): + if not flow.todo_of_flow.filter(type=TodoType.INNER_APPROVE, status__in=TODO_RUNNING_STATUS).count(): notify.send_msg.apply_async(args=(ticket.id,)) Todo.objects.create(