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',
|
||||
'rest_framework.authentication.SessionAuthentication',
|
||||
],
|
||||
'DEFAULT_PERMISSION_CLASSES': [
|
||||
'rest_framework.permissions.IsAuthenticated',
|
||||
]
|
||||
}
|
||||
|
||||
OIDC_RP_CLIENT_ID = os.getenv('OIDC_RP_CLIENT_ID')
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
from itertools import permutations
|
||||
from rest_framework.views import APIView
|
||||
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.serializers import ArtistSerializer
|
||||
|
||||
class ArtistListView(APIView):
|
||||
authentication_classes = [SessionAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get(self, request):
|
||||
artists = Artist.objects.all()
|
||||
serializer = ArtistSerializer(artists, many=True, context={'request': request})
|
||||
|
||||
@@ -2,33 +2,22 @@ from pickle import BUILD
|
||||
from playlist import serializers
|
||||
from rest_framework.views import APIView
|
||||
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.models import Profile, Background
|
||||
|
||||
class ProfileDetailView(APIView):
|
||||
authentication_classes = [SessionAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get(self, request, id):
|
||||
profile = Profile.objects.get(pk=id)
|
||||
serializer = ProfileSerializer(profile)
|
||||
return Response(serializer.data)
|
||||
|
||||
class BackgroundListView(APIView):
|
||||
authentication_classes = [SessionAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get(self, request):
|
||||
backgrounds = Background.objects.all()
|
||||
serializer = BackgroundSerializer(backgrounds, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
class BackgroundDetailView(APIView):
|
||||
authentication_classes = [SessionAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get(self, request, id):
|
||||
background = Background.objects.get(pk=id)
|
||||
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.reverse import reverse
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
@permission_classes([])
|
||||
def api_root(request, format=None):
|
||||
return Response({
|
||||
'tracks': reverse('api-tracks', request=request, format=format),
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
from rest_framework.views import APIView
|
||||
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.serializers import TrackSerializer
|
||||
from playlist.spotify import spt
|
||||
from playlist.tasks import get_banter, get_and_dither_image
|
||||
|
||||
class TrackListView(APIView):
|
||||
authentication_classes = [SessionAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
def get(self, request):
|
||||
tracks = Track.objects.all()
|
||||
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)
|
||||
|
||||
class TrackDetailView(APIView):
|
||||
authentication_classes = [SessionAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
def get(self, request, id):
|
||||
track = Track.objects.get(pk=id)
|
||||
serializer = TrackSerializer(track, context={'request': request})
|
||||
|
||||
@@ -2,20 +2,14 @@ from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from django.contrib.auth.models import User
|
||||
from playlist.serializers import UserSerializer
|
||||
from rest_framework.authentication import SessionAuthentication
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
|
||||
class UserListView(APIView):
|
||||
authentication_classes = [SessionAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
def get(self, request):
|
||||
users = User.objects.all()
|
||||
serializer = UserSerializer(users, many=True, context={'request': request})
|
||||
return Response(serializer.data)
|
||||
|
||||
class UserDetailView(APIView):
|
||||
authentication_classes = [SessionAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
def get(self, request, id):
|
||||
user = User.objects.get(pk=id)
|
||||
serializer = UserSerializer(user, context={'request': request})
|
||||
|
||||
Reference in New Issue
Block a user