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"],