Skip to content

Commit

Permalink
fix for participant selection on login
Browse files Browse the repository at this point in the history
  • Loading branch information
bbonf committed Sep 24, 2024
1 parent 02acadf commit 8d87568
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
19 changes: 19 additions & 0 deletions integration_tests/test_parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,22 @@ def test_parent_login_expired(participant, apps, page, link_from_mail, login_as)
expect(page.get_by_text('verlopen')).to_be_visible()

expect(page.get_by_text('Appointments')).not_to_be_visible()


def test_parent_login_multiple_children(participant, apps, page, login_as):
first = participant
Participant = apps.lab.get_model("participants", "Participant")
second = Participant.objects.create(
email=first.email,
name="BabyTwo McBaby",
parent_first_name=first.parent_first_name,
parent_last_name=first.parent_last_name,
birth_date=datetime.date(2023, 1, 1),
phonenumber=first.phonenumber,
dyslexic_parent=first.dyslexic_parent,
email_subscription=True,
)
assert login_as(first.email) is True
page.locator('a').get_by_text(first.name).click()
page.wait_for_url('**/overview')
expect(page.locator('.alert-error')).to_have_count(0)
5 changes: 4 additions & 1 deletion lab/mailauth/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from datetime import timedelta

import jwt
from django.conf import settings
from django.utils import timezone, translation
from django.utils.translation import gettext as _
from rest_framework import exceptions, views
Expand Down Expand Up @@ -64,6 +66,7 @@ def post(self, request, *args, **kwargs):
except Exception:
raise exceptions.PermissionDenied()

if resolve_participant(token, request.data["participant_id"]):
decoded = jwt.decode(token, settings.JWT_SECRET, algorithms=[settings.JWT_ALGORITHM])
if resolve_participant(decoded["session"], request.data["participant_id"]):
return Response(dict())
raise exceptions.PermissionDenied()

0 comments on commit 8d87568

Please sign in to comment.