Fer Mena
Fer Mena

Reputation: 407

Django restframework test permissions

Which is the proper way to test object based permissions?

Sample:

from rest_framework import permissions

class IsOfficeAdmin(permissions.BasePermission):

    def has_object_permission(self, request, view, obj):
        office = obj
        return office.admin == request.user

Upvotes: 1

Views: 71

Answers (1)

Roba
Roba

Reputation: 688

To your questions:

  • it's up to you to write the logic which will allow a user to access the object. As a result, you have to return a Boolean.
  • yes. You will specify to the view which permission classes you want to apply. In case of object permissions they will be queried on detail routes (get, update, delete)

Upvotes: 1

Related Questions