diff --git a/authentik/core/api/applications.py b/authentik/core/api/applications.py index 6343f802f..b43d26431 100644 --- a/authentik/core/api/applications.py +++ b/authentik/core/api/applications.py @@ -108,7 +108,7 @@ class ApplicationViewSet(ModelViewSet): should_cache = request.GET.get("search", "") == "" 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: serializer = self.get_serializer(queryset, many=True) diff --git a/authentik/core/api/propertymappings.py b/authentik/core/api/propertymappings.py index 56d3cded5..fc1954b49 100644 --- a/authentik/core/api/propertymappings.py +++ b/authentik/core/api/propertymappings.py @@ -1,6 +1,7 @@ """PropertyMapping API Views""" from json import dumps +from drf_yasg import openapi from drf_yasg.utils import swagger_auto_schema from guardian.shortcuts import get_objects_for_user from rest_framework import mixins @@ -102,6 +103,13 @@ class PropertyMappingViewSet( @swagger_auto_schema( request_body=PolicyTestSerializer(), 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"]) # pylint: disable=unused-argument, invalid-name @@ -112,6 +120,8 @@ class PropertyMappingViewSet( if not test_params.is_valid(): 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 users = get_objects_for_user(request.user, "authentik_core.view_user").filter( pk=test_params.validated_data["user"].pk @@ -126,7 +136,9 @@ class PropertyMappingViewSet( self.request, **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 response_data["result"] = str(exc) response_data["successful"] = False diff --git a/swagger.yaml b/swagger.yaml index c5ba26a77..f6a3404e1 100755 --- a/swagger.yaml +++ b/swagger.yaml @@ -7674,6 +7674,9 @@ paths: required: true schema: $ref: '#/definitions/PolicyTest' + - name: format_result + in: query + type: boolean responses: '200': description: '' diff --git a/web/src/pages/property-mappings/PropertyMappingTestForm.ts b/web/src/pages/property-mappings/PropertyMappingTestForm.ts index 1a4fce60f..b2b4df264 100644 --- a/web/src/pages/property-mappings/PropertyMappingTestForm.ts +++ b/web/src/pages/property-mappings/PropertyMappingTestForm.ts @@ -27,7 +27,8 @@ export class PolicyTestForm extends Form { send = (data: PolicyTest): Promise => { return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsAllTest({ pmUuid: this.mapping?.pk || "", - data: data + data: data, + formatResult: true, }).then(result => this.result = result); };