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.pyindex 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.pyindex 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 = Truetry:- 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_objif 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.pyindex 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) -> HttpResporealm = 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.pyindex 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] = Nonetry:- 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_objif realm != multiuse_object.realm:return render(request, "confirmation/link_does_not_exist.html", status=404)# Required for OAuth 2diff --git a/zerver/views/unsubscribe.py b/zerver/views/unsubscribe.pyindex 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)