Skip to content

Commit

Permalink
inclusion_connect: Improve FT agent login
Browse files Browse the repository at this point in the history
Don't crash if they signed-up as employer (just don't update the
prescriber memberships)
  • Loading branch information
tonial committed Oct 3, 2024
1 parent 22dfb9f commit a7a78cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion itou/openid_connect/inclusion_connect/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def inclusion_connect_callback(request):

code_safir_pole_emploi = user_data.get("structure_pe")
# Only handle user creation for the moment, not updates.
if is_successful and code_safir_pole_emploi:
if is_successful and user.is_prescriber and code_safir_pole_emploi:
try:
ic_user_data.join_org(user=user, safir=code_safir_pole_emploi)
except PrescriberOrganization.DoesNotExist:
Expand Down
11 changes: 11 additions & 0 deletions tests/openid_connect/inclusion_connect/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,17 @@ def test_callback_update_FT_organization(self):
)
self.assertQuerySetEqual(org.members.all(), [user])

@respx.mock
def test_callback_update_FT_organization_employer_does_not_crash(self):
mock_oauth_dance(
self.client,
UserKind.EMPLOYER,
oidc_userinfo=OIDC_USERINFO_FT_WITH_SAFIR.copy(),
)
user = get_user(self.client)
assert user.is_authenticated
assert not user.prescribermembership_set.exists()

@respx.mock
def test_callback_ft_users_with_no_org(self):
PrescriberFactory(**dataclasses.asdict(InclusionConnectPrescriberData.from_user_info(OIDC_USERINFO)))
Expand Down

0 comments on commit a7a78cb

Please sign in to comment.