jumpserver/apps/assets/api/category.py

35 lines
1.1 KiB
Python

from rest_framework.mixins import ListModelMixin
from rest_framework.decorators import action
from rest_framework.response import Response
from common.api import JMSGenericViewSet
from assets.serializers import CategorySerializer, TypeSerializer
from assets.const import AllTypes
__all__ = ['CategoryViewSet']
class CategoryViewSet(ListModelMixin, JMSGenericViewSet):
serializer_classes = {
'default': CategorySerializer,
'types': TypeSerializer
}
permission_classes = ()
def get_queryset(self):
return AllTypes.categories()
@action(methods=['get'], detail=False)
def types(self, request, *args, **kwargs):
queryset = AllTypes.types()
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)
@action(methods=['get'], detail=False)
def constraints(self, request, *args, **kwargs):
category = request.query_params.get('category')
tp = request.query_params.get('type')
constraints = AllTypes.get_constraints(category, tp)
return Response(constraints)