From 08116a17b0dfec59b5eba7e97facb13fcad56309 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Thu, 1 Apr 2021 08:16:52 -0700 Subject: [PATCH] typing: Move to parameter validation to view code. --- zerver/lib/actions.py | 3 --- zerver/views/typing.py | 10 +++++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 37b9c7d63c..1c1dc814ab 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 de0af3d34a..a239375458 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()