Skip to content

Commit

Permalink
fix(backend): 补充sqlserver列表权限字段 #7121
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud committed Sep 24, 2024
1 parent 05ebc1d commit 5ceb3d8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 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

0 comments on commit 5ceb3d8

Please sign in to comment.