Skip to content

Commit

Permalink
Properly handle case insensitive matches for existing usernames in bu…
Browse files Browse the repository at this point in the history
…lkimport (#11779)
  • Loading branch information
nick2432 authored Feb 23, 2024
1 parent 401c1b6 commit 0f802b0
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions kolibri/core/auth/management/commands/bulkimportusers.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def compare_fields(self, user_obj, values):
setattr(user_obj, field, values[field])
return changed

def build_users_objects(self, users):
def build_users_objects(self, users): # noqa C901
new_users = []
update_users = []
keeping_users = []
Expand Down Expand Up @@ -564,7 +564,7 @@ def build_users_objects(self, users):
if user_obj.username != user:
# check for duplicated username in the facility
existing_user = FacilityUser.objects.get(
username=user, facility=self.default_facility
username__iexact=user, facility=self.default_facility
)
if existing_user:
error = {
Expand All @@ -579,6 +579,21 @@ def build_users_objects(self, users):
if self.compare_fields(user_obj, values):
update_users.append(user_obj)
else:
# If UUID is not specified, check for a username clash
if values["uuid"] == "":
existing_user = FacilityUser.objects.filter(
username__iexact=user, facility=self.default_facility
).first()
if existing_user:
error = {
"row": users[user]["position"],
"username": user,
"message": MESSAGES[DUPLICATED_USERNAME],
"field": "USERNAME",
"value": user,
}
per_line_errors.append(error)
continue
if values["uuid"] != "":
error = {
"row": users[user]["position"],
Expand Down

0 comments on commit 0f802b0

Please sign in to comment.