From 6a113e72bebc71c1db25865456535b54e0223679 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 13 Dec 2024 10:37:05 +0100 Subject: [PATCH 1/2] include token in confirmation mail cancel link --- api/utils/appointment_mail.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/api/utils/appointment_mail.py b/api/utils/appointment_mail.py index ec9bcb3..4491a6f 100644 --- a/api/utils/appointment_mail.py +++ b/api/utils/appointment_mail.py @@ -5,6 +5,7 @@ from experiments.emails import ConfirmationEmail +from api.auth.models import UserToken from experiments.models import Experiment, TimeSlot from participants.models import Participant @@ -19,10 +20,6 @@ def get_initial_confirmation_context(experiment: Experiment) -> dict: 'leader_email': experiment.leader.api_user.email, 'leader_phonenumber': experiment.leader.phonenumber, 'all_leaders_name_list': experiment.all_leaders_str, - 'cancel_link': parse.urljoin( - settings.FRONTEND_URI, - 'participant/cancel/' - ), } if experiment.location: @@ -42,9 +39,20 @@ def send_appointment_mail( if participant.email is None: return + # create login token for cancelation link + token = UserToken.objects.create( + participant=participant, + type=UserToken.CANCEL_APPOINTMENTS, + ) + cancel_link = parse.urljoin( + settings.FRONTEND_URI, + "participant/appointments/{}/".format(token.token) + ) + context = get_initial_confirmation_context(experiment) context.update({ 'name': participant.mail_name, + 'cancel_link': cancel_link }) if experiment.use_timeslots: @@ -65,4 +73,3 @@ def send_appointment_mail( context=context, ) email.send() - From 6fb6c8ad16ed0e225a7433e64ee9799a32876aa6 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 13 Dec 2024 11:28:04 +0100 Subject: [PATCH 2/2] sort appointments by date --- api/views/participant_views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/views/participant_views.py b/api/views/participant_views.py index ec21c94..6d15c3d 100644 --- a/api/views/participant_views.py +++ b/api/views/participant_views.py @@ -288,4 +288,4 @@ def _get_participant(self): raise PermissionDenied def get_queryset(self): - return Appointment.objects.filter(participant=self._get_participant()) + return Appointment.objects.filter(participant=self._get_participant()).order_by('-timeslot__datetime')