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.
This commit is contained in:
Mahhheshh 2024-03-08 17:54:04 +05:30 committed by Tim Abbott
parent 11e498f937
commit 073b70a516
1 changed files with 4 additions and 5 deletions

View File

@ -5,17 +5,16 @@ from django.http import HttpRequest, HttpResponse
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST 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.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 @csrf_exempt
@require_POST @require_POST
@has_request_variables @typed_endpoint
def report_csp_violations( def report_csp_violations(
request: HttpRequest, request: HttpRequest, *, csp_report: JsonBodyPayload[WildValue]
csp_report: WildValue = REQ(argument_type="body", converter=to_wild_value),
) -> HttpResponse: ) -> HttpResponse:
def get_attr(csp_report_attr: str) -> str: def get_attr(csp_report_attr: str) -> str:
return csp_report.get(csp_report_attr, "").tame(check_string) return csp_report.get(csp_report_attr, "").tame(check_string)