From 8158d2b981d917be6cd5a89b20cd82e7a53e6ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8C=BF=E5=B0=8F=E5=A4=A9?= <1638245306@qq.com> Date: Thu, 29 Dec 2022 14:44:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=8F=98=E5=8C=96:=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8E=88=E6=9D=83=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/dvadmin/system/views/menu_button.py | 2 +- backend/dvadmin/system/views/role.py | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/backend/dvadmin/system/views/menu_button.py b/backend/dvadmin/system/views/menu_button.py index 4c4d2eb..f32bcb4 100644 --- a/backend/dvadmin/system/views/menu_button.py +++ b/backend/dvadmin/system/views/menu_button.py @@ -18,7 +18,7 @@ class MenuButtonSerializer(CustomModelSerializer): class Meta: model = MenuButton - fields = "__all__" + fields = ['id','name','value','api','method'] read_only_fields = ["id"] diff --git a/backend/dvadmin/system/views/role.py b/backend/dvadmin/system/views/role.py index e1acf87..be9a1a2 100644 --- a/backend/dvadmin/system/views/role.py +++ b/backend/dvadmin/system/views/role.py @@ -81,7 +81,7 @@ class MenuPermissonSerializer(CustomModelSerializer): class Meta: model = Menu - fields = '__all__' + fields = ['id','parent','name','menuPermission'] class RoleViewSet(CustomModelViewSet): @@ -102,12 +102,18 @@ class RoleViewSet(CustomModelViewSet): @action(methods=['GET'], detail=True, permission_classes=[IsAuthenticated]) def roleId_get_menu(self, request,pk): """通过角色id获取该角色用于的菜单""" - instance = Role.objects.filter(id=pk).first() - queryset = instance.menu.all() - # queryset = Menu.objects.filter(status=1).all() + is_superuser = request.user.is_superuser + is_admin = Role.objects.filter(id=pk, admin=True).first() + if is_superuser or is_admin: + queryset = Menu.objects.filter(status=1).all() + else: + instance = Role.objects.filter(id=pk).first() + queryset = instance.menu.all() + print(111, queryset) queryset = self.filter_queryset(queryset) serializer = MenuPermissonSerializer(queryset, many=True) - return SuccessResponse(data=serializer.data) + print(114, serializer.data) + return DetailResponse(data=serializer.data) @action(methods=['GET'], detail=False, permission_classes=[IsAuthenticated]) def data_scope(self,request):