Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

permission_classes in ListBulkCreateUpdateAPIView #73

Open
nguyenducthuanuet opened this issue Dec 19, 2018 · 1 comment
Open

permission_classes in ListBulkCreateUpdateAPIView #73

nguyenducthuanuet opened this issue Dec 19, 2018 · 1 comment

Comments

@nguyenducthuanuet
Copy link

nguyenducthuanuet commented Dec 19, 2018

I have a permisson class like this

from rest_framework import status, permissions
class IsOwnerOrReadOnly(permissions.BasePermission):
    """
    Custom permission to only allow owners of an object to edit it.
    """

    def has_object_permission(self, request, view, obj):
        # Read permissions are allowed to any request,
        # so we'll always allow GET, HEAD or OPTIONS requests.
        if request.method in permissions.SAFE_METHODS:
            return True

        # Write permissions are only allowed to the owner of the snippet.
        return obj.user == request.user

and my ViewSet:

class CompanyView(ListBulkCreateUpdateAPIView):
     serializer_class = company_serializer.CompanySerializer
     permission_classes = (IsOwnerOrReadOnly,)

But When I make a POST/PUT request to insert or update many records, My ViewSet does not use Permission class to check permissions.
How to add permission classes to Bulk ViewSet ?

@mvduyn
Copy link

mvduyn commented Jan 29, 2019

You should call self.check_object_permission() from the GenericAPIView class.
See the documentation: https://www.django-rest-framework.org/api-guide/generic-views/#genericapiview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants