Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulkimport #11779

Merged
merged 8 commits into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading