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.

zapier: Strengthen types using WildValue.

Hari Prashant Bhimarajue9e1c1d6b128
diff --git a/zerver/webhooks/zapier/view.py b/zerver/webhooks/zapier/view.py
index 5577877e469..b928fca544c 100644
--- a/zerver/webhooks/zapier/view.py
+++ b/zerver/webhooks/zapier/view.py
@@ -1,5 +1,3 @@
-from typing import Any, Dict
-
from django.http import HttpRequest, HttpResponse
from django.utils.translation import gettext as _
@@ -7,6 +5,7 @@ from zerver.decorator import webhook_view
from zerver.lib.exceptions import JsonableError
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success
+from zerver.lib.validator import WildValue, check_none_or, check_string, to_wild_value
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
@@ -16,9 +15,9 @@ from zerver.models import UserProfile
def api_zapier_webhook(
request: HttpRequest,
user_profile: UserProfile,
- payload: Dict[str, Any] = REQ(argument_type="body"),
+ payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
) -> HttpResponse:
- if payload.get("type") == "auth":
+ if payload.get("type").tame(check_none_or(check_string)) == "auth":
# The bot's details are used by our Zapier app to format a connection
# label for users to be able to distinguish between different Zulip
# bots and API keys in their UI
@@ -31,11 +30,11 @@ def api_zapier_webhook(
},
)
- topic = payload.get("topic")
- content = payload.get("content")
+ topic = payload.get("topic").tame(check_none_or(check_string))
+ content = payload.get("content").tame(check_none_or(check_string))
if topic is None:
- topic = payload.get("subject") # Backwards-compatibility
+ topic = payload.get("subject").tame(check_none_or(check_string)) # Backwards-compatibility
if topic is None:
raise JsonableError(_("Topic can't be empty"))