From 073b70a51646a216860cab6a6853645db68f2524 Mon Sep 17 00:00:00 2001 From: Mahhheshh <100200105+Mahhheshh@users.noreply.github.com> Date: Fri, 8 Mar 2024 17:54:04 +0530 Subject: [PATCH] csp_violations: Migrate has_request_variables to typed_endpoint. Refactor `report_csp_violations` view to use `typed_endpoint` decorator instead of `has_request_variables`. This change improves code consistency and enhances codebase comprehension. --- zerver/views/report.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/zerver/views/report.py b/zerver/views/report.py index ee886380b8..1c1c7509c4 100644 --- a/zerver/views/report.py +++ b/zerver/views/report.py @@ -5,17 +5,16 @@ from django.http import HttpRequest, HttpResponse from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST -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.typed_endpoint import JsonBodyPayload, typed_endpoint +from zerver.lib.validator import WildValue, check_string @csrf_exempt @require_POST -@has_request_variables +@typed_endpoint def report_csp_violations( - request: HttpRequest, - csp_report: WildValue = REQ(argument_type="body", converter=to_wild_value), + request: HttpRequest, *, csp_report: JsonBodyPayload[WildValue] ) -> HttpResponse: def get_attr(csp_report_attr: str) -> str: return csp_report.get(csp_report_attr, "").tame(check_string)