Skip to content

Commit

Permalink
fix(backend): itsm的处理人关联审批人 #8688
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud committed Dec 18, 2024
1 parent afe8c70 commit fcb96dd
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class RedisClusterViewSet(viewsets.ResourceViewSet):
ActionEnum.REDIS_VIEW,
ActionEnum.REDIS_BACKUP,
ActionEnum.REDIS_ACCESS_ENTRY_VIEW,
ActionEnum.REDIS_WEBCONSOLE,
]
list_instance_perm_actions = [ActionEnum.REDIS_VIEW]
list_external_perm_actions = [ActionEnum.ACCESS_ENTRY_EDIT]
Expand Down
7 changes: 4 additions & 3 deletions dbm-ui/backend/ticket/builders/mysql/mysql_priv_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ def build_controller_info(self) -> dict:


class MySQLAccountRuleChangeItsmFlowParamBuilder(builders.ItsmParamBuilder):
def get_approvers(self):
approver_list = DBRuleActionLog.get_notifiers(self.ticket.details["rule_id"])
return ",".join(approver_list)

def get_params(self):
params = super().get_params()
field_map = {field["key"]: field["value"] for field in params["fields"]}
# 获取权限审批人
approver_list = DBRuleActionLog.get_notifiers(self.ticket.details["rule_id"])
field_map["approver"] = ",".join(approver_list)
# 审批模式改成会签
field_map["approve_mode"] = ItsmApproveMode.CounterSign
# 导出itsm字段
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class BackendGroupSerializer(serializers.Serializer):
shard_num = serializers.IntegerField(help_text=_("集群分片数"))
group_num = serializers.IntegerField(help_text=_("部署机器组数"))
db_version = serializers.CharField(help_text=_("版本号"))
capacity = serializers.IntegerField(help_text=_("当前容量需求"))
capacity = serializers.FloatField(help_text=_("当前容量需求"))
future_capacity = serializers.IntegerField(help_text=_("未来容量需求"))
online_switch_type = serializers.ChoiceField(
help_text=_("切换类型"), choices=SwitchConfirmType.get_choices(), default=SwitchConfirmType.NO_CONFIRM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SpecSerializer(serializers.Serializer):
current_shard_num = serializers.IntegerField(help_text=_("当前分片数"))
cluster_shard_num = serializers.IntegerField(help_text=_("目标分片数"))
resource_spec = ResourceSpecSerializer(help_text=_("资源申请"))
capacity = serializers.IntegerField(help_text=_("当前容量需求"))
capacity = serializers.FloatField(help_text=_("当前容量需求"))
future_capacity = serializers.IntegerField(help_text=_("未来容量需求"))
db_version = serializers.CharField(help_text=_("版本号"))
online_switch_type = serializers.ChoiceField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SpecSerializer(serializers.Serializer):
current_cluster_type = serializers.ChoiceField(choices=ClusterType.get_choices(), help_text=_("当前集群类型"))
target_cluster_type = serializers.ChoiceField(choices=ClusterType.get_choices(), help_text=_("目标集群类型"))
resource_spec = ResourceSpecSerializer(help_text=_("资源申请"))
capacity = serializers.IntegerField(help_text=_("当前容量需求"))
capacity = serializers.FloatField(help_text=_("当前容量需求"))
future_capacity = serializers.IntegerField(help_text=_("未来容量需求"))
db_version = serializers.CharField(help_text=_("版本号"))
online_switch_type = serializers.ChoiceField(
Expand Down
3 changes: 2 additions & 1 deletion dbm-ui/backend/ticket/flow_manager/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
FlowType,
FlowTypeConfig,
TicketFlowStatus,
TodoStatus,
)
from backend.ticket.models import ClusterOperateRecord, Flow, InstanceOperateRecord, TicketFlowsConfig, Todo

Expand Down Expand Up @@ -265,7 +266,7 @@ def _revoke(self, operator) -> Any:
# 停止相关联的todo
from backend.ticket.todos import ActionType, TodoActorFactory

todos = Todo.objects.filter(ticket=self.ticket, flow=self.flow_obj)
todos = Todo.objects.filter(ticket=self.ticket, flow=self.flow_obj, status=TodoStatus.TODO)
for todo in todos:
TodoActorFactory.actor(todo).process(operator, ActionType.TERMINATE, params={})
# 刷新flow和单据状态 --> 终止
Expand Down
9 changes: 6 additions & 3 deletions dbm-ui/backend/ticket/flow_manager/itsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,16 @@ def _status(self) -> str:
# 把 ITSM 单据状态映射为本系统内的单据状态
current_status = self.ticket_approval_result["current_status"]
approve_result = self.ticket_approval_result["approve_result"]
updater = self.ticket_approval_result["updated_by"]
todo = self.flow_obj.todo_of_flow.first()

# 进行中
if current_status == ItsmTicketStatus.RUNNING:
return self.flow_obj.update_status(TicketFlowStatus.RUNNING)

todo = self.flow_obj.todo_of_flow.first()
updater = self.ticket_approval_result["updated_by"]

# 撤单
elif current_status == ItsmTicketStatus.REVOKED:
if current_status == ItsmTicketStatus.REVOKED:
todo.set_status(username=updater, status=TodoStatus.DONE_FAILED)
return self.flow_obj.update_status(TicketFlowStatus.TERMINATED)
# 审批通过
Expand Down
23 changes: 14 additions & 9 deletions dbm-ui/backend/ticket/models/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from backend.bk_web.constants import LEN_MIDDLE, LEN_SHORT
from backend.bk_web.models import AuditedModel
from backend.configuration.models import BizSettings, DBAdministrator
from backend.ticket.builders import BuilderFactory
from backend.ticket.constants import (
TODO_RUNNING_STATUS,
FlowMsgStatus,
Expand All @@ -42,17 +43,19 @@ def get_operators(self, todo_type, ticket, operators):
biz_helpers = BizSettings.get_assistance(ticket.bk_biz_id)

# 构造单据状态与处理人之间的对应关系
# - 审批中:提单人可撤销,dba可处理
# - 审批中:提单人可撤销,dba可处理,
# 考虑某些单据审批人是特定配置(数据导出 -- 运维审批),所以从ItsmBuilder获得审批人
# - 待执行:提单人 + 单据协助人
# - 待继续:提单人 + 单据协助人 + dba
# - 待补货:提单人 + 单据协助人 + dba
# - 已失败:提单人 + 单据协助人 + dba
# - 待继续:dba + 提单人 + 单据协助人
# - 待补货:dba + 提单人 + 单据协助人
# - 已失败:dba + 提单人 + 单据协助人
itsm_builder = BuilderFactory.get_builder_cls(ticket.ticket_type).itsm_flow_builder(ticket)
todo_operators_map = {
TodoType.ITSM: dba,
TodoType.ITSM: itsm_builder.get_approvers().split(","),
TodoType.APPROVE: creator + biz_helpers,
TodoType.INNER_APPROVE: creator + biz_helpers + dba,
TodoType.RESOURCE_REPLENISH: creator + biz_helpers + dba,
TodoType.INNER_FAILED: creator + biz_helpers + dba,
TodoType.INNER_APPROVE: dba + creator + biz_helpers,
TodoType.RESOURCE_REPLENISH: dba + creator + biz_helpers,
TodoType.INNER_FAILED: dba + creator + biz_helpers,
}
# 按照顺序去重
operators = list(dict.fromkeys(operators + todo_operators_map.get(todo_type, [])))
Expand Down Expand Up @@ -109,8 +112,10 @@ def url(self):
return f"{env.BK_SAAS_HOST}/my-todos?id={self.ticket.id}"

def set_status(self, username, status):
self.status = status
if self.status == status:
return

self.status = status
if status in [TodoStatus.DONE_SUCCESS, TodoStatus.DONE_FAILED]:
self.done_by = username
self.done_at = timezone.now()
Expand Down

0 comments on commit fcb96dd

Please sign in to comment.