Add basic superuser permission checks for admin
This commit is contained in:
parent
4dd7d8628d
commit
1664e9409c
1 changed files with 28 additions and 0 deletions
|
@ -61,3 +61,31 @@ class User(AbstractBaseUser):
|
||||||
|
|
||||||
def normalize_username(self, username):
|
def normalize_username(self, username):
|
||||||
return super().normalize_username(username).strip().lower()
|
return super().normalize_username(username).strip().lower()
|
||||||
|
|
||||||
|
def has_perm(self, perm, obj=None):
|
||||||
|
"""
|
||||||
|
Return True if the user has the specified permission.
|
||||||
|
Superusers automatically have all permissions.
|
||||||
|
"""
|
||||||
|
return self.is_superuser
|
||||||
|
|
||||||
|
def has_module_perms(self, app_label):
|
||||||
|
"""
|
||||||
|
Return True if the user has any permissions in the given app label.
|
||||||
|
Superusers automatically have all permissions.
|
||||||
|
"""
|
||||||
|
return self.is_superuser
|
||||||
|
|
||||||
|
def get_all_permissions(self, obj=None):
|
||||||
|
"""
|
||||||
|
Return a set of permission strings that the user has.
|
||||||
|
Superusers have all permissions.
|
||||||
|
"""
|
||||||
|
if self.is_superuser:
|
||||||
|
from django.contrib.auth.models import Permission
|
||||||
|
|
||||||
|
return {
|
||||||
|
f"{perm.content_type.app_label}.{perm.codename}"
|
||||||
|
for perm in Permission.objects.all()
|
||||||
|
}
|
||||||
|
return set()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue