uncloud-mravi/uncloud/uncloud_auth/views.py
2020-03-18 14:36:40 +01:00

16 lines
586 B
Python

from rest_framework import viewsets, permissions, status
from .serializers import *
class UserViewSet(viewsets.ReadOnlyModelViewSet):
serializer_class = UserSerializer
permission_classes = [permissions.IsAuthenticated]
def get_queryset(self):
if self.request.user.is_superuser:
obj = get_user_model().objects.all()
else:
# This is a bit stupid: we have a user, we create a queryset by
# matching on the username.
obj = get_user_model().objects.filter(username=self.request.user.username)
return obj