From 6fe407b1b7d306fcffec48247403aa04d8dc9789 Mon Sep 17 00:00:00 2001 From: iSecloud <869820505@qq.com> Date: Tue, 24 Sep 2024 19:39:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(backend):=20=E8=A1=A5=E5=85=85sqlserver?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=9D=83=E9=99=90=E5=AD=97=E6=AE=B5=20#7121?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sqlserver/resources/sqlserver_ha/views.py | 10 ++------ .../resources/sqlserver_single/views.py | 10 ++------ .../db_services/sqlserver/resources/views.py | 19 +++++++++++++- dbm-ui/backend/tests/ticket/server_base.py | 25 ++++++++++--------- .../tests/ticket/test_sqlserver_flow.py | 8 ++++++ 5 files changed, 43 insertions(+), 29 deletions(-) diff --git a/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_ha/views.py b/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_ha/views.py index 1260fe52d2..5ebd9c59e0 100644 --- a/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_ha/views.py +++ b/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_ha/views.py @@ -12,13 +12,11 @@ from rest_framework import status from backend.bk_web.swagger import common_swagger_auto_schema -from backend.configuration.constants import DBType from backend.db_services.dbbase.resources import serializers from backend.db_services.sqlserver.resources import constants from backend.db_services.sqlserver.resources.sqlserver_ha import yasg_slz from backend.db_services.sqlserver.resources.sqlserver_ha.query import ListRetrieveResource -from backend.db_services.sqlserver.resources.views import BaseSQLServerViewset -from backend.iam_app.dataclass.actions import ActionEnum +from backend.db_services.sqlserver.resources.views import BaseSQLServerViewSet @method_decorator( @@ -73,12 +71,8 @@ tags=[constants.RESOURCE_TAG], ), ) -class SQLServerHaViewSet(BaseSQLServerViewset): +class SQLServerHaViewSet(BaseSQLServerViewSet): """SQLServer Ha 架构资源""" query_class = ListRetrieveResource query_serializer_class = serializers.ListSQLServerResourceSLZ - db_type = DBType.Sqlserver - - list_perm_actions = [ActionEnum.SQLSERVER_VIEW] - list_instance_perm_actions = [ActionEnum.SQLSERVER_VIEW] diff --git a/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_single/views.py b/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_single/views.py index 795da1dc70..20642fbeb5 100644 --- a/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_single/views.py +++ b/dbm-ui/backend/db_services/sqlserver/resources/sqlserver_single/views.py @@ -12,13 +12,11 @@ from rest_framework import status from backend.bk_web.swagger import common_swagger_auto_schema -from backend.configuration.constants import DBType from backend.db_services.dbbase.resources import serializers from backend.db_services.sqlserver.resources import constants from backend.db_services.sqlserver.resources.sqlserver_single import yasg_slz from backend.db_services.sqlserver.resources.sqlserver_single.query import ListRetrieveResource -from backend.db_services.sqlserver.resources.views import BaseSQLServerViewset -from backend.iam_app.dataclass.actions import ActionEnum +from backend.db_services.sqlserver.resources.views import BaseSQLServerViewSet @method_decorator( @@ -73,12 +71,8 @@ tags=[constants.RESOURCE_TAG], ), ) -class SQLServerSingleViewSet(BaseSQLServerViewset): +class SQLServerSingleViewSet(BaseSQLServerViewSet): """SQLServer Single 架构资源""" query_class = ListRetrieveResource query_serializer_class = serializers.ListSQLServerResourceSLZ - db_type = DBType.Sqlserver - - list_perm_actions = [ActionEnum.SQLSERVER_VIEW] - list_instance_perm_actions = [ActionEnum.SQLSERVER_VIEW] diff --git a/dbm-ui/backend/db_services/sqlserver/resources/views.py b/dbm-ui/backend/db_services/sqlserver/resources/views.py index e5936c5e9a..02a84b56d6 100644 --- a/dbm-ui/backend/db_services/sqlserver/resources/views.py +++ b/dbm-ui/backend/db_services/sqlserver/resources/views.py @@ -18,6 +18,7 @@ from backend.bk_web.swagger import common_swagger_auto_schema from backend.bk_web.viewsets import SystemViewSet +from backend.configuration.constants import DBType from backend.db_meta.models.cluster import Cluster from backend.db_meta.models.db_module import DBModule from backend.db_meta.models.storage_set_dtl import SqlserverClusterSyncMode @@ -27,6 +28,8 @@ from backend.db_services.dbbase.resources.views import BaseListResourceViewSet from backend.db_services.dbbase.resources.yasg_slz import ResourceTreeSLZ from backend.db_services.sqlserver.resources import constants +from backend.iam_app.dataclass import ResourceEnum +from backend.iam_app.dataclass.actions import ActionEnum from backend.iam_app.handlers.drf_perm.base import DBManagePermission from backend.iam_app.handlers.permission import Permission @@ -89,7 +92,21 @@ def get_resource_tree(self, request, bk_biz_id): return Response(tree) -class BaseSQLServerViewset(viewsets.ResourceViewSet): +class BaseSQLServerViewSet(viewsets.ResourceViewSet): + + db_type = DBType.Sqlserver + + list_perm_actions = [ActionEnum.SQLSERVER_VIEW] + list_instance_perm_actions = [ActionEnum.SQLSERVER_VIEW] + list_external_perm_actions = [ActionEnum.ACCESS_ENTRY_EDIT] + + @staticmethod + def _external_perm_param_field(kwargs): + return { + ResourceEnum.BUSINESS.id: kwargs["bk_biz_id"], + ResourceEnum.DBTYPE.id: kwargs["view_class"].db_type.value, + } + @Permission.decorator_permission_field( id_field=lambda d: d["id"], data_field=lambda d: d["results"], diff --git a/dbm-ui/backend/tests/ticket/server_base.py b/dbm-ui/backend/tests/ticket/server_base.py index 6b7f321dec..3162867b9b 100644 --- a/dbm-ui/backend/tests/ticket/server_base.py +++ b/dbm-ui/backend/tests/ticket/server_base.py @@ -19,22 +19,23 @@ class TestFlowBase: 测试流程的基类。 """ + patches = [ + patch.object(TicketViewSet, "permission_classes"), + patch.object(InnerFlow, "_run"), + patch.object(InnerFlow, "status", new_callable=PropertyMock), + patch.object(PauseFlow, "status", new_callable=PropertyMock), + patch.object(TicketViewSet, "get_permissions"), + patch("backend.ticket.flow_manager.itsm.ItsmApi", ItsmApiMock()), + patch("backend.db_services.cmdb.biz.CCApi", CCApiMock()), + patch("backend.components.cmsi.handler.CmsiHandler.send_msg", lambda msg: "有一条待办事项需要您处理"), + patch("backend.db_services.cmdb.biz.Permission", PermissionMock), + ] + def apply_patches(self): """ 应用测试所需的所有patches。 """ - patches = [ - patch.object(TicketViewSet, "permission_classes"), - patch.object(InnerFlow, "_run"), - patch.object(InnerFlow, "status", new_callable=PropertyMock), - patch.object(PauseFlow, "status", new_callable=PropertyMock), - patch.object(TicketViewSet, "get_permissions"), - patch("backend.ticket.flow_manager.itsm.ItsmApi", ItsmApiMock()), - patch("backend.db_services.cmdb.biz.CCApi", CCApiMock()), - patch("backend.components.cmsi.handler.CmsiHandler.send_msg", lambda msg: "有一条待办事项需要您处理"), - patch("backend.db_services.cmdb.biz.Permission", PermissionMock), - ] - self.mocks = [patcher.start() for patcher in patches] + self.mocks = [patcher.start() for patcher in self.patches] def setup(self): """ diff --git a/dbm-ui/backend/tests/ticket/test_sqlserver_flow.py b/dbm-ui/backend/tests/ticket/test_sqlserver_flow.py index f3a2a2c984..6d436d7c13 100644 --- a/dbm-ui/backend/tests/ticket/test_sqlserver_flow.py +++ b/dbm-ui/backend/tests/ticket/test_sqlserver_flow.py @@ -78,6 +78,14 @@ class TestSqlServerApplyFlow(TestFlowBase, TestCase): SQLSERVER APPLY测试类。 """ + patches = [ + *TestFlowBase.patches, + patch( + "backend.ticket.builders.common.base.CommonValidate.validate_sqlserver_table_selector", + lambda *args, **kwargs: (True, ""), + ), + ] + # SQLSERVER single部署: start --> itsm --> PAUSE --> RESOURC --> INNER_FLOW --> end def test_sqlserver_single_apply_flow(self): self.flow_test(client, SQLSERVER_SINGLE_APPLY_TICKET_DATA)