Skip to content

Commit

Permalink
fix group creation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeriox committed Dec 12, 2023
1 parent ecfc008 commit b1de989
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion myhpi/core/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ def _update_groups(self, user, claims):
group_names = claims.get("roles", [])
groups = set()
for group in group_names:
groups.add(Group.objects.get_or_create(name__iexact=group)[0])
try:
# djangos get_or_create does not work with __iexact, therefore using try/catch
groups.add(Group.objects.get(name__iexact=group))
except Group.DoesNotExist:
groups.add(Group.objects.create(name=group))
user.groups.set(groups)

def create_user(self, claims):
Expand Down

0 comments on commit b1de989

Please sign in to comment.