forked from learningequality/kolibri
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request learningequality#11425 from jredrejo/allow_email_i…
…n_usernames Allow email in usernames
- Loading branch information
Showing
5 changed files
with
117 additions
and
10 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
kolibri/core/auth/migrations/0024_extend_username_length.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.29 on 2023-10-17 17:51 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
from django.db import models | ||
|
||
import kolibri.core.auth.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("kolibriauth", "0023_change_extra_fields_validator"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="facilityuser", | ||
name="username", | ||
field=models.CharField( | ||
help_text="Required. 254 characters or fewer.", | ||
max_length=254, | ||
validators=[kolibri.core.auth.models.validate_username], | ||
verbose_name="username", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -751,6 +751,32 @@ def test_creating_user_same_username_case_insensitive(self): | |
response.data[0]["id"], error_constants.USERNAME_ALREADY_EXISTS | ||
) | ||
|
||
def test_do_not_allow_emails_in_usernames(self): | ||
data = { | ||
"username": "[email protected]", | ||
"password": DUMMY_PASSWORD, | ||
"facility": self.facility.id, | ||
} | ||
response = self.client.post( | ||
reverse("kolibri:core:facilityuser-list"), data, format="json" | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | ||
self.assertEqual(response.data[0]["id"], error_constants.INVALID) | ||
self.assertEqual(response.data[0]["metadata"]["field"], "username") | ||
|
||
def test_max_length_username_in_api(self): | ||
data = { | ||
"username": 32 * "gh", | ||
"password": DUMMY_PASSWORD, | ||
"facility": self.facility.id, | ||
} | ||
response = self.client.post( | ||
reverse("kolibri:core:facilityuser-list"), data, format="json" | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | ||
self.assertEqual(response.data[0]["id"], error_constants.MAX_LENGTH) | ||
self.assertEqual(response.data[0]["metadata"]["field"], "username") | ||
|
||
|
||
class UserUpdateTestCase(APITestCase): | ||
@classmethod | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -680,6 +680,26 @@ def test_deserialize_empty_password(self): | |
self.assertEqual("bob", user.username) | ||
self.assertEqual(NOT_SPECIFIED, user.password) | ||
|
||
def test_username_validation(self): | ||
self.facility = Facility.objects.create() | ||
self.device_settings = DeviceSettings.objects.create() | ||
user1 = FacilityUser.objects.create( | ||
username="[email protected]", | ||
password="password", | ||
facility=self.facility, | ||
) | ||
user1.full_clean() | ||
user2 = FacilityUser.objects.create( | ||
username="@bob", password="password", facility=self.facility | ||
) | ||
with self.assertRaises(ValidationError): | ||
user2.full_clean() | ||
user3 = FacilityUser.objects.create( | ||
username=32 * "gh", password="password", facility=self.facility | ||
) | ||
with self.assertRaises(ValidationError): | ||
user3.full_clean() | ||
|
||
|
||
class CollectionHierarchyTestCase(TestCase): | ||
def test_facility_with_parent(self): | ||
|