Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
zerver: Migrate several small files to typed_endpoint.
Kenneth Rodriguesfe2097fd26bd
diff --git a/zerver/views/development/dev_login.py b/zerver/views/development/dev_login.pyindex c648cb2ed2f..019067da97d 100644--- a/zerver/views/development/dev_login.py+++ b/zerver/views/development/dev_login.py@@ -15,9 +15,9 @@ from zerver.lib.exceptions import (RealmDeactivatedError,UserDeactivatedError,)-from zerver.lib.request import REQ, has_request_variablesfrom zerver.lib.response import json_successfrom zerver.lib.subdomains import get_subdomain+from zerver.lib.typed_endpoint import typed_endpointfrom zerver.lib.users import get_api_keyfrom zerver.lib.validator import validate_login_emailfrom zerver.models import Realm, UserProfile@@ -66,10 +66,11 @@ def add_dev_login_context(realm: Optional[Realm], context: Dict[str, Any]) -> No@csrf_exempt-@has_request_variables+@typed_endpointdef dev_direct_login(request: HttpRequest,- next: str = REQ(default="/"),+ *,+ next: str = "/",) -> HttpResponse:# This function allows logging in without a password and should only be called# in development environments. It may be called if the DevAuthBackend is included@@ -106,8 +107,8 @@ def check_dev_auth_backend() -> None:@csrf_exempt@require_post-@has_request_variables-def api_dev_fetch_api_key(request: HttpRequest, username: str = REQ()) -> HttpResponse:+@typed_endpoint+def api_dev_fetch_api_key(request: HttpRequest, *, username: str) -> HttpResponse:"""This function allows logging in without a password on the Zulipmobile apps when connecting to a Zulip development environment. Itrequires DevAuthBackend to be included in settings.AUTHENTICATION_BACKENDS.diff --git a/zerver/views/submessage.py b/zerver/views/submessage.pyindex f28bc7e2369..2d2244fa93b 100644--- a/zerver/views/submessage.py+++ b/zerver/views/submessage.py@@ -3,26 +3,28 @@ from django.core.exceptions import ValidationErrorfrom django.db import transactionfrom django.http import HttpRequest, HttpResponsefrom django.utils.translation import gettext as _+from pydantic import Jsonfrom zerver.actions.submessage import do_add_submessage, verify_submessage_senderfrom zerver.lib.exceptions import JsonableErrorfrom zerver.lib.message import access_message-from zerver.lib.request import REQ, has_request_variablesfrom zerver.lib.response import json_success-from zerver.lib.validator import check_int, validate_poll_data, validate_todo_data+from zerver.lib.typed_endpoint import typed_endpoint+from zerver.lib.validator import validate_poll_data, validate_todo_datafrom zerver.lib.widget import get_widget_typefrom zerver.models import UserProfile# transaction.atomic is required since we use FOR UPDATE queries in access_message.@transaction.atomic-@has_request_variables+@typed_endpointdef process_submessage(request: HttpRequest,user_profile: UserProfile,- message_id: int = REQ(json_validator=check_int),- msg_type: str = REQ(),- content: str = REQ(),+ *,+ message_id: Json[int],+ msg_type: str,+ content: str,) -> HttpResponse:message = access_message(user_profile, message_id, lock_message=True)diff --git a/zerver/views/thumbnail.py b/zerver/views/thumbnail.pyindex c4213605926..824a6ed3826 100644--- a/zerver/views/thumbnail.py+++ b/zerver/views/thumbnail.py@@ -7,8 +7,8 @@ from django.utils.translation import gettext as _from zerver.context_processors import get_valid_realm_from_requestfrom zerver.lib.attachments import validate_attachment_request-from zerver.lib.request import REQ, has_request_variablesfrom zerver.lib.thumbnail import generate_thumbnail_url+from zerver.lib.typed_endpoint import typed_endpointfrom zerver.models import Realm, UserProfile@@ -27,12 +27,13 @@ def validate_thumbnail_request(return True-@has_request_variables+@typed_endpointdef backend_serve_thumbnail(request: HttpRequest,maybe_user_profile: Union[UserProfile, AnonymousUser],- url: str = REQ(),- size_requested: str = REQ("size"),+ *,+ url: str,+ size: str,) -> HttpResponse:if not maybe_user_profile.is_authenticated:realm = get_valid_realm_from_request(request)diff --git a/zerver/views/tutorial.py b/zerver/views/tutorial.pyindex 739efa73fe9..e5745147d0c 100644--- a/zerver/views/tutorial.py+++ b/zerver/views/tutorial.py@@ -1,15 +1,16 @@from django.http import HttpRequest, HttpResponse+from typing_extensions import Literalfrom zerver.decorator import human_users_only-from zerver.lib.request import REQ, has_request_variablesfrom zerver.lib.response import json_success+from zerver.lib.typed_endpoint import typed_endpointfrom zerver.models import UserProfile@human_users_only-@has_request_variables+@typed_endpointdef set_tutorial_status(- request: HttpRequest, user_profile: UserProfile, status: str = REQ()+ request: HttpRequest, user_profile: UserProfile, *, status: Literal["started", "finished"]) -> HttpResponse:if status == "started":user_profile.tutorial_status = UserProfile.TUTORIAL_STARTEDdiff --git a/zerver/views/zephyr.py b/zerver/views/zephyr.pyindex cd2d348376a..40d8a1a7034 100644--- a/zerver/views/zephyr.py+++ b/zerver/views/zephyr.py@@ -15,8 +15,8 @@ from zerver.decorator import authenticated_json_viewfrom zerver.lib.ccache import make_ccachefrom zerver.lib.exceptions import JsonableErrorfrom zerver.lib.pysa import mark_sanitized-from zerver.lib.request import REQ, has_request_variablesfrom zerver.lib.response import json_success+from zerver.lib.typed_endpoint import typed_endpointfrom zerver.lib.users import get_api_keyfrom zerver.models import UserProfile@@ -28,9 +28,9 @@ kerberos_alter_egos = {@authenticated_json_view-@has_request_variables+@typed_endpointdef webathena_kerberos_login(- request: HttpRequest, user_profile: UserProfile, cred: Optional[str] = REQ(default=None)+ request: HttpRequest, user_profile: UserProfile, *, cred: Optional[str] = None) -> HttpResponse:if cred is None:raise JsonableError(_("Could not find Kerberos credential"))