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.

webhooks: Migrate librato to use @typed_endpoint.

Zixuan James Li4037196fb214
diff --git a/zerver/webhooks/librato/view.py b/zerver/webhooks/librato/view.py
index 0f3489b82d6..9caa9b126ea 100644
--- a/zerver/webhooks/librato/view.py
+++ b/zerver/webhooks/librato/view.py
@@ -4,12 +4,12 @@ from typing import Any, Callable, Dict, List, Mapping, Tuple
import orjson
from django.http import HttpRequest, HttpResponse
from django.utils.translation import gettext as _
+from pydantic import Json
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 check_dict
+from zerver.lib.typed_endpoint import typed_endpoint
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
@@ -159,11 +159,14 @@ class LibratoWebhookHandler(LibratoWebhookParser):
@webhook_view("Librato")
-@has_request_variables
+@typed_endpoint
def api_librato_webhook(
request: HttpRequest,
user_profile: UserProfile,
- payload: Mapping[str, Any] = REQ(json_validator=check_dict(), default={}),
+ *,
+ payload: Json[
+ Mapping[str, Any]
+ ] = {}, # noqa: B006 # Mapping is indeed immutable, but Json's type annotation drops that information
) -> HttpResponse:
try:
attachments = orjson.loads(request.body).get("attachments", [])