Created
August 27, 2020 01:03
-
-
Save BrockHerion/fe03532cb3ac305d7dfe33edae4605e2 to your computer and use it in GitHub Desktop.
All Users View
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserListView(APIView): | |
serializer_class = UserListSerializer | |
permission_classes = (IsAuthenticated,) | |
def get(self, request): | |
user = request.user | |
if user.role != 1: | |
response = { | |
'success': False, | |
'status_code': status.HTTP_403_FORBIDDEN, | |
'message': 'You are not authorized to perform this action' | |
} | |
return Response(response, status.HTTP_403_FORBIDDEN) | |
else: | |
users = AuthUser.objects.all() | |
serializer = self.serializer_class(users, many=True) | |
response = { | |
'success': True, | |
'status_code': status.HTTP_200_OK, | |
'message': 'Successfully fetched users', | |
'users': serializer.data | |
} | |
return Response(response, status=status.HTTP_200_OK) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment