Default authentication on endpoints
Ik was er namelijk alweer eentje vergeten dus heh.
This commit is contained in:
@@ -91,6 +91,9 @@ REST_FRAMEWORK = {
|
|||||||
'mozilla_django_oidc.contrib.drf.OIDCAuthentication',
|
'mozilla_django_oidc.contrib.drf.OIDCAuthentication',
|
||||||
'rest_framework.authentication.SessionAuthentication',
|
'rest_framework.authentication.SessionAuthentication',
|
||||||
],
|
],
|
||||||
|
'DEFAULT_PERMISSION_CLASSES': [
|
||||||
|
'rest_framework.permissions.IsAuthenticated',
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
OIDC_RP_CLIENT_ID = os.getenv('OIDC_RP_CLIENT_ID')
|
OIDC_RP_CLIENT_ID = os.getenv('OIDC_RP_CLIENT_ID')
|
||||||
|
|||||||
@@ -1,15 +1,10 @@
|
|||||||
from itertools import permutations
|
from itertools import permutations
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.authentication import SessionAuthentication
|
|
||||||
from rest_framework.permissions import IsAuthenticated
|
|
||||||
from playlist.models import Artist
|
from playlist.models import Artist
|
||||||
from playlist.serializers import ArtistSerializer
|
from playlist.serializers import ArtistSerializer
|
||||||
|
|
||||||
class ArtistListView(APIView):
|
class ArtistListView(APIView):
|
||||||
authentication_classes = [SessionAuthentication]
|
|
||||||
permission_classes = [IsAuthenticated]
|
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
artists = Artist.objects.all()
|
artists = Artist.objects.all()
|
||||||
serializer = ArtistSerializer(artists, many=True, context={'request': request})
|
serializer = ArtistSerializer(artists, many=True, context={'request': request})
|
||||||
|
|||||||
@@ -2,33 +2,22 @@ from pickle import BUILD
|
|||||||
from playlist import serializers
|
from playlist import serializers
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.authentication import SessionAuthentication
|
|
||||||
from rest_framework.permissions import IsAuthenticated
|
|
||||||
from playlist.serializers import ProfileSerializer, BackgroundSerializer
|
from playlist.serializers import ProfileSerializer, BackgroundSerializer
|
||||||
from playlist.models import Profile, Background
|
from playlist.models import Profile, Background
|
||||||
|
|
||||||
class ProfileDetailView(APIView):
|
class ProfileDetailView(APIView):
|
||||||
authentication_classes = [SessionAuthentication]
|
|
||||||
permission_classes = [IsAuthenticated]
|
|
||||||
|
|
||||||
def get(self, request, id):
|
def get(self, request, id):
|
||||||
profile = Profile.objects.get(pk=id)
|
profile = Profile.objects.get(pk=id)
|
||||||
serializer = ProfileSerializer(profile)
|
serializer = ProfileSerializer(profile)
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
class BackgroundListView(APIView):
|
class BackgroundListView(APIView):
|
||||||
authentication_classes = [SessionAuthentication]
|
|
||||||
permission_classes = [IsAuthenticated]
|
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
backgrounds = Background.objects.all()
|
backgrounds = Background.objects.all()
|
||||||
serializer = BackgroundSerializer(backgrounds, many=True)
|
serializer = BackgroundSerializer(backgrounds, many=True)
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
class BackgroundDetailView(APIView):
|
class BackgroundDetailView(APIView):
|
||||||
authentication_classes = [SessionAuthentication]
|
|
||||||
permission_classes = [IsAuthenticated]
|
|
||||||
|
|
||||||
def get(self, request, id):
|
def get(self, request, id):
|
||||||
background = Background.objects.get(pk=id)
|
background = Background.objects.get(pk=id)
|
||||||
serializer = BackgroundSerializer(background)
|
serializer = BackgroundSerializer(background)
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
from rest_framework.decorators import api_view
|
from rest_framework.decorators import api_view, permission_classes
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.reverse import reverse
|
from rest_framework.reverse import reverse
|
||||||
|
|
||||||
|
|
||||||
@api_view(['GET'])
|
@api_view(['GET'])
|
||||||
|
@permission_classes([])
|
||||||
def api_root(request, format=None):
|
def api_root(request, format=None):
|
||||||
return Response({
|
return Response({
|
||||||
'tracks': reverse('api-tracks', request=request, format=format),
|
'tracks': reverse('api-tracks', request=request, format=format),
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.authentication import SessionAuthentication
|
|
||||||
from rest_framework.permissions import IsAuthenticated
|
|
||||||
from playlist.models import Track, Profile
|
from playlist.models import Track, Profile
|
||||||
from playlist.serializers import TrackSerializer
|
from playlist.serializers import TrackSerializer
|
||||||
from playlist.spotify import spt
|
from playlist.spotify import spt
|
||||||
from playlist.tasks import get_banter, get_and_dither_image
|
from playlist.tasks import get_banter, get_and_dither_image
|
||||||
|
|
||||||
class TrackListView(APIView):
|
class TrackListView(APIView):
|
||||||
authentication_classes = [SessionAuthentication]
|
|
||||||
permission_classes = [IsAuthenticated]
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
tracks = Track.objects.all()
|
tracks = Track.objects.all()
|
||||||
serializer = TrackSerializer(tracks, many=True, context={'request': request})
|
serializer = TrackSerializer(tracks, many=True, context={'request': request})
|
||||||
@@ -32,8 +28,6 @@ class TrackListView(APIView):
|
|||||||
return Response({'error': 'Only superusers can delete all tracks'}, status=403)
|
return Response({'error': 'Only superusers can delete all tracks'}, status=403)
|
||||||
|
|
||||||
class TrackDetailView(APIView):
|
class TrackDetailView(APIView):
|
||||||
authentication_classes = [SessionAuthentication]
|
|
||||||
permission_classes = [IsAuthenticated]
|
|
||||||
def get(self, request, id):
|
def get(self, request, id):
|
||||||
track = Track.objects.get(pk=id)
|
track = Track.objects.get(pk=id)
|
||||||
serializer = TrackSerializer(track, context={'request': request})
|
serializer = TrackSerializer(track, context={'request': request})
|
||||||
|
|||||||
@@ -2,20 +2,14 @@ from rest_framework.views import APIView
|
|||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from playlist.serializers import UserSerializer
|
from playlist.serializers import UserSerializer
|
||||||
from rest_framework.authentication import SessionAuthentication
|
|
||||||
from rest_framework.permissions import IsAuthenticated
|
|
||||||
|
|
||||||
class UserListView(APIView):
|
class UserListView(APIView):
|
||||||
authentication_classes = [SessionAuthentication]
|
|
||||||
permission_classes = [IsAuthenticated]
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
users = User.objects.all()
|
users = User.objects.all()
|
||||||
serializer = UserSerializer(users, many=True, context={'request': request})
|
serializer = UserSerializer(users, many=True, context={'request': request})
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
class UserDetailView(APIView):
|
class UserDetailView(APIView):
|
||||||
authentication_classes = [SessionAuthentication]
|
|
||||||
permission_classes = [IsAuthenticated]
|
|
||||||
def get(self, request, id):
|
def get(self, request, id):
|
||||||
user = User.objects.get(pk=id)
|
user = User.objects.get(pk=id)
|
||||||
serializer = UserSerializer(user, context={'request': request})
|
serializer = UserSerializer(user, context={'request': request})
|
||||||
|
|||||||
Reference in New Issue
Block a user