功能变化: 优化授权管理

pull/84/head
猿小天 2022-12-29 14:44:39 +08:00
parent 43e21c9c64
commit 8158d2b981
2 changed files with 12 additions and 6 deletions

View File

@ -18,7 +18,7 @@ class MenuButtonSerializer(CustomModelSerializer):
class Meta:
model = MenuButton
fields = "__all__"
fields = ['id','name','value','api','method']
read_only_fields = ["id"]

View File

@ -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获取该角色用于的菜单"""
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()
# queryset = Menu.objects.filter(status=1).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):