Skip to content

Commit

Permalink
fix:import-duplicate-usernames
Browse files Browse the repository at this point in the history
  • Loading branch information
nick2432 committed Feb 24, 2024
1 parent a49730d commit 2de4f18
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion kolibri/core/auth/management/commands/bulkimportusers.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ def get_username(self, row):
lowercase_username = username.lower()

# Check if a user with the provided username exists (case-insensitive)
existing_user = FacilityUser.objects.filter(username__iexact=lowercase_username).first()
existing_user = FacilityUser.objects.filter(
username__iexact=lowercase_username
).first()
# Convert existing keys in self.users to lowercase
if existing_user and uuid == "":
return None # Duplicate username
Expand Down
5 changes: 3 additions & 2 deletions kolibri/core/auth/test/test_bulk_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def test_password_is_required(self):
assert "'value': '*'" in result[1]
assert "new_coach" in result[1]
assert "'row': 2" in result[1]

def test_case_insensitive_usernames(self):
_, first_filepath = tempfile.mkstemp(suffix=".csv")
rows = [
Expand Down Expand Up @@ -282,10 +283,10 @@ def test_case_insensitive_usernames(self):
]
self.create_csv(first_filepath, rows)
call_command("bulkimportusers", first_filepath, facility=self.facility.id)

# Retrieve the user(s)
users = FacilityUser.objects.filter(username__iexact="peter")

# Ensure that only one user is created, and it has the latest password
assert users.count() == 1

Expand Down

0 comments on commit 2de4f18

Please sign in to comment.