From f787ddc7d2224eada3d3a197aa80d5029b999891 Mon Sep 17 00:00:00 2001 From: Mateusz Mandera Date: Thu, 21 Jul 2022 15:26:09 +0200 Subject: [PATCH] get_object_from_key: Make mark_object_used an obligatory kwarg. --- confirmation/models.py | 2 +- zerver/tests/test_signup.py | 2 +- zerver/views/user_settings.py | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/confirmation/models.py b/confirmation/models.py index ed22f97809..add4fcec32 100644 --- a/confirmation/models.py +++ b/confirmation/models.py @@ -50,7 +50,7 @@ ConfirmationObjT = Union[MultiuseInvite, PreregistrationUser, EmailChangeStatus, def get_object_from_key( - confirmation_key: str, confirmation_types: List[int], mark_object_used: bool = True + confirmation_key: str, confirmation_types: List[int], *, mark_object_used: bool ) -> ConfirmationObjT: """Access a confirmation object from one of the provided confirmation types with the provided key. diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py index 67fe4d4ff5..20454f1923 100644 --- a/zerver/tests/test_signup.py +++ b/zerver/tests/test_signup.py @@ -2123,7 +2123,7 @@ so we didn't send them an invitation. We did send invitations to everyone else!" # Mainly a test of get_object_from_key, rather than of the invitation pathway with self.assertRaises(ConfirmationKeyException) as cm: - get_object_from_key(registration_key, [Confirmation.INVITATION]) + get_object_from_key(registration_key, [Confirmation.INVITATION], mark_object_used=True) self.assertEqual(cm.exception.error_type, ConfirmationKeyException.DOES_NOT_EXIST) # Verify that using the wrong type doesn't work in the main confirm code path diff --git a/zerver/views/user_settings.py b/zerver/views/user_settings.py index d526d541f1..e12e9af1a2 100644 --- a/zerver/views/user_settings.py +++ b/zerver/views/user_settings.py @@ -62,7 +62,9 @@ AVATAR_CHANGES_DISABLED_ERROR = gettext_lazy("Avatar changes are disabled in thi def confirm_email_change(request: HttpRequest, confirmation_key: str) -> HttpResponse: try: - email_change_object = get_object_from_key(confirmation_key, [Confirmation.EMAIL_CHANGE]) + email_change_object = get_object_from_key( + confirmation_key, [Confirmation.EMAIL_CHANGE], mark_object_used=True + ) except ConfirmationKeyException as exception: return render_confirmation_key_error(request, exception)