Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
opencollective: Strengthen types using WildValue.
Hari Prashant Bhimaraju35ec9c3fd6d0
diff --git a/zerver/webhooks/opencollective/view.py b/zerver/webhooks/opencollective/view.pyindex f451f3cdb24..3b6389b4b69 100644--- a/zerver/webhooks/opencollective/view.py+++ b/zerver/webhooks/opencollective/view.py@@ -1,10 +1,9 @@-from typing import Any, Dict-from django.http import HttpRequest, HttpResponsefrom zerver.decorator import webhook_viewfrom zerver.lib.request import REQ, has_request_variablesfrom zerver.lib.response import json_success+from zerver.lib.validator import WildValue, check_string, to_wild_valuefrom zerver.lib.webhooks.common import check_send_webhook_messagefrom zerver.models import UserProfile@@ -17,7 +16,7 @@ AMOUNT_TEMPLATE = "{amount}"def api_opencollective_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:name = get_name(payload)@@ -39,9 +38,13 @@ def api_opencollective_webhook(return json_success(request)-def get_name(payload: Dict[str, Any]) -> str:- return MEMBER_NAME_TEMPLATE.format(name=payload["data"]["member"]["memberCollective"]["name"])+def get_name(payload: WildValue) -> str:+ return MEMBER_NAME_TEMPLATE.format(+ name=payload["data"]["member"]["memberCollective"]["name"].tame(check_string)+ )-def get_amount(payload: Dict[str, Any]) -> str:- return AMOUNT_TEMPLATE.format(amount=payload["data"]["order"]["formattedAmount"])+def get_amount(payload: WildValue) -> str:+ return AMOUNT_TEMPLATE.format(+ amount=payload["data"]["order"]["formattedAmount"].tame(check_string)+ )