From 71b6839d0348b55be9037058a21a594f442b625a Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 16 Apr 2021 17:18:55 +0200 Subject: [PATCH] flows: include configure_flow in stages API Signed-off-by: Jens Langhammer --- authentik/flows/api/stages.py | 13 ++++++++++++- swagger.yaml | 24 +++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/authentik/flows/api/stages.py b/authentik/flows/api/stages.py index 4d89cb19b..190903662 100644 --- a/authentik/flows/api/stages.py +++ b/authentik/flows/api/stages.py @@ -4,6 +4,7 @@ from typing import Iterable from drf_yasg.utils import swagger_auto_schema from rest_framework import mixins from rest_framework.decorators import action +from rest_framework.fields import BooleanField from rest_framework.request import Request from rest_framework.response import Response from rest_framework.serializers import ModelSerializer, SerializerMethodField @@ -19,6 +20,12 @@ from authentik.lib.utils.reflection import all_subclasses LOGGER = get_logger() +class StageUserSettingSerializer(UserSettingSerializer): + """User settings but can include a configure flow""" + + configure_flow = BooleanField(required=False) + + class StageSerializer(ModelSerializer, MetaNameSerializer): """Stage Serializer""" @@ -78,7 +85,7 @@ class StageViewSet( data = sorted(data, key=lambda x: x["name"]) return Response(TypeCreateSerializer(data, many=True).data) - @swagger_auto_schema(responses={200: UserSettingSerializer(many=True)}) + @swagger_auto_schema(responses={200: StageUserSettingSerializer(many=True)}) @action(detail=False, pagination_class=None, filter_backends=[]) def user_settings(self, request: Request) -> Response: """Get all stages the user can configure""" @@ -89,6 +96,10 @@ class StageViewSet( if not user_settings: continue user_settings.initial_data["object_uid"] = str(stage.pk) + if hasattr(stage, "configure_flow"): + user_settings.initial_data["configure_flow"] = bool( + stage.configure_flow + ) if not user_settings.is_valid(): LOGGER.warning(user_settings.errors) matching_stages.append(user_settings.initial_data) diff --git a/swagger.yaml b/swagger.yaml index 58d1c47c5..e83b9edc3 100755 --- a/swagger.yaml +++ b/swagger.yaml @@ -10265,7 +10265,7 @@ paths: schema: type: array items: - $ref: '#/definitions/UserSetting' + $ref: '#/definitions/StageUserSetting' '403': description: Authentication credentials were invalid, absent or insufficient. schema: @@ -17216,6 +17216,28 @@ definitions: \ log out manually. (Format: hours=1;minutes=2;seconds=3)." type: string minLength: 1 + StageUserSetting: + required: + - object_uid + - component + - title + type: object + properties: + object_uid: + title: Object uid + type: string + minLength: 1 + component: + title: Component + type: string + minLength: 1 + title: + title: Title + type: string + minLength: 1 + configure_flow: + title: Configure flow + type: boolean AuthenticatorStaticStage: required: - name