Переглянути джерело

Fix createsuperuser cli

Fixes https://github.com/lesspass/lesspass/issues/699
dependabot/npm_and_yarn/mobile/ansi-regex-4.1.1
Guillaume Vincent 2 роки тому
джерело
коміт
533ece38a8
5 змінених файлів з 56 додано та 15 видалено
  1. +18
    -0
      containers/backend/api/migrations/0009_alter_lesspassuser_key.py
  2. +23
    -0
      containers/backend/api/migrations/0010_alter_password_site_and_login.py
  3. +7
    -12
      containers/backend/api/models.py
  4. +2
    -2
      containers/backend/api/tests/test_user.py
  5. +6
    -1
      containers/backend/lesspass/settings.py

+ 18
- 0
containers/backend/api/migrations/0009_alter_lesspassuser_key.py Переглянути файл

@@ -0,0 +1,18 @@
# Generated by Django 3.2.10 on 2022-02-17 20:17

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("api", "0008_encryptedpasswordprofiles"),
]

operations = [
migrations.AlterField(
model_name="lesspassuser",
name="key",
field=models.TextField(blank=True, default=""),
),
]

+ 23
- 0
containers/backend/api/migrations/0010_alter_password_site_and_login.py Переглянути файл

@@ -0,0 +1,23 @@
# Generated by Django 3.2.10 on 2022-02-17 20:17

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("api", "0009_alter_lesspassuser_key"),
]

operations = [
migrations.AlterField(
model_name="password",
name="login",
field=models.CharField(blank=True, default="", max_length=255),
),
migrations.AlterField(
model_name="password",
name="site",
field=models.CharField(blank=True, default="", max_length=255),
),
]

+ 7
- 12
containers/backend/api/models.py Переглянути файл

@@ -4,23 +4,18 @@ from django.contrib.auth.models import BaseUserManager, AbstractBaseUser


class LesspassUserManager(BaseUserManager):
def create_user(self, email, password=None):
def create_user(self, email, password=None, key=""):
if not email:
raise ValueError("Users must have an email address")

user = self.model(
email=self.normalize_email(email),
)
user = self.model(email=self.normalize_email(email), key=key)

user.set_password(password)
user.save(using=self._db)
return user

def create_superuser(self, email, password):
user = self.create_user(
email,
password=password,
)
def create_superuser(self, email, password, key=""):
user = self.create_user(email, password=password, key=key)
user.is_admin = True
user.save(using=self._db)
return user
@@ -30,7 +25,7 @@ class LessPassUser(AbstractBaseUser):
email = models.EmailField(verbose_name="email address", max_length=255, unique=True)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)
key = models.TextField(null=True)
key = models.TextField(blank=True, default="")

objects = LesspassUserManager()

@@ -77,8 +72,8 @@ class Password(DateMixin):
user = models.ForeignKey(
LessPassUser, on_delete=models.CASCADE, related_name="passwords"
)
login = models.CharField(max_length=255, null=True, blank=True)
site = models.CharField(max_length=255, null=True, blank=True)
login = models.CharField(max_length=255, blank=True, default="")
site = models.CharField(max_length=255, blank=True, default="")

lowercase = models.BooleanField(default=True)
uppercase = models.BooleanField(default=True)


+ 2
- 2
containers/backend/api/tests/test_user.py Переглянути файл

@@ -13,10 +13,10 @@ class UserTestCase(APITestCase):
def test_auth_user_me(self):
request = self.client.get("/api/auth/users/me/")
self.assertEqual(request.status_code, 200)
self.assertIsNone(request.data["key"])
self.assertEqual(request.data["key"], "")

def test_update_auth_user_me(self):
self.assertIsNone(models.LessPassUser.objects.first().key)
self.assertEqual(models.LessPassUser.objects.first().key, "")
request = self.client.put("/api/auth/users/me/", {"key": "abc"})
self.assertEqual(request.status_code, 200)
self.assertEqual("abc", models.LessPassUser.objects.first().key)


+ 6
- 1
containers/backend/lesspass/settings.py Переглянути файл

@@ -192,7 +192,7 @@ if "test" in sys.argv[1:] or "jenkins" in sys.argv[1:]:
DJOSER = {
"PASSWORD_RESET_CONFIRM_URL": "#/password/reset/confirm/{uid}/{token}",
"ACTIVATION_URL": "#/activate/{uid}/{token}",
"TOKEN_MODEL": None
"TOKEN_MODEL": None,
}

SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
@@ -215,3 +215,8 @@ EMAIL_PORT = env.int("EMAIL_PORT", default=25)
EMAIL_SUBJECT_PREFIX = os.getenv("EMAIL_SUBJECT_PREFIX", "[LessPass] ")
EMAIL_USE_TLS = env.bool("EMAIL_USE_TLS", default=False)
EMAIL_USE_SSL = env.bool("EMAIL_USE_SSL", default=False)

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.AutoField"

Завантаження…
Відмінити
Зберегти