get_object_from_key: Make mark_object_used an obligatory kwarg.

This commit is contained in:
Mateusz Mandera 2022-07-21 15:26:09 +02:00 committed by Tim Abbott
parent dcc03a453a
commit f787ddc7d2
3 changed files with 5 additions and 3 deletions

View File

@ -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.

View File

@ -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

View File

@ -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)