mirror of
https://github.com/zulip/zulip.git
synced 2025-10-30 19:43:47 +00:00
hellosign: Strengthen types using WildValue.
This commit is contained in:
committed by
Tim Abbott
parent
f0fd083e88
commit
c692fc400d
@@ -1,11 +1,11 @@
|
|||||||
from typing import Any, Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
from django.http import HttpRequest, HttpResponse
|
from django.http import HttpRequest, HttpResponse
|
||||||
|
|
||||||
from zerver.decorator import webhook_view
|
from zerver.decorator import webhook_view
|
||||||
from zerver.lib.request import REQ, has_request_variables
|
from zerver.lib.request import REQ, has_request_variables
|
||||||
from zerver.lib.response import json_success
|
from zerver.lib.response import json_success
|
||||||
from zerver.lib.validator import check_dict
|
from zerver.lib.validator import WildValue, check_string, to_wild_value
|
||||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||||
from zerver.models import UserProfile
|
from zerver.models import UserProfile
|
||||||
|
|
||||||
@@ -14,14 +14,15 @@ WAS_JUST_SIGNED_BY = "was just signed by {signed_recipients}"
|
|||||||
BODY = "The `{contract_title}` document {actions}."
|
BODY = "The `{contract_title}` document {actions}."
|
||||||
|
|
||||||
|
|
||||||
def get_message_body(payload: Dict[str, Any]) -> str:
|
def get_message_body(payload: WildValue) -> str:
|
||||||
contract_title = payload["signature_request"]["title"]
|
contract_title = payload["signature_request"]["title"].tame(check_string)
|
||||||
recipients: Dict[str, List[str]] = {}
|
recipients: Dict[str, List[str]] = {}
|
||||||
signatures = payload["signature_request"]["signatures"]
|
signatures = payload["signature_request"]["signatures"]
|
||||||
|
|
||||||
for signature in signatures:
|
for signature in signatures:
|
||||||
recipients.setdefault(signature["status_code"], [])
|
status_code = signature["status_code"].tame(check_string)
|
||||||
recipients[signature["status_code"]].append(signature["signer_name"])
|
recipients.setdefault(status_code, [])
|
||||||
|
recipients[status_code].append(signature["signer_name"].tame(check_string))
|
||||||
|
|
||||||
recipients_text = ""
|
recipients_text = ""
|
||||||
if recipients.get("awaiting_signature"):
|
if recipients.get("awaiting_signature"):
|
||||||
@@ -59,11 +60,11 @@ def get_recipients_text(recipients: List[str]) -> str:
|
|||||||
def api_hellosign_webhook(
|
def api_hellosign_webhook(
|
||||||
request: HttpRequest,
|
request: HttpRequest,
|
||||||
user_profile: UserProfile,
|
user_profile: UserProfile,
|
||||||
payload: Dict[str, Any] = REQ(whence="json", json_validator=check_dict()),
|
payload: WildValue = REQ(whence="json", converter=to_wild_value),
|
||||||
) -> HttpResponse:
|
) -> HttpResponse:
|
||||||
if "signature_request" in payload:
|
if "signature_request" in payload:
|
||||||
body = get_message_body(payload)
|
body = get_message_body(payload)
|
||||||
topic = payload["signature_request"]["title"]
|
topic = payload["signature_request"]["title"].tame(check_string)
|
||||||
check_send_webhook_message(request, user_profile, topic, body)
|
check_send_webhook_message(request, user_profile, topic, body)
|
||||||
|
|
||||||
return json_success(request, data={"msg": "Hello API Event Received"})
|
return json_success(request, data={"msg": "Hello API Event Received"})
|
||||||
|
|||||||
Reference in New Issue
Block a user