Reputation: 101
When I place the PermissionRequiredMixin as the most left paramenter, my requests get forwarded to the login URL even though the request is coming from an already authenticated user.
class ExampleViewSet(PermissionRequiredMixin, viewsets.ModelViewSet):
permission_required = ('example.example_view',)
When I place the PermissionRequiredMixin after the ModelViewSet the authenticated user is detected, however, the permission_required is ignored, and every user without the permission is allowed as well. And this answer suggested, that this is caused by the placement of the parameter, which leads to the first problem.
class ExampleViewSet(viewsets.ModelViewSet, PermissionRequiredMixin):
permission_required = ('example.example_view',)
How do I solve this problem?
Upvotes: 0
Views: 499
Reputation: 1869
It is not a problem. Order of inheritance classes is important. View base class have to set at last position. Mixins by theirs positions can override some function of the django view. The ordering of overriding function by the child class is in part defined by this ordering. First parent in the order will be called at first. In your case, if you put a breakpoint in your PermissionRequiredMixin, you will see that python does not pass in it when you call your page
You can read some links as:
Upvotes: 1