mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 18:36:36 +00:00
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:
@@ -16,10 +16,19 @@ from django.http import HttpRequest, HttpResponse
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.timezone import now as timezone_now
|
from django.utils.timezone import now as timezone_now
|
||||||
|
from typing_extensions import Protocol
|
||||||
|
|
||||||
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
|
||||||
@@ -74,14 +83,16 @@ def get_object_from_key(
|
|||||||
|
|
||||||
|
|
||||||
def create_confirmation_link(
|
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:
|
) -> str:
|
||||||
key = generate_key()
|
key = generate_key()
|
||||||
realm = None
|
realm = None
|
||||||
if hasattr(obj, "realm"):
|
if isinstance(obj, Realm):
|
||||||
realm = obj.realm
|
|
||||||
elif isinstance(obj, Realm):
|
|
||||||
realm = obj
|
realm = obj
|
||||||
|
elif hasattr(obj, "realm"):
|
||||||
|
realm = obj.realm
|
||||||
|
|
||||||
Confirmation.objects.create(
|
Confirmation.objects.create(
|
||||||
content_object=obj,
|
content_object=obj,
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ def create_preregistration_user(
|
|||||||
password_required: bool = True,
|
password_required: bool = True,
|
||||||
full_name: Optional[str] = None,
|
full_name: Optional[str] = None,
|
||||||
full_name_validated: bool = False,
|
full_name_validated: bool = False,
|
||||||
) -> HttpResponse:
|
) -> PreregistrationUser:
|
||||||
realm = None
|
realm = None
|
||||||
if not realm_creation:
|
if not realm_creation:
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user