N
N
nurzhannogerbek2017-12-10 14:56:41
WordPress
nurzhannogerbek, 2017-12-10 14:56:41

How to override has_perm method in Django?

Hello! Please help me figure it out.
I ran into the following problem. There is a superuser who lacks one right (for example, use_tool rights). When checking the use_tool permission for this user, I expected that it would return False, since this user does not have this right, although he is a superuser. It always returns True.
views.py:

if user.has_perm("use_tool"):
    print "True"
else:
    print "False"

I looked under the hood of Django and noticed that there is such an inheritance:
User -> AbstractUser -> AbstractBaseUser, PermissionMixin

The has_perm method is defined in PermissionMixin :
def has_perm(self, perm, obj=None):
        if self.is_active and self.is_superuser: <-- Проблема вызывается из-за данной строки
            return True

PS Well, or how else to check the user, regardless of his status, a certain right (permission)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jupiter Max, 2019-09-28
@vardoLP

It's some kind of plugin. For example, this one

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question