Reputation: 2453
I use Django auth groups. The groups contain permissions(https://docs.djangoproject.com/en/4.1/ref/contrib/auth/#group-model). Now groups are assigned to users based on their actual role. In my test setup one group contains the permission (market.xyz). This group is assigned to the logged in user.
In the debugger I see that the group permission is assigned (line 88)
But if I call user.has_perm(per1) I get False (line 87). Same results for calling user.has_perm('market.xyz').
I can not make sense of this result. Is it necessary to activate the auth group mechanism? Do I have to add some additional Middleware?
To be sure I double-checked the documentation about group permissions being available on user level (https://docs.djangoproject.com/en/4.1/topics/auth/default/#groups):
A user in a group automatically has the permissions granted to that group. For example, if the group Site editors has the permission can_edit_home_page, any user in that group will have that permission.
Upvotes: 0
Views: 156
Reputation: 2453
Above I already suspected that some kind of Middleware is missing to activate the auth groups. Pretty close! After some trial and error I discovered that the ModelBackend makes it all work. IMHO the documentation on auth groups could make a remark on this!
AUTHENTICATION_BACKENDS = [
"foo.bar.MyOwnAuthBackend",
"django.contrib.auth.backends.ModelBackend",
]
Upvotes: 0