Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

confirmation: Support more models as ConfirmationObjT.

Zixuan James Li0017f7a025e5
diff --git a/confirmation/models.py b/confirmation/models.py
index bf1492bd4af..87bf2522bbd 100644
--- a/confirmation/models.py
+++ b/confirmation/models.py
@@ -54,7 +54,7 @@ def generate_key() -> str:
return b32encode(secrets.token_bytes(15)).decode().lower()
-ConfirmationObjT = Union[MultiuseInvite, PreregistrationUser, EmailChangeStatus]
+ConfirmationObjT = Union[MultiuseInvite, PreregistrationUser, EmailChangeStatus, UserProfile, Realm]
def get_object_from_key(
diff --git a/zerver/views/auth.py b/zerver/views/auth.py
index 9b341cb76bc..7660497d338 100644
--- a/zerver/views/auth.py
+++ b/zerver/views/auth.py
@@ -190,11 +190,14 @@ def maybe_send_to_registration(
if multiuse_object_key:
from_multiuse_invite = True
try:
- multiuse_obj = get_object_from_key(multiuse_object_key, [Confirmation.MULTIUSE_INVITE])
+ confirmation_obj = get_object_from_key(
+ multiuse_object_key, [Confirmation.MULTIUSE_INVITE]
+ )
except ConfirmationKeyException as exception:
return render_confirmation_key_error(request, exception)
- assert multiuse_obj is not None
+ assert isinstance(confirmation_obj, MultiuseInvite)
+ multiuse_obj = confirmation_obj
if realm != multiuse_obj.realm:
return render(request, "confirmation/link_does_not_exist.html", status=404)
diff --git a/zerver/views/realm.py b/zerver/views/realm.py
index bd30f8f7cd8..acfee2e3e31 100644
--- a/zerver/views/realm.py
+++ b/zerver/views/realm.py
@@ -330,6 +330,7 @@ def realm_reactivation(request: HttpRequest, confirmation_key: str) -> HttpRespo
realm = get_object_from_key(confirmation_key, [Confirmation.REALM_REACTIVATION])
except ConfirmationKeyException:
return render(request, "zerver/realm_reactivation_link_error.html")
+ assert isinstance(realm, Realm)
do_reactivate_realm(realm)
context = {"realm": realm}
return render(request, "zerver/realm_reactivation.html", context)
diff --git a/zerver/views/registration.py b/zerver/views/registration.py
index ce051bd612c..4eb3dec543c 100644
--- a/zerver/views/registration.py
+++ b/zerver/views/registration.py
@@ -137,6 +137,7 @@ def check_prereg_key(request: HttpRequest, confirmation_key: str) -> Preregistra
]
prereg_user = get_object_from_key(confirmation_key, confirmation_types, activate_object=False)
+ assert isinstance(prereg_user, PreregistrationUser)
if prereg_user.status == confirmation_settings.STATUS_REVOKED:
raise ConfirmationKeyException(ConfirmationKeyException.EXPIRED)
@@ -741,9 +742,11 @@ def accounts_home(
def accounts_home_from_multiuse_invite(request: HttpRequest, confirmation_key: str) -> HttpResponse:
realm = get_realm_from_request(request)
- multiuse_object = None
+ multiuse_object: Optional[MultiuseInvite] = None
try:
- multiuse_object = get_object_from_key(confirmation_key, [Confirmation.MULTIUSE_INVITE])
+ confirmation_obj = get_object_from_key(confirmation_key, [Confirmation.MULTIUSE_INVITE])
+ assert isinstance(confirmation_obj, MultiuseInvite)
+ multiuse_object = confirmation_obj
if realm != multiuse_object.realm:
return render(request, "confirmation/link_does_not_exist.html", status=404)
# Required for OAuth 2
diff --git a/zerver/views/unsubscribe.py b/zerver/views/unsubscribe.py
index e1b0c31a760..3ede06d94c2 100644
--- a/zerver/views/unsubscribe.py
+++ b/zerver/views/unsubscribe.py
@@ -22,6 +22,7 @@ def process_unsubscribe(
except ConfirmationKeyException:
return render(request, "zerver/unsubscribe_link_error.html")
+ assert isinstance(user_profile, UserProfile)
unsubscribe_function(user_profile)
context = common_context(user_profile)
context.update(subscription_type=subscription_type)