2

I have a view:

class DealsView(APIView):
    permission_classes = (IsAuthenticated, IsOwnerOrCuratorOrDirectorOrNotAllowed, )

    def get(self, request, user_pk):
        ...

But in order to check the permissions correctly I need to pass user_pk url argument to permission:

class IsOwnerOrCuratorOrDirectorOrNotAllowed(permissions.BasePermission):
    def has_permission(self, request, view):
        ...

By default it doesn't have any arguments except self, request, and view. How can I go through it?

Alexander Shpindler
  • 811
  • 1
  • 11
  • 31

1 Answers1

17

Try this:

class IsOwnerOrCuratorOrDirectorOrNotAllowed(permissions.BasePermission):
    def has_permission(self, request, view):
        user_pk = view.kwargs.get('user_pk', None)
        ...
Neuron
  • 5,141
  • 5
  • 38
  • 59
origamic
  • 1,076
  • 8
  • 18