I am using Django Guardian
to have object-level permission along with global permissions. Some of the users have a group with global permissions, and some have object-level permissions. With this, I seem to need to modify the PermissionRequiredMixin
to check also for the object-level permission.
views.py
class MainPageView(PermissionRequiredMixin, TemplateView):
permission_required = "app.view_mainpage"
template_name = "web/mainpage.html"
This one works if the user has global permission but if the user is under a group with object-level permission, it won't. With guardian, to check for object-level permission, you also have to pass the object instance.
example:
self.request.user.has_perm('view_mainpage', obj)
And on PermissionRequiredMixin
, the checking goes only like this, self.request.user.has_perms(perms)
So if the user has a group with permission of view_mainpage
of a specific object, how can I check it too? By the way, all my permissions are of the same content_type
. Is there any way I can execute this? Like I have to pass the object instance to PermissionRequiredMixin
if the user is under an object-level group and None
if the user is under a global group.