From 119bcba0fcf1fdafc8a896bbbe2e983744a6b92d Mon Sep 17 00:00:00 2001 From: Nino Date: Mon, 2 Sep 2024 13:52:33 +0200 Subject: [PATCH] Fix user creation --- .../migrations/0011_alter_user_managers.py | 20 ++++++ app/apps/users/models.py | 5 +- app/apps/users/user_manager.py | 65 ++++++++++--------- app/requirements.txt | 3 +- 4 files changed, 56 insertions(+), 37 deletions(-) create mode 100644 app/apps/users/migrations/0011_alter_user_managers.py diff --git a/app/apps/users/migrations/0011_alter_user_managers.py b/app/apps/users/migrations/0011_alter_user_managers.py new file mode 100644 index 00000000..31f4b00f --- /dev/null +++ b/app/apps/users/migrations/0011_alter_user_managers.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2.15 on 2024-09-02 11:41 + +import django.contrib.auth.models +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("users", "0010_user_team_settings"), + ] + + operations = [ + migrations.AlterModelManagers( + name="user", + managers=[ + ("objects", django.contrib.auth.models.UserManager()), + ], + ), + ] diff --git a/app/apps/users/models.py b/app/apps/users/models.py index 3e572d00..f7e0428c 100755 --- a/app/apps/users/models.py +++ b/app/apps/users/models.py @@ -1,7 +1,6 @@ import datetime import uuid -from apps.users.user_manager import UserManager from apps.users.utils import generate_username from django.contrib.auth.models import AbstractUser from django.db import models @@ -26,9 +25,7 @@ class Meta: ) USERNAME_FIELD = "email" - REQUIRED_FIELDS = [] - - objects = UserManager() + REQUIRED_FIELDS = ["username"] @property def get_current_itinerary(self): diff --git a/app/apps/users/user_manager.py b/app/apps/users/user_manager.py index fa65c08f..7d2b9faf 100755 --- a/app/apps/users/user_manager.py +++ b/app/apps/users/user_manager.py @@ -2,34 +2,37 @@ class UserManager(BaseUserManager): - """Define a model manager for User model with no username field.""" - - use_in_migrations = True - - def _create_user(self, email, password, **extra_fields): - """Create and save a User with the given email and password.""" - if not email: - raise ValueError("The given email must be set") - email = self.normalize_email(email) - user = self.model(email=email, **extra_fields) - user.set_password(password) - user.save(using=self._db) - return user - - def create_user(self, email, password=None, **extra_fields): - """Create and save a regular User with the given email and password.""" - extra_fields.setdefault("is_staff", False) - extra_fields.setdefault("is_superuser", False) - return self._create_user(email, password, **extra_fields) - - def create_superuser(self, email, password, **extra_fields): - """Create and save a SuperUser with the given email and password.""" - extra_fields.setdefault("is_staff", True) - extra_fields.setdefault("is_superuser", True) - - if extra_fields.get("is_staff") is not True: - raise ValueError("Superuser must have is_staff=True.") - if extra_fields.get("is_superuser") is not True: - raise ValueError("Superuser must have is_superuser=True.") - - return self._create_user(email, password, **extra_fields) + """ + This model isn't used anymore but can't be deleted because of the reference in 0001_initial.py + If the migrations are applied in production, this can be removed. + """ + + # use_in_migrations = True + + # def _create_user(self, email, password, **extra_fields): + # """Create and save a User with the given email and password.""" + # if not email: + # raise ValueError("The given email must be set") + # email = self.normalize_email(email) + # user = self.model(email=email, **extra_fields) + # user.set_password(password) + # user.save(using=self._db) + # return user + + # def create_user(self, email, password=None, **extra_fields): + # """Create and save a regular User with the given email and password.""" + # extra_fields.setdefault("is_staff", False) + # extra_fields.setdefault("is_superuser", False) + # return self._create_user(email, password, **extra_fields) + + # def create_superuser(self, email, password, **extra_fields): + # """Create and save a SuperUser with the given email and password.""" + # extra_fields.setdefault("is_staff", True) + # extra_fields.setdefault("is_superuser", True) + + # if extra_fields.get("is_staff") is not True: + # raise ValueError("Superuser must have is_staff=True.") + # if extra_fields.get("is_superuser") is not True: + # raise ValueError("Superuser must have is_superuser=True.") + + # return self._create_user(email, password, **extra_fields) diff --git a/app/requirements.txt b/app/requirements.txt index df0c59fe..e8377474 100755 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -26,9 +26,8 @@ django-celery-results==2.5.1 django-timezone-field<7.0 # Authentication -datapunt-keycloak-oidc @ git+https://github.com/remyvdwereld/keycloak_oidc_top.git@v1.1 +datapunt-keycloak-oidc @ git+https://github.com/remyvdwereld/keycloak_oidc_top.git@main djangorestframework-simplejwt==5.3.1 - # Algorithm toolbox geopy==2.4.1 joblib==1.3.2