fix: 放行按钮权限接口
parent
7ee4c3a672
commit
acfe3e338d
|
@ -23,7 +23,7 @@ class MenuButtonSerializer(CustomModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = MenuButton
|
||||
fields = ['id', 'name', 'value', 'api', 'method', 'menu']
|
||||
fields = ["id", "name", "value", "api", "method", "menu"]
|
||||
read_only_fields = ["id"]
|
||||
|
||||
|
||||
|
@ -34,7 +34,7 @@ class MenuButtonInitSerializer(CustomModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = MenuButton
|
||||
fields = ['id', 'name', 'value', 'api', 'method', 'menu']
|
||||
fields = ["id", "name", "value", "api", "method", "menu"]
|
||||
read_only_fields = ["id"]
|
||||
|
||||
|
||||
|
@ -58,21 +58,26 @@ class MenuButtonViewSet(CustomModelViewSet):
|
|||
retrieve:单例
|
||||
destroy:删除
|
||||
"""
|
||||
|
||||
queryset = MenuButton.objects.all()
|
||||
serializer_class = MenuButtonSerializer
|
||||
create_serializer_class = MenuButtonCreateUpdateSerializer
|
||||
update_serializer_class = MenuButtonCreateUpdateSerializer
|
||||
extra_filter_backends = []
|
||||
|
||||
@action(methods=['get'], detail=False)
|
||||
def get_btn_permission(self,request):
|
||||
@action(methods=["GET"], detail=False, permission_classes=[])
|
||||
def get_btn_permission(self, request):
|
||||
"""
|
||||
获取当前用户的按钮权限
|
||||
"""
|
||||
user = request.user
|
||||
if not user.is_superuser:
|
||||
menuIds = user.role.values_list('menu__id', flat=True)
|
||||
menuIds = user.role.values_list("menu__id", flat=True)
|
||||
else:
|
||||
menuIds = Menu.objects.filter(status=1)
|
||||
queryset = MenuButton.objects.filter(menu__in=menuIds).annotate(permission=Concat('menu__web_path',Value(':'),'value',output_field=CharField())).values_list('permission',flat=True)
|
||||
queryset = (
|
||||
MenuButton.objects.filter(menu__in=menuIds)
|
||||
.annotate(permission=Concat("menu__web_path", Value(":"), "value", output_field=CharField()))
|
||||
.values_list("permission", flat=True)
|
||||
)
|
||||
return DetailResponse(data=queryset)
|
||||
|
|
Loading…
Reference in New Issue