uncloud/uncloud_net/views.py

34 lines
955 B
Python
Raw Normal View History

from django.shortcuts import render
from rest_framework import viewsets, permissions
from .models import *
from .serializers import *
2020-04-06 20:30:01 +00:00
class VPNPoolViewSet(viewsets.ModelViewSet):
serializer_class = VPNPoolSerializer
permission_classes = [permissions.IsAdminUser]
queryset = VPNPool.objects.all()
class VPNNetworkReservationViewSet(viewsets.ModelViewSet):
serializer_class = VPNNetworkReservationSerializer
permission_classes = [permissions.IsAdminUser]
queryset = VPNNetworkReservation.objects.all()
2020-04-06 20:30:01 +00:00
class VPNNetworkViewSet(viewsets.ModelViewSet):
serializer_class = VPNNetworkSerializer
2020-05-07 18:22:42 +00:00
# permission_classes = [permissions.IsAdminUser]
permission_classes = [permissions.IsAuthenticated]
def get_queryset(self):
if self.request.user.is_superuser:
2020-04-06 20:30:01 +00:00
obj = VPNNetwork.objects.all()
else:
2020-04-06 20:30:01 +00:00
obj = VPNNetwork.objects.filter(owner=self.request.user)
return obj