mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
appfollow: Strengthen types using WildValue.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
07ae5f54ee
commit
04e09d21a3
@@ -1,12 +1,12 @@
|
|||||||
# Webhooks for external integrations.
|
# Webhooks for external integrations.
|
||||||
import re
|
import re
|
||||||
from typing import Any, Dict
|
|
||||||
|
|
||||||
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 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
|
||||||
|
|
||||||
@@ -16,9 +16,9 @@ from zerver.models import UserProfile
|
|||||||
def api_appfollow_webhook(
|
def api_appfollow_webhook(
|
||||||
request: HttpRequest,
|
request: HttpRequest,
|
||||||
user_profile: UserProfile,
|
user_profile: UserProfile,
|
||||||
payload: Dict[str, Any] = REQ(argument_type="body"),
|
payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
|
||||||
) -> HttpResponse:
|
) -> HttpResponse:
|
||||||
message = payload["text"]
|
message = payload["text"].tame(check_string)
|
||||||
app_name_search = re.search(r"\A(.+)", message)
|
app_name_search = re.search(r"\A(.+)", message)
|
||||||
assert app_name_search is not None
|
assert app_name_search is not None
|
||||||
app_name = app_name_search.group(0)
|
app_name = app_name_search.group(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user