Does django-rules work with django rest framework viewsets?
See original GitHub issueHi,
I am trying to integrate rules with DRF’s viewsets but I keep getting an AttributeError: 'OrgViewSet' object has no attribute 'request'
Here is my viewset code:
class OrgViewSet(PermissionRequiredMixin,
mixins.ListModelMixin,
viewsets.GenericViewSet):
permission_required = CHANGE_ORG
queryset = Org.objects.all()
serializer_class = OrgSerializer
Here is the stack trace
Internal Server Error: /orgs/
Traceback (most recent call last):
File "/Users/dre/code/treebeard/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/Users/dre/code/treebeard/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/dre/code/treebeard/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/dre/code/treebeard/venv/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/Users/dre/code/treebeard/venv/lib/python3.6/site-packages/rest_framework/viewsets.py", line 86, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/dre/code/treebeard/venv/lib/python3.6/site-packages/django/contrib/auth/mixins.py", line 90, in dispatch
if not self.has_permission():
File "/Users/dre/code/treebeard/venv/lib/python3.6/site-packages/rules/contrib/views.py", line 51, in has_permission
return self.request.user.has_perms(perms, obj)
AttributeError: 'OrgViewSet' object has no attribute 'request'
Any help would be greatly appreciated.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Viewsets - Django REST framework
Django REST framework allows you to combine the logic for a set of related views in a single class, called a ViewSet ....
Read more >django-rest-framework-rules - PyPI
django -rest-framework-rules aims to seamlessly integrate rules - a tiny but powerful app providing object-level permissions - into the Django REST framework ......
Read more >DRF ViewSet operation authorization with rules - Stack Overflow
Using django-rules, how can the create() operation in CourseViewSet be restricted to only users of user_type TEACHER? python · security · django ......
Read more >Built-in Permission Classes in Django REST Framework
This article looks at how the built-in permission classes work in Django REST Framework.
Read more >Django Rest Framework ViewSets - Level Up Coding
A browsable API; Authentication; Serializers; Customization features. In this tutorial, we will build a Django application that utilizes ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
rules
now has built-in support for Django Rest Framework (contributed by @efficiosoft in #100). See here for docs on the feature: https://github.com/dfunckt/django-rules#permissions-in-django-rest-frameworkDRF support ties well with the newly-added support for automatic permissions for models – see https://github.com/dfunckt/django-rules#permissions-in-models (also by @efficiosoft, in #99)
All in all, I think
rules
now integrates well with DRF – let me know of any feedback you may have.django-rules
works with django REST framework viewsets using thedjango-rest-framework-rules
package.lnstallation and usage are documented in
django-rest-framework-rules
’ README, further examples can be found indjango-rest-framework-rules
’ tests.@dfunckt: I guess, that you can close this issue now.