mirror of https://github.com/zulip/zulip.git
confirmation: Use the correct type hints for create_confirmation_link.
Previously we annotate the first argument as `ContentType`, which is wrong as suggested by django-stubs.
This commit is contained in:
parent
beadb5ec7f
commit
cf8687662f
|
@ -16,10 +16,19 @@ from django.http import HttpRequest, HttpResponse
|
|||
from django.shortcuts import render
|
||||
from django.urls import reverse
|
||||
from django.utils.timezone import now as timezone_now
|
||||
from typing_extensions import Protocol
|
||||
|
||||
from zerver.models import EmailChangeStatus, MultiuseInvite, PreregistrationUser, Realm, UserProfile
|
||||
|
||||
|
||||
class HasRealmObject(Protocol):
|
||||
realm: Realm
|
||||
|
||||
|
||||
class OptionalHasRealmObject(Protocol):
|
||||
realm: Optional[Realm]
|
||||
|
||||
|
||||
class ConfirmationKeyException(Exception):
|
||||
WRONG_LENGTH = 1
|
||||
EXPIRED = 2
|
||||
|
@ -74,14 +83,16 @@ def get_object_from_key(
|
|||
|
||||
|
||||
def create_confirmation_link(
|
||||
obj: ContentType, confirmation_type: int, url_args: Mapping[str, str] = {}
|
||||
obj: Union[Realm, HasRealmObject, OptionalHasRealmObject],
|
||||
confirmation_type: int,
|
||||
url_args: Mapping[str, str] = {},
|
||||
) -> str:
|
||||
key = generate_key()
|
||||
realm = None
|
||||
if hasattr(obj, "realm"):
|
||||
realm = obj.realm
|
||||
elif isinstance(obj, Realm):
|
||||
if isinstance(obj, Realm):
|
||||
realm = obj
|
||||
elif hasattr(obj, "realm"):
|
||||
realm = obj.realm
|
||||
|
||||
Confirmation.objects.create(
|
||||
content_object=obj,
|
||||
|
|
|
@ -112,7 +112,7 @@ def create_preregistration_user(
|
|||
password_required: bool = True,
|
||||
full_name: Optional[str] = None,
|
||||
full_name_validated: bool = False,
|
||||
) -> HttpResponse:
|
||||
) -> PreregistrationUser:
|
||||
realm = None
|
||||
if not realm_creation:
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue