mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
typing_notifications: Do op validation in view function.
Instead of validating `op` value later, this commit does that in `REQ`. Also helps avoiding duplication of this validation when stream typing notifications feature is added.
This commit is contained in:
@@ -2238,8 +2238,6 @@ def check_send_typing_notification(sender: UserProfile, user_ids: List[int], ope
|
|||||||
realm = sender.realm
|
realm = sender.realm
|
||||||
if len(user_ids) == 0:
|
if len(user_ids) == 0:
|
||||||
raise JsonableError(_("Missing parameter: 'to' (recipient)"))
|
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 mobile
|
""" The next chunk of code will go away when we upgrade old mobile
|
||||||
users away from versions of mobile that send emails. For the
|
users away from versions of mobile that send emails. For the
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class TypingValidateOperatorTest(ZulipTestCase):
|
|||||||
op="foo",
|
op="foo",
|
||||||
)
|
)
|
||||||
result = self.api_post(sender, "/api/v1/typing", params)
|
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):
|
class TypingValidateUsersTest(ZulipTestCase):
|
||||||
|
|||||||
@@ -5,15 +5,17 @@ from django.http import HttpRequest, HttpResponse
|
|||||||
from zerver.decorator import REQ, has_request_variables
|
from zerver.decorator import REQ, has_request_variables
|
||||||
from zerver.lib.actions import check_send_typing_notification
|
from zerver.lib.actions import check_send_typing_notification
|
||||||
from zerver.lib.response import json_success
|
from 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_in
|
||||||
from zerver.models import UserProfile
|
from zerver.models import UserProfile
|
||||||
|
|
||||||
|
VALID_OPERATOR_TYPES = ["start", "stop"]
|
||||||
|
|
||||||
|
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def send_notification_backend(
|
def send_notification_backend(
|
||||||
request: HttpRequest,
|
request: HttpRequest,
|
||||||
user_profile: UserProfile,
|
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)),
|
notification_to: List[int] = REQ("to", validator=check_list(check_int)),
|
||||||
) -> HttpResponse:
|
) -> HttpResponse:
|
||||||
check_send_typing_notification(user_profile, notification_to, operator)
|
check_send_typing_notification(user_profile, notification_to, operator)
|
||||||
|
|||||||
Reference in New Issue
Block a user