|
@@ -2,11 +2,11 @@ from django.contrib.auth.models import User, Group
|
|
|
from rest_framework import viewsets
|
|
|
from .serializers import UserSerializer, GroupSerializer
|
|
|
from rest_framework.views import APIView
|
|
|
-from .permission import HasAPIKey, HAsKeyPermissionn
|
|
|
+from .permission import HasAPIKey
|
|
|
from rest_framework.permissions import IsAuthenticated
|
|
|
from .models import APIKey
|
|
|
from rest_framework.decorators import api_view, permission_classes
|
|
|
-
|
|
|
+from rest_framework.response import Response
|
|
|
|
|
|
|
|
|
class UserViewSet(viewsets.ModelViewSet):
|
|
@@ -18,7 +18,7 @@ class UserViewSet(viewsets.ModelViewSet):
|
|
|
keys = APIKey.objects.all()
|
|
|
for i in keys:
|
|
|
print()
|
|
|
- permission_classes = [HasAPIKey | IsAuthenticated | HAsKeyPermissionn]
|
|
|
+ permission_classes = [HasAPIKey | IsAuthenticated]
|
|
|
|
|
|
|
|
|
class GroupViewSet(viewsets.ModelViewSet):
|
|
@@ -27,4 +27,22 @@ class GroupViewSet(viewsets.ModelViewSet):
|
|
|
"""
|
|
|
queryset = Group.objects.all()
|
|
|
serializer_class = GroupSerializer
|
|
|
- permission_classes = [HasAPIKey | IsAuthenticated]
|
|
|
+ permission_classes = [HasAPIKey | IsAuthenticated]
|
|
|
+
|
|
|
+
|
|
|
+class SnippetUSER(APIView):
|
|
|
+ permission_classes = []
|
|
|
+ print(permission_classes)
|
|
|
+ def get(self, request, format=None):
|
|
|
+ snippets = User.objects.all()
|
|
|
+ serializer = UserSerializer(snippets, many=True, context={'request': request})
|
|
|
+ try:
|
|
|
+ header_key = request.META["HTTP_X_API_KEY"]
|
|
|
+ except:
|
|
|
+ header_key = request.META["HTTP_X_CSRFTOKEN"]
|
|
|
+ db_key = APIKey.objects.get_from_key(header_key)
|
|
|
+ #print(db_key.permission.all())
|
|
|
+ print(db_key.has_permission("user"))
|
|
|
+ print(db_key.has_permission_method("user", "add"))
|
|
|
+ #print(header_key.permission)
|
|
|
+ return Response(serializer.data)
|