Skip to content

Commit

Permalink
Hotfix drop endpoint permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
noloerino committed Mar 3, 2019
1 parent ae842a0 commit db37312
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
10 changes: 10 additions & 0 deletions csm_web/scheduler/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,13 @@ def has_permission(self, request, view):

def has_object_permission(self, request, view, obj):
return bool(request.user and request.user == obj.user)


class DestroyIsOwner(permissions.BasePermission):
"""
Grants permission to destroy the resource only if the requester is the user
associated with the object.
"""

def has_object_permission(self, request, view, obj):
return bool(request.user and request.user == obj.user)
4 changes: 3 additions & 1 deletion csm_web/scheduler/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def handle_profile_post_save(sender, **kwargs):
)
if (
models.Profile.objects.filter(
user=profile.user, course__name="CS70", leader=profile.leader
user=profile.user,
course__name="CS70",
leader=profile.leader,
).count()
== 1
):
Expand Down
13 changes: 12 additions & 1 deletion csm_web/scheduler/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@
SpacetimeSerializer,
OverrideSerializer,
)
from .permissions import is_leader, IsLeader, IsLeaderOrReadOnly, IsReadIfOwner, IsOwner
from .permissions import (
is_leader,
IsLeader,
IsLeaderOrReadOnly,
IsReadIfOwner,
IsOwner,
DestroyIsOwner,
)

VERBOSE = "verbose"
USERINFO = "userinfo"
Expand Down Expand Up @@ -162,8 +169,12 @@ def get_serializer_class(self):

class DeleteProfile(generics.DestroyAPIView):
# TODO this looks like it should really have a permission class...

permission_classes = (DestroyIsOwner,)

def destroy(self, request, *args, **kwargs):
profile = get_object_or_404(Profile, pk=self.kwargs["pk"])
self.check_object_permissions(request, profile)
if not profile.active:
raise PermissionDenied(
"This profile ({}) has been deactivated".format(profile)
Expand Down

0 comments on commit db37312

Please sign in to comment.