Skip to content

Commit

Permalink
Move other data on batch add user to group when just create user (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
meomancer authored Aug 12, 2024
1 parent 4c42857 commit 15bf58b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions django_project/core/api/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,8 @@ def post(self, request, pk):
for idx, row in enumerate(list(reader)):
try:
data = {
'first_name': row['First name'],
'last_name': row['Last name'],
'email': row['Email address']
}
role = row['Role']
try:
# If azure, use email instead
if settings.USE_AZURE:
Expand All @@ -146,11 +143,16 @@ def post(self, request, pk):
user = User.objects.get(username=username)
user.groups.add(group)
except User.DoesNotExist:
data.update({
'first_name': row['First name'],
'last_name': row['Last name'],
})
user, _ = User.objects.get_or_create(
username=data['username'],
defaults=data
)
try:
role = row['Role']
Profile.update_role(user=user, role=role)
except RoleDoesNotFound:
raise RoleDoesNotFound(
Expand Down

0 comments on commit 15bf58b

Please sign in to comment.