Skip to content

Commit

Permalink
fix(backend): 通知补充协助人逻辑 #9080
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud committed Jan 15, 2025
1 parent 0cb216a commit 911c5ab
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
13 changes: 9 additions & 4 deletions dbm-ui/backend/core/notify/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 [],
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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})",
Expand All @@ -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(),
}
Expand Down
4 changes: 2 additions & 2 deletions dbm-ui/backend/core/notify/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
业务: {{biz_name}}
域名: {{cluster_domains}}
备注: {{remark}}
当前处理人: {{operators}}
当前处理人: {{operators}},当前协助人: {{helpers}}
查看详情: {{detail_address}}\
"""
)
Expand All @@ -44,7 +44,7 @@
业务: {{biz_name}}
域名: {{cluster_domains}}
失败时间: {{update_time}}
当前当前处理人: {{operators}}
当前处理人: {{operators}},当前协助人: {{helpers}}
查看详情: {{detail_address}}\
"""
)
Expand Down
4 changes: 2 additions & 2 deletions dbm-ui/backend/ticket/models/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions dbm-ui/backend/ticket/todos/pipeline_todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 911c5ab

Please sign in to comment.