Skip to content

Commit

Permalink
cleanup and small improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
lme-nca committed Mar 15, 2024
1 parent 49412f1 commit 91306ae
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
5 changes: 3 additions & 2 deletions dojo/group/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib.auth.models import Group
from django.db.models.signals import post_save, post_delete
from django.dispatch import receiver
from dojo.models import Dojo_Group, Dojo_Group_Member, Role
from dojo.models import Dojo_Group, Dojo_Group_Member, Role, Dojo_User
from django.conf import settings

Check notice on line 6 in dojo/group/utils.py

View workflow job for this annotation

GitHub Actions / flake8-your-pr

dojo/group/utils.py#L6

'django.conf.settings' imported but unused (F401)


Expand Down Expand Up @@ -41,7 +41,8 @@ def group_post_save_handler(sender, **kwargs):
group.save()

user = get_current_user()
if user and not settings.AZUREAD_TENANT_OAUTH2_GET_GROUPS and not settings.KEYCLOAK_TENANT_OAUTH2_GET_GROUPS:
if user and isinstance(user, Dojo_User):
#if user and not settings.AZUREAD_TENANT_OAUTH2_GET_GROUPS and not settings.KEYCLOAK_TENANT_OAUTH2_GET_GROUPS:

Check notice on line 45 in dojo/group/utils.py

View workflow job for this annotation

GitHub Actions / flake8-your-pr

dojo/group/utils.py#L45

expected an indented block (comment) (E115)

Check notice on line 45 in dojo/group/utils.py

View workflow job for this annotation

GitHub Actions / flake8-your-pr

dojo/group/utils.py#L45

block comment should start with '# ' (E265)
# Add the current user as the owner of the group
member = Dojo_Group_Member()
member.user = user
Expand Down
6 changes: 1 addition & 5 deletions dojo/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,11 @@ def modify_permissions(backend, uid, user=None, social=None, *args, **kwargs):

def update_keycloak_groups(backend, uid, user=None, social=None, *args, **kwargs):
if settings.KEYCLOAK_OAUTH2_ENABLED and settings.KEYCLOAK_TENANT_OAUTH2_GET_GROUPS and isinstance(backend, OpenIdConnectAuth):
soc = user.social_auth.order_by("-created").first()
token = soc.extra_data['access_token']
#print("accesstoken: " + str(token))
#print("response raw: " + str(kwargs['response']))
group_names = []
if 'groups' not in kwargs['response'] or kwargs['response']['groups'] == "":
logger.warning("No groups in response. Stopping to update groups of user based on azureAD")
return
group_ids = kwargs['response']['groups'] # probably need another setting with a regex ?
group_ids = kwargs['response']['groups']
for group_from_response in group_ids:
if settings.KEYCLOAK_TENANT_OAUTH2_GROUPS_FILTER == "" or re.search(settings.KEYCLOAK_TENANT_OAUTH2_GROUPS_FILTER, group_from_response):
group_names.append(group_from_response)
Expand Down

0 comments on commit 91306ae

Please sign in to comment.