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.

typing: Move to parameter validation to view code.

Tim Abbott08116a17b0df
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py
index 37b9c7d63c3..1c1dc814ab8 100644
--- a/zerver/lib/actions.py
+++ b/zerver/lib/actions.py
@@ -2234,10 +2234,7 @@ def do_send_typing_notification(
# check_send_typing_notification:
# Checks the typing notification and sends it
def check_send_typing_notification(sender: UserProfile, user_ids: List[int], operator: str) -> None:
-
realm = sender.realm
- if len(user_ids) == 0:
- raise JsonableError(_("Missing parameter: 'to' (recipient)"))
if sender.id not in user_ids:
user_ids.append(sender.id)
diff --git a/zerver/views/typing.py b/zerver/views/typing.py
index de0af3d34ab..a239375458e 100644
--- a/zerver/views/typing.py
+++ b/zerver/views/typing.py
@@ -1,10 +1,11 @@
from typing import List
from django.http import HttpRequest, HttpResponse
+from django.utils.translation import ugettext as _
from zerver.decorator import REQ, has_request_variables
from zerver.lib.actions import check_send_typing_notification
-from zerver.lib.response import json_success
+from zerver.lib.response import json_error, json_success
from zerver.lib.validator import check_int, check_list, check_string_in
from zerver.models import UserProfile
@@ -16,7 +17,10 @@ def send_notification_backend(
request: HttpRequest,
user_profile: UserProfile,
operator: str = REQ("op", str_validator=check_string_in(VALID_OPERATOR_TYPES)),
- notification_to: List[int] = REQ("to", validator=check_list(check_int)),
+ user_ids: List[int] = REQ("to", validator=check_list(check_int)),
) -> HttpResponse:
- check_send_typing_notification(user_profile, notification_to, operator)
+ if len(user_ids) == 0:
+ return json_error(_("Missing parameter: 'to' (recipient)"))
+
+ check_send_typing_notification(user_profile, user_ids, operator)
return json_success()