You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Documentation of the decorator for permissions on views is good, but focuses on views with passed-in objects and a user's permissions to access them. The simpler case, where you have set up group membership rules with django-rules and want to protect an entire view based on group membership, is not obvious.
I finally figured out that django-rules can be used in conjunction with Django's user_passes_test. I recommend adding to that section of the documentation something like this:
If you want to protect an entire view with a rules decorator, irrespective of any particular object, django-rules can be used in conjunction with Django's user_passes_test decorator. Rather than using the permission_required, use something like:
I think you're somewhat confused. You're not testing for permissions in your example and while what you have should work, the following might make things slightly clearer. Here's how I'd do the same thing as you're trying to do, but with Django permissions:
Ah! Thanks much for clarifying. Yes that's much better. I didn't quite get that from the docs but maybe that was my own uncareful reading. Possibly worth adding that simple case to the docs as well? Cheers.
Documentation of the decorator for permissions on views is good, but focuses on views with passed-in objects and a user's permissions to access them. The simpler case, where you have set up group membership rules with django-rules and want to protect an entire view based on group membership, is not obvious.
I finally figured out that django-rules can be used in conjunction with Django's
user_passes_test
. I recommend adding to that section of the documentation something like this:If you want to protect an entire view with a rules decorator, irrespective of any particular object, django-rules can be used in conjunction with Django's
user_passes_test
decorator. Rather than using thepermission_required
, use something like:The text was updated successfully, but these errors were encountered: