flows: include configure_flow in stages API
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
d01fd7cdb7
commit
33a8cea007
|
@ -4,6 +4,7 @@ from typing import Iterable
|
||||||
from drf_yasg.utils import swagger_auto_schema
|
from drf_yasg.utils import swagger_auto_schema
|
||||||
from rest_framework import mixins
|
from rest_framework import mixins
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
|
from rest_framework.fields import BooleanField
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.serializers import ModelSerializer, SerializerMethodField
|
from rest_framework.serializers import ModelSerializer, SerializerMethodField
|
||||||
|
@ -19,6 +20,12 @@ from authentik.lib.utils.reflection import all_subclasses
|
||||||
LOGGER = get_logger()
|
LOGGER = get_logger()
|
||||||
|
|
||||||
|
|
||||||
|
class StageUserSettingSerializer(UserSettingSerializer):
|
||||||
|
"""User settings but can include a configure flow"""
|
||||||
|
|
||||||
|
configure_flow = BooleanField(required=False)
|
||||||
|
|
||||||
|
|
||||||
class StageSerializer(ModelSerializer, MetaNameSerializer):
|
class StageSerializer(ModelSerializer, MetaNameSerializer):
|
||||||
"""Stage Serializer"""
|
"""Stage Serializer"""
|
||||||
|
|
||||||
|
@ -78,7 +85,7 @@ class StageViewSet(
|
||||||
data = sorted(data, key=lambda x: x["name"])
|
data = sorted(data, key=lambda x: x["name"])
|
||||||
return Response(TypeCreateSerializer(data, many=True).data)
|
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=[])
|
@action(detail=False, pagination_class=None, filter_backends=[])
|
||||||
def user_settings(self, request: Request) -> Response:
|
def user_settings(self, request: Request) -> Response:
|
||||||
"""Get all stages the user can configure"""
|
"""Get all stages the user can configure"""
|
||||||
|
@ -89,6 +96,10 @@ class StageViewSet(
|
||||||
if not user_settings:
|
if not user_settings:
|
||||||
continue
|
continue
|
||||||
user_settings.initial_data["object_uid"] = str(stage.pk)
|
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():
|
if not user_settings.is_valid():
|
||||||
LOGGER.warning(user_settings.errors)
|
LOGGER.warning(user_settings.errors)
|
||||||
matching_stages.append(user_settings.initial_data)
|
matching_stages.append(user_settings.initial_data)
|
||||||
|
|
24
swagger.yaml
24
swagger.yaml
|
@ -10265,7 +10265,7 @@ paths:
|
||||||
schema:
|
schema:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: '#/definitions/UserSetting'
|
$ref: '#/definitions/StageUserSetting'
|
||||||
'403':
|
'403':
|
||||||
description: Authentication credentials were invalid, absent or insufficient.
|
description: Authentication credentials were invalid, absent or insufficient.
|
||||||
schema:
|
schema:
|
||||||
|
@ -17216,6 +17216,28 @@ definitions:
|
||||||
\ log out manually. (Format: hours=1;minutes=2;seconds=3)."
|
\ log out manually. (Format: hours=1;minutes=2;seconds=3)."
|
||||||
type: string
|
type: string
|
||||||
minLength: 1
|
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:
|
AuthenticatorStaticStage:
|
||||||
required:
|
required:
|
||||||
- name
|
- name
|
||||||
|
|
Reference in New Issue