Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Extend user model to use groups and permissions

Marcin Gębala6c70a5b0ff40
diff --git a/saleor/registration/backends.py b/saleor/registration/backends.py
index 441dbd3168..456def0fa4 100644
--- a/saleor/registration/backends.py
+++ b/saleor/registration/backends.py
@@ -1,11 +1,12 @@
from django.contrib.auth import get_user_model
+from django.contrib.auth.backends import ModelBackend
from .models import ExternalUserData
User = get_user_model()
-class Backend(object):
+class Backend(ModelBackend):
def get_user(self, user_id):
try:
diff --git a/saleor/userprofile/models.py b/saleor/userprofile/models.py
index 87323ebefe..ad41561e20 100644
--- a/saleor/userprofile/models.py
+++ b/saleor/userprofile/models.py
@@ -3,7 +3,7 @@ import re
from django.contrib.auth.hashers import (check_password, make_password,
is_password_usable)
-from django.contrib.auth.models import BaseUserManager
+from django.contrib.auth.models import BaseUserManager, PermissionsMixin
from django.db import models
from django.forms.models import model_to_dict
from django.utils import timezone
@@ -149,7 +149,8 @@ class UserManager(BaseUserManager):
return user
def create_superuser(self, email, password=None, **extra_fields):
- return self.create_user(email, password, is_staff=True, **extra_fields)
+ return self.create_user(email, password, is_staff=True,
+ is_superuser=True, **extra_fields)
def store_address(self, user, address, alias,
billing=False, shipping=False):
@@ -166,7 +167,7 @@ class UserManager(BaseUserManager):
@python_2_unicode_compatible
-class User(models.Model):
+class User(PermissionsMixin, models.Model):
email = models.EmailField(unique=True)
addresses = models.ManyToManyField(Address, through=AddressBook)
@@ -213,15 +214,6 @@ class User(models.Model):
def get_short_name(self):
return self.email
- def has_perm(self, *_args, **_kwargs):
- return True
-
- def has_perms(self, *_args, **_kwargs):
- return True
-
- def has_module_perms(self, _app_label):
- return True
-
def get_username(self):
'Return the identifying username for this User'
return self.email