[organization] Allow to create super user with default org
@@ -199,6 +199,11 @@ class UserManager(BaseUserManager):
def _create_user(self, email, password, **extra_fields):
"""Create and save a User with the given email and password."""
+ if not extra_fields.get('organization'):
+ extra_fields['organization'] = get_user_request_organization()
+ if not extra_fields['organization']:
+ extra_fields['organization'] = get_organization(email=email)
+
if not email:
raise ValueError('The given email must be set')
email = self.normalize_email(email)
@@ -212,14 +217,10 @@ class UserManager(BaseUserManager):
if extra_fields.get('username'):
email = extra_fields.pop('username')
- if not extra_fields.get('organization'):
- extra_fields['organization'] = get_user_request_organization()
- if not extra_fields['organization']:
- extra_fields['organization'] = get_organization(email=email)
-
extra_fields.setdefault('is_staff', False)
extra_fields.setdefault('is_superuser', False)
extra_fields.setdefault('is_admin', False)
+
return self._create_user(email, password, **extra_fields)
def create_superuser(self, email, password, **extra_fields):
