Skip to content

Commit 5943bd7

Browse files
committed
Day 9: Added Global Permission and remove permission_classes from views and setting.py file
1 parent e6c8bf0 commit 5943bd7

File tree

2 files changed

+3
-20
lines changed

2 files changed

+3
-20
lines changed

api/views.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from django.shortcuts import get_object_or_404
88
from rest_framework import status
99
from rest_framework.parsers import FormParser, JSONParser, MultiPartParser
10-
from rest_framework.permissions import AllowAny, IsAdminUser, IsAuthenticated
10+
from rest_framework.permissions import AllowAny, IsAdminUser
1111
from rest_framework.response import Response
1212
from rest_framework.views import APIView
1313
from rest_framework_simplejwt.exceptions import TokenError
@@ -27,7 +27,6 @@
2727
UserSettings,
2828
)
2929
from api.pagination import DefaultPagination
30-
from api.permissions import DynamicPagePermission
3130
from api.serializers import (
3231
AssignPermissionSerializer,
3332
FollowerSerializer,
@@ -115,7 +114,6 @@ def post(self, request):
115114

116115

117116
class ProfileView(APIView):
118-
permission_classes = [IsAuthenticated, DynamicPagePermission]
119117
serializer_class = ProfileSerializer
120118
parser_classes = [
121119
JSONParser,
@@ -157,7 +155,6 @@ def patch(self, request, username):
157155

158156

159157
class FollowersView(APIView):
160-
permission_classes = [IsAuthenticated, DynamicPagePermission]
161158
pagination_class = DefaultPagination
162159

163160
def get(self, request, username):
@@ -195,7 +192,6 @@ def delete(self, request, username):
195192

196193

197194
class FollowingView(APIView):
198-
permission_classes = [IsAuthenticated, DynamicPagePermission]
199195
pagination_class = DefaultPagination
200196

201197
def get(self, request, username):
@@ -238,8 +234,6 @@ def delete(self, request, username):
238234

239235

240236
class FollowActionView(APIView):
241-
permission_classes = [IsAuthenticated]
242-
243237
def post(self, request, username):
244238
target_user = get_object_or_404(User, username=username)
245239
if request.user == target_user:
@@ -270,8 +264,6 @@ def delete(self, request, username):
270264

271265

272266
class FollowRequestRespondView(APIView):
273-
permission_classes = [IsAuthenticated]
274-
275267
def post(self, request, request_id):
276268
follow_request = get_object_or_404(FollowRequest, id=request_id)
277269

@@ -325,8 +317,6 @@ def post(self, request):
325317

326318
# ======================= Block User View =======================
327319
class BlockUserView(APIView):
328-
permission_classes = [IsAuthenticated]
329-
330320
def post(self, request, user_id):
331321
BlockedUser.objects.get_or_create(blocker=request.user, blocked_id=user_id)
332322
return Response({"detail": "User blocked"}, status=201)
@@ -338,8 +328,6 @@ def delete(self, request, user_id):
338328

339329
# ======================= Mute User View =======================
340330
class MuteUserView(APIView):
341-
permission_classes = [IsAuthenticated]
342-
343331
def post(self, request, user_id):
344332
MutedUser.objects.get_or_create(user=request.user, muted_user_id=user_id)
345333
return Response({"detail": "User muted"}, status=201)
@@ -351,8 +339,6 @@ def delete(self, request, user_id):
351339

352340
# ======================= Close Friends View =======================
353341
class CloseFriendView(APIView):
354-
permission_classes = [IsAuthenticated]
355-
356342
def post(self, request, user_id):
357343
CloseFriend.objects.get_or_create(user=request.user, friend_id=user_id)
358344
return Response({"detail": "Added to close friends"}, status=201)
@@ -366,8 +352,6 @@ def delete(self, request, user_id):
366352

367353

368354
class UserSettingsView(APIView):
369-
permission_classes = [IsAuthenticated]
370-
371355
def get(self, request):
372356
settings_obj, _ = UserSettings.objects.get_or_create(user=request.user)
373357
serializer = UserSettingsSerializer(settings_obj)
@@ -385,8 +369,6 @@ def patch(self, request):
385369

386370
# ======================== Logout View ========================
387371
class LogoutView(APIView):
388-
permission_classes = [IsAuthenticated]
389-
390372
def post(self, request):
391373
try:
392374
refresh_token = request.data.get("refresh")

backend/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@
204204
"rest_framework_simplejwt.authentication.JWTAuthentication",
205205
],
206206
"DEFAULT_PERMISSION_CLASSES": [
207-
"rest_framework.permissions.AllowAny",
207+
"rest_framework.permissions.IsAuthenticated",
208+
"api.permissions.DynamicPagePermission",
208209
],
209210
# Disable CSRF for API endpoints (we use JWT)
210211
"DEFAULT_RENDERER_CLASSES": [

0 commit comments

Comments
 (0)