Skip to content

Commit

Permalink
fix(backend): 补充sqlserver列表权限字段 TencentBlueKing#7121
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud committed Sep 24, 2024
1 parent 05ebc1d commit dbf9a54
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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]
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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]
19 changes: 18 additions & 1 deletion dbm-ui/backend/db_services/sqlserver/resources/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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"],
Expand Down
25 changes: 13 additions & 12 deletions dbm-ui/backend/tests/ticket/server_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
8 changes: 8 additions & 0 deletions dbm-ui/backend/tests/ticket/test_sqlserver_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dbf9a54

Please sign in to comment.