Skip to content

Commit

Permalink
Fix super-admin not having an organization
Browse files Browse the repository at this point in the history
  • Loading branch information
tudoramariei committed Oct 1, 2024
1 parent f4e74ab commit 5ff44d5
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions backend/redirectioneaza/social_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ def common_user_init(sociallogin: SocialLogin) -> UserModel:
raise ImmediateHttpResponse(redirect(reverse("error-app-missing")))

user_role: str = user_profile.role
ngohub_org_id: int = user_profile.organization.id

if not user.first_name:
user.first_name = user_profile.name
user.save()
Expand All @@ -98,7 +96,11 @@ def common_user_init(sociallogin: SocialLogin) -> UserModel:
if user_role == settings.NGOHUB_ROLE_SUPER_ADMIN:
# A super admin from NGO Hub will become a Django admin
user.groups.add(Group.objects.get(name=RESTRICTED_ADMIN))
elif user_role == settings.NGOHUB_ROLE_NGO_ADMIN:

return user

ngohub_org_id: int = user_profile.organization.id
if user_role == settings.NGOHUB_ROLE_NGO_ADMIN:
if not ngohub.check_user_organization_has_application(ngo_token=token, login_link=settings.BASE_WEBSITE):
_deactivate_ngo_and_users(ngohub_org_id)
raise ImmediateHttpResponse(redirect(reverse("error-app-missing")))
Expand All @@ -107,7 +109,10 @@ def common_user_init(sociallogin: SocialLogin) -> UserModel:
user.groups.add(Group.objects.get(name=NGO_ADMIN))

_connect_user_and_ngo(user, ngohub_org_id, token)
elif user_role == settings.NGOHUB_ROLE_NGO_EMPLOYEE:

return user

if user_role == settings.NGOHUB_ROLE_NGO_EMPLOYEE:
if not ngohub.check_user_organization_has_application(ngo_token=token, login_link=settings.BASE_WEBSITE):
user.deactivate()
raise ImmediateHttpResponse(redirect(reverse("error-app-missing")))
Expand All @@ -116,11 +121,11 @@ def common_user_init(sociallogin: SocialLogin) -> UserModel:
user.groups.add(Group.objects.get(name=NGO_MEMBER))

_connect_user_and_ngo(user, ngohub_org_id, token)
else:
# Unknown user role
raise ImmediateHttpResponse(redirect(reverse("error-unknown-user-role")))

return user
return user

# Unknown user role
raise ImmediateHttpResponse(redirect(reverse("error-unknown-user-role")))


def _connect_user_and_ngo(user, ngohub_org_id, token):
Expand Down

0 comments on commit 5ff44d5

Please sign in to comment.