Create group if not in DB
santigandolfo opened this issue · 6 comments
santigandolfo commented
Currently if a group from the user_identity
and a Group.DoesNotExist
is thrown, then the group is skipped.
groups = []
for group_name in user["user_identity"][group_attribute]:
# Group names can optionally be mapped to different names in Django
if group_map and group_name in group_map:
group_name_django = group_map[group_name]
else:
group_name_django = group_name
try:
groups.append(Group.objects.get(name=group_name_django))
except Group.DoesNotExist:
pass
It would be nice to have a setting 'CREATE_GROUPS': True,
(similar to CREATE_USER
) that instead would let us create the group and add it to the list:
groups = []
for group_name in user["user_identity"][group_attribute]:
# Group names can optionally be mapped to different names in Django
if group_map and group_name in group_map:
group_name_django = group_map[group_name]
else:
group_name_django = group_name
try:
groups.append(Group.objects.get(name=group_name_django))
except Group.DoesNotExist:
should_create_new_groups = dictor(saml2_auth_settings, "CREATE_GROUPS", False)
if should_create_new_groups:
groups.append(Group.objects.create(name=group_name_django))
mostafa commented
Hey @santigandolfo,
Would you create a PR for this and include some tests?
santigandolfo commented
mostafa commented
Thanks for your contribution! I merged the PR after fixing the tests. It'll be released in the next release, v3.11.0.
santigandolfo commented
Hi @mostafa , do you have any ETA on when we will have release 3.11.0
?
mostafa commented
Hey @santigandolfo,
I was hoping I can add tests with mock IdP (#187), yet it seems to be a bigger task than I initially anticipated. So, I'll release the new version without the test today.