From a3a67bf67c4105bb6bb9d95c2f9806b866dae288 Mon Sep 17 00:00:00 2001 From: ycggyao Date: Tue, 19 Nov 2024 14:25:48 +0800 Subject: [PATCH] =?UTF-8?q?feat(backend):=20=E5=8D=95=E6=8D=AE=E5=8D=8F?= =?UTF-8?q?=E5=8A=A9=E8=AE=BE=E7=BD=AE=E5=BC=80=E5=8F=91=20#8036=20#=20Rev?= =?UTF-8?q?iewed,=20transaction=20id:=2024154?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbm-ui/backend/configuration/constants.py | 2 ++ dbm-ui/backend/ticket/models/todo.py | 12 +++++++ dbm-ui/backend/ticket/serializers.py | 9 ++++++ dbm-ui/backend/ticket/views.py | 38 ++++++++++++++++++++++- 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/dbm-ui/backend/configuration/constants.py b/dbm-ui/backend/configuration/constants.py index 34e4424426..1495cf9afe 100644 --- a/dbm-ui/backend/configuration/constants.py +++ b/dbm-ui/backend/configuration/constants.py @@ -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"] diff --git a/dbm-ui/backend/ticket/models/todo.py b/dbm-ui/backend/ticket/models/todo.py index 77478bd41d..1e6005dc85 100644 --- a/dbm-ui/backend/ticket/models/todo.py +++ b/dbm-ui/backend/ticket/models/todo.py @@ -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 @@ -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={ diff --git a/dbm-ui/backend/ticket/serializers.py b/dbm-ui/backend/ticket/serializers.py index 70a9686266..8aca673c26 100644 --- a/dbm-ui/backend/ticket/serializers.py +++ b/dbm-ui/backend/ticket/serializers.py @@ -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="") diff --git a/dbm-ui/backend/ticket/views.py b/dbm-ui/backend/ticket/views.py index 9b66b6e7a4..dbadca5c16 100644 --- a/dbm-ui/backend/ticket/views.py +++ b/dbm-ui/backend/ticket/views.py @@ -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 @@ -54,6 +55,7 @@ from backend.ticket.serializers import ( BatchApprovalSerializer, BatchTodoOperateSerializer, + BizFacilitatorSerializer, ClusterModifyOpSerializer, CountTicketSLZ, CreateTicketFlowConfigSerializer, @@ -75,6 +77,7 @@ TodoOperateSerializer, TodoSerializer, UpdateTicketFlowConfigSerializer, + WriteBizFacilitatorSerializer, ) from backend.ticket.todos import TodoActorFactory from backend.utils.batch_request import request_multi_thread @@ -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()