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

Create group if not in DB #189

Closed
santigandolfo opened this issue Jul 14, 2023 · 6 comments · Fixed by #191
Closed

Create group if not in DB #189

santigandolfo opened this issue Jul 14, 2023 · 6 comments · Fixed by #191
Labels
enhancement New feature or request

Comments

@santigandolfo
Copy link
Contributor

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
Copy link
Member

mostafa commented Jul 17, 2023

Hey @santigandolfo,

Would you create a PR for this and include some tests?

@mostafa mostafa added the enhancement New feature or request label Jul 17, 2023
@santigandolfo
Copy link
Contributor Author

Hi @mostafa, done!
#191

@mostafa mostafa linked a pull request Jul 18, 2023 that will close this issue
@mostafa
Copy link
Member

mostafa commented Jul 18, 2023

@santigandolfo

Thanks for your contribution! I merged the PR after fixing the tests. It'll be released in the next release, v3.11.0.

@santigandolfo
Copy link
Contributor Author

Hi @mostafa , do you have any ETA on when we will have release 3.11.0?

@mostafa
Copy link
Member

mostafa commented Jul 31, 2023

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.

@mostafa
Copy link
Member

mostafa commented Jul 31, 2023

@santigandolfo

I just released v3.11.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants