core: add parameter to output property mapping test formatted
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
0a1a2a035e
commit
14d702450a
|
@ -108,7 +108,7 @@ class ApplicationViewSet(ModelViewSet):
|
||||||
should_cache = request.GET.get("search", "") == ""
|
should_cache = request.GET.get("search", "") == ""
|
||||||
|
|
||||||
superuser_full_list = (
|
superuser_full_list = (
|
||||||
request.GET.get("superuser_full_list", "false").lower() == "true"
|
str(request.GET.get("superuser_full_list", "false")).lower() == "true"
|
||||||
)
|
)
|
||||||
if superuser_full_list and request.user.is_superuser:
|
if superuser_full_list and request.user.is_superuser:
|
||||||
serializer = self.get_serializer(queryset, many=True)
|
serializer = self.get_serializer(queryset, many=True)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"""PropertyMapping API Views"""
|
"""PropertyMapping API Views"""
|
||||||
from json import dumps
|
from json import dumps
|
||||||
|
|
||||||
|
from drf_yasg import openapi
|
||||||
from drf_yasg.utils import swagger_auto_schema
|
from drf_yasg.utils import swagger_auto_schema
|
||||||
from guardian.shortcuts import get_objects_for_user
|
from guardian.shortcuts import get_objects_for_user
|
||||||
from rest_framework import mixins
|
from rest_framework import mixins
|
||||||
|
@ -102,6 +103,13 @@ class PropertyMappingViewSet(
|
||||||
@swagger_auto_schema(
|
@swagger_auto_schema(
|
||||||
request_body=PolicyTestSerializer(),
|
request_body=PolicyTestSerializer(),
|
||||||
responses={200: PropertyMappingTestResultSerializer, 400: "Invalid parameters"},
|
responses={200: PropertyMappingTestResultSerializer, 400: "Invalid parameters"},
|
||||||
|
manual_parameters=[
|
||||||
|
openapi.Parameter(
|
||||||
|
name="format_result",
|
||||||
|
in_=openapi.IN_QUERY,
|
||||||
|
type=openapi.TYPE_BOOLEAN,
|
||||||
|
)
|
||||||
|
],
|
||||||
)
|
)
|
||||||
@action(detail=True, pagination_class=None, filter_backends=[], methods=["POST"])
|
@action(detail=True, pagination_class=None, filter_backends=[], methods=["POST"])
|
||||||
# pylint: disable=unused-argument, invalid-name
|
# pylint: disable=unused-argument, invalid-name
|
||||||
|
@ -112,6 +120,8 @@ class PropertyMappingViewSet(
|
||||||
if not test_params.is_valid():
|
if not test_params.is_valid():
|
||||||
return Response(test_params.errors, status=400)
|
return Response(test_params.errors, status=400)
|
||||||
|
|
||||||
|
format_result = str(request.GET.get("format_result", "false")).lower() == "true"
|
||||||
|
|
||||||
# User permission check, only allow mapping testing for users that are readable
|
# User permission check, only allow mapping testing for users that are readable
|
||||||
users = get_objects_for_user(request.user, "authentik_core.view_user").filter(
|
users = get_objects_for_user(request.user, "authentik_core.view_user").filter(
|
||||||
pk=test_params.validated_data["user"].pk
|
pk=test_params.validated_data["user"].pk
|
||||||
|
@ -126,7 +136,9 @@ class PropertyMappingViewSet(
|
||||||
self.request,
|
self.request,
|
||||||
**test_params.validated_data.get("context", {}),
|
**test_params.validated_data.get("context", {}),
|
||||||
)
|
)
|
||||||
response_data["result"] = dumps(result)
|
response_data["result"] = dumps(
|
||||||
|
result, indent=(4 if format_result else None)
|
||||||
|
)
|
||||||
except Exception as exc: # pylint: disable=broad-except
|
except Exception as exc: # pylint: disable=broad-except
|
||||||
response_data["result"] = str(exc)
|
response_data["result"] = str(exc)
|
||||||
response_data["successful"] = False
|
response_data["successful"] = False
|
||||||
|
|
|
@ -7674,6 +7674,9 @@ paths:
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/PolicyTest'
|
$ref: '#/definitions/PolicyTest'
|
||||||
|
- name: format_result
|
||||||
|
in: query
|
||||||
|
type: boolean
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: ''
|
description: ''
|
||||||
|
|
|
@ -27,7 +27,8 @@ export class PolicyTestForm extends Form<PolicyTest> {
|
||||||
send = (data: PolicyTest): Promise<PropertyMappingTestResult> => {
|
send = (data: PolicyTest): Promise<PropertyMappingTestResult> => {
|
||||||
return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsAllTest({
|
return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsAllTest({
|
||||||
pmUuid: this.mapping?.pk || "",
|
pmUuid: this.mapping?.pk || "",
|
||||||
data: data
|
data: data,
|
||||||
|
formatResult: true,
|
||||||
}).then(result => this.result = result);
|
}).then(result => this.result = result);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Reference in New Issue