From 32ff0cb32a7138adcaa3fbd0d4e0c9ec298ebf65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zaoral?= Date: Thu, 16 Nov 2023 12:32:27 +0100 Subject: [PATCH] django: allow '/' character in usernames All worker usernames use the `worker/hostname` format which did not match the regular expression in the corresponding field validator. Therefore, worker user profiles could not be directly edited in the Django Admin. Resolves: https://github.com/openscanhub/openscanhub/issues/185 --- .../migrations/0003_alter_user_username.py | 19 +++++++++++++++++++ kobo/django/auth/models.py | 6 +++--- 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 kobo/django/auth/migrations/0003_alter_user_username.py diff --git a/kobo/django/auth/migrations/0003_alter_user_username.py b/kobo/django/auth/migrations/0003_alter_user_username.py new file mode 100644 index 00000000..b95f2ffe --- /dev/null +++ b/kobo/django/auth/migrations/0003_alter_user_username.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.20 on 2023-11-16 11:30 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('kobo_auth', '0002_auto_20220203_1511'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='username', + field=models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 255 characters or fewer. Letters, digits and @.+-_/ only.', max_length=255, unique=True, validators=[django.core.validators.RegexValidator('^[\\w.@+\\-/]+$', 'Enter a valid username. This value may contain only letters, numbers and @.+-_/ characters.', 'invalid')], verbose_name='username'), + ), + ] diff --git a/kobo/django/auth/models.py b/kobo/django/auth/models.py index aa4d05ca..01b12d0a 100644 --- a/kobo/django/auth/models.py +++ b/kobo/django/auth/models.py @@ -18,12 +18,12 @@ class User(AbstractBaseUser, PermissionsMixin): Username, password and email are required. Other fields are optional. """ username = models.CharField(_('username'), max_length=MAX_LENGTH, unique=True, - help_text=_('Required. %s characters or fewer. Letters, digits and @/./+/-/_ only.' % MAX_LENGTH), + help_text=_('Required. %s characters or fewer. Letters, digits and @.+-_/ only.' % MAX_LENGTH), validators=[ - validators.RegexValidator(r'^[\w.@+-]+$', + validators.RegexValidator(r'^[\w.@+\-/]+$', _('Enter a valid username. ' 'This value may contain only letters, numbers ' - 'and @/./+/-/_ characters.'), 'invalid'), + 'and @.+-_/ characters.'), 'invalid'), ], error_messages={ 'unique': _("A user with that username already exists."),