Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
typing_notifications: Do op validation in view function.
Dineshddca602123f5
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.pyindex 8c2315ab074..cfcd93767f5 100644--- a/zerver/lib/actions.py+++ b/zerver/lib/actions.py@@ -2238,8 +2238,6 @@ def check_send_typing_notification(sender: UserProfile, user_ids: List[int], operealm = sender.realmif len(user_ids) == 0:raise JsonableError(_("Missing parameter: 'to' (recipient)"))- elif operator not in ("start", "stop"):- raise JsonableError(_("Invalid 'op' value (should be start or stop)"))""" The next chunk of code will go away when we upgrade old mobileusers away from versions of mobile that send emails. For thediff --git a/zerver/tests/test_typing.py b/zerver/tests/test_typing.pyindex 3ed9d6be768..da20b73803e 100644--- a/zerver/tests/test_typing.py+++ b/zerver/tests/test_typing.py@@ -29,7 +29,7 @@ class TypingValidateOperatorTest(ZulipTestCase):op="foo",)result = self.api_post(sender, "/api/v1/typing", params)- self.assert_json_error(result, "Invalid 'op' value (should be start or stop)")+ self.assert_json_error(result, "Invalid op")class TypingValidateUsersTest(ZulipTestCase):diff --git a/zerver/views/typing.py b/zerver/views/typing.pyindex d1eb6912346..de0af3d34ab 100644--- a/zerver/views/typing.py+++ b/zerver/views/typing.py@@ -5,15 +5,17 @@ from django.http import HttpRequest, HttpResponsefrom zerver.decorator import REQ, has_request_variablesfrom zerver.lib.actions import check_send_typing_notificationfrom zerver.lib.response import json_success-from zerver.lib.validator import check_int, check_list+from zerver.lib.validator import check_int, check_list, check_string_infrom zerver.models import UserProfile+VALID_OPERATOR_TYPES = ["start", "stop"]+@has_request_variablesdef send_notification_backend(request: HttpRequest,user_profile: UserProfile,- operator: str = REQ("op"),+ operator: str = REQ("op", str_validator=check_string_in(VALID_OPERATOR_TYPES)),notification_to: List[int] = REQ("to", validator=check_list(check_int)),) -> HttpResponse:check_send_typing_notification(user_profile, notification_to, operator)