mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 04:23:46 +00:00
wekan: Strengthen types using WildValue.
This commit is contained in:
committed by
Tim Abbott
parent
958b58f174
commit
537632d58c
@@ -1,10 +1,9 @@
|
||||
from typing import Any, Dict
|
||||
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import webhook_view
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.validator import WildValue, check_string, to_wild_value
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||
from zerver.models import UserProfile
|
||||
|
||||
@@ -26,15 +25,15 @@ def clean_payload_text(text: str) -> str:
|
||||
return text.replace(url, "").replace("\n", "")
|
||||
|
||||
|
||||
def get_message_body(payload: Dict[str, Any], action: str) -> str:
|
||||
footer = get_hyperlinked_url(payload["text"])
|
||||
body = process_message_data(payload, action)
|
||||
def get_message_body(payload: WildValue) -> str:
|
||||
footer = get_hyperlinked_url(payload["text"].tame(check_string))
|
||||
body = process_message_data(payload)
|
||||
return MESSAGE_TEMPLATE.format(body=body, footer=footer)
|
||||
|
||||
|
||||
def process_message_data(payload: Dict[str, Any], action: str) -> str:
|
||||
payload["text"] = clean_payload_text(payload["text"])
|
||||
return "{text}.".format(**payload)
|
||||
def process_message_data(payload: WildValue) -> str:
|
||||
text = clean_payload_text(payload["text"].tame(check_string))
|
||||
return f"{text}."
|
||||
|
||||
|
||||
@webhook_view("Wekan")
|
||||
@@ -42,9 +41,9 @@ def process_message_data(payload: Dict[str, Any], action: str) -> str:
|
||||
def api_wekan_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:
|
||||
topic = "Wekan Notification"
|
||||
body = get_message_body(payload, payload["description"])
|
||||
body = get_message_body(payload)
|
||||
check_send_webhook_message(request, user_profile, topic, body)
|
||||
return json_success(request)
|
||||
|
||||
Reference in New Issue
Block a user