question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Role not working with DRF ViewSet

See original GitHub issue

Hello, I am trying to implement a DRF based application with some object level permissions.

I tired the following simple configuration with not success:

u = User.objects.get(username='user1')
assign_role(u, "test_role")

views.py

class MyObjectViewSet(HasRoleMixin, viewsets.ReadOnlyModelViewSet):
    queryset = MyObject.objects.all()
    serializer_class = MyObjectSerializer
    allowed_roles = ['test_role']

roles.py

class TestRole(AbstractUserRole):
    available_permissions = {
        'list_my_objects': True,
    }

I can successfully login in with user1, but calling the get API over that view results in a 403 Forbidden error.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
StefanoFioravanzocommented, May 1, 2019

Hey @filipeximenes , just tried replacing viewsets.ReadOnlyModelViewSet with generics.ListAPIView but I get the same behavior

1reaction
filipeximenescommented, Apr 30, 2019

Very weird. Could you try using a GenericView instead of a ViewSet to see what happens?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django REST Framework viewset per-action permissions
Let's suppose I defined some permissions classes such as 'IsAdmin', 'IsRole1', 'IsRole2', ..., and I want to grant different permissions to the ...
Read more >
Viewsets - Django REST framework
A ViewSet class is simply a type of class-based View, that does not provide any method handlers such as .get() or .post() ,...
Read more >
Django REST Framework Views - ViewSets - TestDriven.io
The URL prefix for the views; The ViewSet itself. Then, we included the router inside urlpatterns . This is not the only way...
Read more >
10 things you need to know to effectively use Django Rest ...
... I got to know while working with Django Rest Framework in Profile Software. ... Every time you write views that should do...
Read more >
Viewsets and Routers with React Front-end Example - Part-4
Hello, we are back again for the forth tutorial in this Django Rest Framework Series. In the following series of tutorials we will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found