flows: include configure_flow in stages API

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-04-16 17:18:55 +02:00
parent d01fd7cdb7
commit 33a8cea007
2 changed files with 35 additions and 2 deletions

View File

@ -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)

View File

@ -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