confirmation: Allow using used confirmation objects if required.

This commit is contained in:
Aman Agrawal 2024-11-13 13:23:52 +05:30
parent 1f1beb1452
commit 1253686287
1 changed files with 8 additions and 1 deletions

View File

@ -81,7 +81,11 @@ ConfirmationObjT: TypeAlias = NoZilencerConfirmationObjT | ZilencerConfirmationO
def get_object_from_key(
confirmation_key: str, confirmation_types: list[int], *, mark_object_used: bool
confirmation_key: str,
confirmation_types: list[int],
*,
mark_object_used: bool,
allow_used: bool = False,
) -> ConfirmationObjT:
"""Access a confirmation object from one of the provided confirmation
types with the provided key.
@ -109,6 +113,9 @@ def get_object_from_key(
assert obj is not None
used_value = confirmation_settings.STATUS_USED
if allow_used and obj.status == used_value:
return obj
revoked_value = confirmation_settings.STATUS_REVOKED
if hasattr(obj, "status") and obj.status in [used_value, revoked_value]:
# Confirmations where the object has the status attribute are one-time use