From 56eaf6c12ed6dff11ef30424f382d95f0aebac97 Mon Sep 17 00:00:00 2001 From: Martin Vlach Date: Tue, 27 Feb 2024 15:57:03 +0100 Subject: [PATCH 1/2] fix unhandled case of expired invitation in multiple-send --- invitations/views.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/invitations/views.py b/invitations/views.py index f98735f..8950049 100644 --- a/invitations/views.py +++ b/invitations/views.py @@ -71,6 +71,11 @@ def post(self, request, *args, **kwargs): try: validate_email(invitee) CleanEmailMixin().validate_invitation(invitee) + # ^as a read-only check it does not change old entries as needed: + invalid_invitations = Invitation.objects.all().exclude(pk__in=Invitation.objects.all_valid()) + target_invitation = invalid_invitations.filter(email__iexact=invitee) + if target_invitation: + target_invitation.get().delete() # will work as the email is unique invite = Invitation.create(invitee) except (ValueError, KeyError): pass From 2e0ac68515d20eeb90f28421c2241e94e1bc6d60 Mon Sep 17 00:00:00 2001 From: Martin Vlach Date: Tue, 27 Feb 2024 17:26:20 +0100 Subject: [PATCH 2/2] fix formatting --- invitations/views.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/invitations/views.py b/invitations/views.py index 8950049..9a6020a 100644 --- a/invitations/views.py +++ b/invitations/views.py @@ -72,10 +72,14 @@ def post(self, request, *args, **kwargs): validate_email(invitee) CleanEmailMixin().validate_invitation(invitee) # ^as a read-only check it does not change old entries as needed: - invalid_invitations = Invitation.objects.all().exclude(pk__in=Invitation.objects.all_valid()) - target_invitation = invalid_invitations.filter(email__iexact=invitee) + invalid_invitations = Invitation.objects.all().exclude( + pk__in=Invitation.objects.all_valid() + ) + target_invitation = invalid_invitations.filter( + email__iexact=invitee + ) if target_invitation: - target_invitation.get().delete() # will work as the email is unique + target_invitation.get().delete() # email is unique, .get works invite = Invitation.create(invitee) except (ValueError, KeyError): pass