功能变化: 优化授权管理
parent
43e21c9c64
commit
8158d2b981
|
@ -18,7 +18,7 @@ class MenuButtonSerializer(CustomModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = MenuButton
|
model = MenuButton
|
||||||
fields = "__all__"
|
fields = ['id','name','value','api','method']
|
||||||
read_only_fields = ["id"]
|
read_only_fields = ["id"]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ class MenuPermissonSerializer(CustomModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Menu
|
model = Menu
|
||||||
fields = '__all__'
|
fields = ['id','parent','name','menuPermission']
|
||||||
|
|
||||||
|
|
||||||
class RoleViewSet(CustomModelViewSet):
|
class RoleViewSet(CustomModelViewSet):
|
||||||
|
@ -102,12 +102,18 @@ class RoleViewSet(CustomModelViewSet):
|
||||||
@action(methods=['GET'], detail=True, permission_classes=[IsAuthenticated])
|
@action(methods=['GET'], detail=True, permission_classes=[IsAuthenticated])
|
||||||
def roleId_get_menu(self, request,pk):
|
def roleId_get_menu(self, request,pk):
|
||||||
"""通过角色id获取该角色用于的菜单"""
|
"""通过角色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()
|
instance = Role.objects.filter(id=pk).first()
|
||||||
queryset = instance.menu.all()
|
queryset = instance.menu.all()
|
||||||
# queryset = Menu.objects.filter(status=1).all()
|
print(111, queryset)
|
||||||
queryset = self.filter_queryset(queryset)
|
queryset = self.filter_queryset(queryset)
|
||||||
serializer = MenuPermissonSerializer(queryset, many=True)
|
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])
|
@action(methods=['GET'], detail=False, permission_classes=[IsAuthenticated])
|
||||||
def data_scope(self,request):
|
def data_scope(self,request):
|
||||||
|
|
Loading…
Reference in New Issue