mirror of
https://github.com/zulip/zulip.git
synced 2025-10-24 16:43:57 +00:00
confirmation: Fix the type annotation of create_confirmation_link.
Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
committed by
Tim Abbott
parent
0017f7a025
commit
66dd572563
@@ -4,7 +4,7 @@ __revision__ = "$Id: models.py 28 2009-10-22 15:03:02Z jarek.zgoda $"
|
|||||||
import datetime
|
import datetime
|
||||||
import secrets
|
import secrets
|
||||||
from base64 import b32encode
|
from base64 import b32encode
|
||||||
from typing import List, Mapping, Optional, Protocol, Union
|
from typing import List, Mapping, Optional, Union
|
||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -21,14 +21,6 @@ from zerver.lib.types import UnspecifiedValue
|
|||||||
from zerver.models import EmailChangeStatus, MultiuseInvite, PreregistrationUser, Realm, UserProfile
|
from zerver.models import EmailChangeStatus, MultiuseInvite, PreregistrationUser, Realm, UserProfile
|
||||||
|
|
||||||
|
|
||||||
class HasRealmObject(Protocol):
|
|
||||||
realm: Realm
|
|
||||||
|
|
||||||
|
|
||||||
class OptionalHasRealmObject(Protocol):
|
|
||||||
realm: Optional[Realm]
|
|
||||||
|
|
||||||
|
|
||||||
class ConfirmationKeyException(Exception):
|
class ConfirmationKeyException(Exception):
|
||||||
WRONG_LENGTH = 1
|
WRONG_LENGTH = 1
|
||||||
EXPIRED = 2
|
EXPIRED = 2
|
||||||
@@ -82,7 +74,7 @@ def get_object_from_key(
|
|||||||
|
|
||||||
|
|
||||||
def create_confirmation_link(
|
def create_confirmation_link(
|
||||||
obj: Union[Realm, HasRealmObject, OptionalHasRealmObject],
|
obj: ConfirmationObjT,
|
||||||
confirmation_type: int,
|
confirmation_type: int,
|
||||||
*,
|
*,
|
||||||
validity_in_minutes: Union[Optional[int], UnspecifiedValue] = UnspecifiedValue(),
|
validity_in_minutes: Union[Optional[int], UnspecifiedValue] = UnspecifiedValue(),
|
||||||
@@ -92,10 +84,10 @@ def create_confirmation_link(
|
|||||||
# determined by the confirmation_type - its main purpose is for use
|
# determined by the confirmation_type - its main purpose is for use
|
||||||
# in tests which may want to have control over the exact expiration time.
|
# in tests which may want to have control over the exact expiration time.
|
||||||
key = generate_key()
|
key = generate_key()
|
||||||
realm = None
|
realm: Optional[Realm]
|
||||||
if isinstance(obj, Realm):
|
if isinstance(obj, Realm):
|
||||||
realm = obj
|
realm = obj
|
||||||
elif hasattr(obj, "realm"):
|
else:
|
||||||
realm = obj.realm
|
realm = obj.realm
|
||||||
|
|
||||||
current_time = timezone_now()
|
current_time = timezone_now()
|
||||||
|
|||||||
Reference in New Issue
Block a user