Skip to content

Commit

Permalink
feat(backend): 单据协助设置开发 TencentBlueKing#8036
Browse files Browse the repository at this point in the history
# Reviewed, transaction id: 24154
  • Loading branch information
ygcyao committed Nov 19, 2024
1 parent e98cd78 commit a3a67bf
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dbm-ui/backend/configuration/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ class BizSettingsEnum(str, StructuredEnum):
# TODO: 后续待删除
SKIP_GRAMMAR_CHECK = EnumField("SKIP_GRAMMAR_CHECK", _("是否跳过语义检查"))
SQL_IMPORT_FORCE_ITSM = EnumField("SQL_IMPORT_FORCE_ITSM", _("是否变更SQL强制需要审批流"))
BIZ_ASSISTANCE_VARS = EnumField("BIZ_ASSISTANCE_VARS", _("业务协助人员变量"))
BIZ_ASSISTANCE_SWITCH = EnumField("BIZ_ASSISTANCE_SWITCH", _("业务协助开关"))


DEFAULT_DB_ADMINISTRATORS = ["admin"]
Expand Down
12 changes: 12 additions & 0 deletions dbm-ui/backend/ticket/models/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from backend import env
from backend.bk_web.constants import LEN_MIDDLE, LEN_SHORT
from backend.bk_web.models import AuditedModel
from backend.configuration.constants import BizSettingsEnum
from backend.configuration.models import BizSettings
from backend.ticket.constants import FlowMsgStatus, FlowMsgType, TicketFlowStatus, TodoStatus, TodoType
from backend.ticket.tasks.ticket_tasks import send_msg_for_flow

Expand All @@ -28,6 +30,16 @@ def exist_unfinished(self):
return self.filter(status__in=[TodoStatus.TODO, TodoStatus.RUNNING]).exists()

def create(self, **kwargs):
# 获取业务协助人列表
biz_facilitators: list = (
BizSettings.get_setting_value(
bk_biz_id=kwargs["ticket"].bk_biz_id, key=BizSettingsEnum.BIZ_ASSISTANCE_VARS
)
or []
)
operators = kwargs.get("operators", [])
# 合并两个列表并去重
kwargs["operators"] = list(set(operators + biz_facilitators))
todo = super().create(**kwargs)
send_msg_for_flow.apply_async(
kwargs={
Expand Down
9 changes: 9 additions & 0 deletions dbm-ui/backend/ticket/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,12 @@ def validate(self, attrs):
if todo_id not in existing_todo_ids:
raise serializers.ValidationError(_("待办id{}不存在".format(attrs["todo_id"])))
return attrs


class BizFacilitatorSerializer(serializers.Serializer):
bk_biz_id = serializers.IntegerField(help_text=_("业务ID"), required=False, default=PLAT_BIZ_ID)


class WriteBizFacilitatorSerializer(BizFacilitatorSerializer):
assistance_flag = serializers.BooleanField(help_text=_("单据协助开关"))
facilitators = serializers.CharField(help_text=_("默认协助人 (通过,分割)"), default="")
38 changes: 37 additions & 1 deletion dbm-ui/backend/ticket/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
from backend import env
from backend.bk_web import viewsets
from backend.bk_web.swagger import PaginatedResponseSwaggerAutoSchema, common_swagger_auto_schema
from backend.configuration.models import DBAdministrator
from backend.configuration.constants import BizSettingsEnum
from backend.configuration.models import BizSettings, DBAdministrator
from backend.db_services.ipchooser.query.resource import ResourceQueryHelper
from backend.iam_app.dataclass import ResourceEnum
from backend.iam_app.dataclass.actions import ActionEnum
Expand Down Expand Up @@ -54,6 +55,7 @@
from backend.ticket.serializers import (
BatchApprovalSerializer,
BatchTodoOperateSerializer,
BizFacilitatorSerializer,
ClusterModifyOpSerializer,
CountTicketSLZ,
CreateTicketFlowConfigSerializer,
Expand All @@ -75,6 +77,7 @@
TodoOperateSerializer,
TodoSerializer,
UpdateTicketFlowConfigSerializer,
WriteBizFacilitatorSerializer,
)
from backend.ticket.todos import TodoActorFactory
from backend.utils.batch_request import request_multi_thread
Expand Down Expand Up @@ -656,3 +659,36 @@ def batch_process_todo(self, request, *args, **kwargs):

# 使用 TodoSerializer 序列化响应数据
return Response(TodoSerializer(results, many=True).data)

@swagger_auto_schema(
operation_summary=_("获取业务协助设置"),
query_serializer=BizFacilitatorSerializer(),
tags=[TICKET_TAG],
)
@action(methods=["GET"], detail=False, serializer_class=BizFacilitatorSerializer)
def get_biz_facilitators(self, request, *args, **kwargs):
bk_biz_id = self.params_validate(self.get_serializer_class())["bk_biz_id"]
assistance_flag = BizSettings.get_setting_value(bk_biz_id, BizSettingsEnum.BIZ_ASSISTANCE_SWITCH) or False
assistance_facilitators = BizSettings.get_setting_value(bk_biz_id, BizSettingsEnum.BIZ_ASSISTANCE_VARS) or []
results = {"assistance_flag": assistance_flag, "assistance_facilitators": assistance_facilitators}
return Response(results)

@common_swagger_auto_schema(
operation_summary=_("更新业务协助设置"),
request_body=WriteBizFacilitatorSerializer(),
tags=[TICKET_TAG],
)
@action(methods=["POST"], detail=False, serializer_class=WriteBizFacilitatorSerializer)
def biz_facilitators(self, request, *args, **kwargs):
"""更新业务协助设置。"""
validated_data = self.params_validate(self.get_serializer_class())
facilitators = validated_data["facilitators"].split(",")
assistance_flag = validated_data["assistance_flag"]
bk_biz_id = validated_data["bk_biz_id"]
BizSettings.insert_setting_value(
bk_biz_id=bk_biz_id, key=BizSettingsEnum.BIZ_ASSISTANCE_VARS, value_type="dict", value=facilitators
)
BizSettings.insert_setting_value(
bk_biz_id=bk_biz_id, key=BizSettingsEnum.BIZ_ASSISTANCE_SWITCH, value_type="bool", value=assistance_flag
)
return Response()

0 comments on commit a3a67bf

Please sign in to comment.