Skip to content

Instantly share code, notes, and snippets.

@aballah-chamakh
Created December 10, 2019 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aballah-chamakh/3403241b6ca97ddfb63788139e25e103 to your computer and use it in GitHub Desktop.
Save aballah-chamakh/3403241b6ca97ddfb63788139e25e103 to your computer and use it in GitHub Desktop.
from rest_framework import permissions
class IsAuthenticatedAndOwnerOrDeny(permissions.BasePermission):
def has_permission(self, request, view):
# check if the user is authenticated
return self.request.user.is_authenticated()
def has_object_permission(self, request, view, obj):
# check if the user is the owner of the inference object
return obj.user == request.user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment