Skip to content

Commit 3b9bfb9

Browse files
committed
refactor: remove redundant permission
1 parent b93ba3f commit 3b9bfb9

File tree

2 files changed

+3
-18
lines changed

2 files changed

+3
-18
lines changed

backend/backend/permissions.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
from django.utils import timezone
2-
from rest_framework.permissions import SAFE_METHODS, BasePermission
2+
from rest_framework.permissions import BasePermission
33

44
from .models import Role
55
from .serializers import CreatePositionSerializer
66

77
CAN_CREATE_POSITION_ROLES = ["admin", "fum", "board", "presidium", "group_leader"]
88

99

10-
class IsMemberOwner(BasePermission):
11-
"""
12-
Permission to only allow owners of an object to edit/delete it.
13-
"""
14-
15-
def has_object_permission(self, request, view, obj):
16-
# Allow read permissions for any request
17-
if request.method in SAFE_METHODS:
18-
return True
19-
20-
# Write permissions only to the owner
21-
return obj.member == request.user
22-
23-
2410
# TODO: Should be removed if we're considering django-admin for admin functionalities
2511
class CanCreatePosition(BasePermission):
2612
"""

backend/backend/views.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from .email import send_password_reset_email, send_verification_email
1313
from .models import Application, Position
14-
from .permissions import CanCreatePosition, IsMemberOwner
14+
from .permissions import CanCreatePosition
1515
from .serializers import (
1616
ApplicationSerializer,
1717
CreatePositionSerializer,
@@ -416,7 +416,7 @@ class ApplicationViewSet(ModelViewSet):
416416
- Destroy: Delete own application (only if draft status)
417417
"""
418418

419-
permission_classes = [IsAuthenticated, IsMemberOwner]
419+
permission_classes = [IsAuthenticated]
420420

421421
def get_queryset(self):
422422
"""Get all applications with optimized queries"""
@@ -465,7 +465,6 @@ def destroy(self, request, *args, **kwargs):
465465
class PositionViewSet(ReadOnlyModelViewSet):
466466
queryset = Position.objects.all()
467467
serializer_class = PositionSerializer
468-
permission_classes = [IsAuthenticated]
469468

470469
def list(self, request):
471470
"""Return both open positions and user's positions"""

0 commit comments

Comments
 (0)