flows: separate flows api into smaller files
This commit is contained in:
parent
6597d5bd28
commit
a76cbf8b70
|
@ -23,7 +23,9 @@ from authentik.events.api.event import EventViewSet
|
||||||
from authentik.events.api.notification import NotificationViewSet
|
from authentik.events.api.notification import NotificationViewSet
|
||||||
from authentik.events.api.notification_rule import NotificationRuleViewSet
|
from authentik.events.api.notification_rule import NotificationRuleViewSet
|
||||||
from authentik.events.api.notification_transport import NotificationTransportViewSet
|
from authentik.events.api.notification_transport import NotificationTransportViewSet
|
||||||
from authentik.flows.api import FlowStageBindingViewSet, FlowViewSet, StageViewSet
|
from authentik.flows.api.bindings import FlowStageBindingViewSet
|
||||||
|
from authentik.flows.api.flows import FlowViewSet
|
||||||
|
from authentik.flows.api.stages import StageViewSet
|
||||||
from authentik.outposts.api.outpost_service_connections import (
|
from authentik.outposts.api.outpost_service_connections import (
|
||||||
DockerServiceConnectionViewSet,
|
DockerServiceConnectionViewSet,
|
||||||
KubernetesServiceConnectionViewSet,
|
KubernetesServiceConnectionViewSet,
|
||||||
|
|
0
authentik/flows/api/__init__.py
Normal file
0
authentik/flows/api/__init__.py
Normal file
35
authentik/flows/api/bindings.py
Normal file
35
authentik/flows/api/bindings.py
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
"""Flow Binding API Views"""
|
||||||
|
from rest_framework.serializers import ModelSerializer
|
||||||
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
|
from authentik.flows.api.stages import StageSerializer
|
||||||
|
from authentik.flows.models import FlowStageBinding
|
||||||
|
|
||||||
|
|
||||||
|
class FlowStageBindingSerializer(ModelSerializer):
|
||||||
|
"""FlowStageBinding Serializer"""
|
||||||
|
|
||||||
|
stage_obj = StageSerializer(read_only=True, source="stage")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
|
||||||
|
model = FlowStageBinding
|
||||||
|
fields = [
|
||||||
|
"pk",
|
||||||
|
"policybindingmodel_ptr_id",
|
||||||
|
"target",
|
||||||
|
"stage",
|
||||||
|
"stage_obj",
|
||||||
|
"evaluate_on_plan",
|
||||||
|
"re_evaluate_policies",
|
||||||
|
"order",
|
||||||
|
"policies",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class FlowStageBindingViewSet(ModelViewSet):
|
||||||
|
"""FlowStageBinding Viewset"""
|
||||||
|
|
||||||
|
queryset = FlowStageBinding.objects.all()
|
||||||
|
serializer_class = FlowStageBindingSerializer
|
||||||
|
filterset_fields = "__all__"
|
|
@ -3,7 +3,7 @@ from dataclasses import dataclass
|
||||||
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.db.models import Model
|
from django.db.models import Model
|
||||||
from django.shortcuts import get_object_or_404, reverse
|
from django.shortcuts import get_object_or_404
|
||||||
from drf_yasg2.utils import swagger_auto_schema
|
from drf_yasg2.utils import swagger_auto_schema
|
||||||
from guardian.shortcuts import get_objects_for_user
|
from guardian.shortcuts import get_objects_for_user
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
|
@ -15,17 +15,11 @@ from rest_framework.serializers import (
|
||||||
Serializer,
|
Serializer,
|
||||||
SerializerMethodField,
|
SerializerMethodField,
|
||||||
)
|
)
|
||||||
from rest_framework.viewsets import ModelViewSet, ReadOnlyModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.core.api.utils import (
|
from authentik.core.api.utils import CacheSerializer
|
||||||
CacheSerializer,
|
from authentik.flows.models import Flow
|
||||||
MetaNameSerializer,
|
|
||||||
TypeCreateSerializer,
|
|
||||||
)
|
|
||||||
from authentik.flows.models import Flow, FlowStageBinding, Stage
|
|
||||||
from authentik.flows.planner import cache_key
|
from authentik.flows.planner import cache_key
|
||||||
from authentik.lib.templatetags.authentik_utils import verbose_name
|
|
||||||
from authentik.lib.utils.reflection import all_subclasses
|
|
||||||
|
|
||||||
|
|
||||||
class FlowSerializer(ModelSerializer):
|
class FlowSerializer(ModelSerializer):
|
||||||
|
@ -164,76 +158,3 @@ class FlowViewSet(ModelViewSet):
|
||||||
)
|
)
|
||||||
diagram = "\n".join([str(x) for x in header + body + footer])
|
diagram = "\n".join([str(x) for x in header + body + footer])
|
||||||
return Response({"diagram": diagram})
|
return Response({"diagram": diagram})
|
||||||
|
|
||||||
|
|
||||||
class StageSerializer(ModelSerializer, MetaNameSerializer):
|
|
||||||
"""Stage Serializer"""
|
|
||||||
|
|
||||||
object_type = SerializerMethodField()
|
|
||||||
|
|
||||||
def get_object_type(self, obj):
|
|
||||||
"""Get object type so that we know which API Endpoint to use to get the full object"""
|
|
||||||
return obj._meta.object_name.lower().replace("stage", "")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
|
|
||||||
model = Stage
|
|
||||||
fields = ["pk", "name", "object_type", "verbose_name", "verbose_name_plural"]
|
|
||||||
|
|
||||||
|
|
||||||
class StageViewSet(ReadOnlyModelViewSet):
|
|
||||||
"""Stage Viewset"""
|
|
||||||
|
|
||||||
queryset = Stage.objects.all()
|
|
||||||
serializer_class = StageSerializer
|
|
||||||
search_fields = ["name"]
|
|
||||||
filterset_fields = ["name"]
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return Stage.objects.select_subclasses()
|
|
||||||
|
|
||||||
@swagger_auto_schema(responses={200: TypeCreateSerializer(many=True)})
|
|
||||||
@action(detail=False)
|
|
||||||
def types(self, request: Request) -> Response:
|
|
||||||
"""Get all creatable stage types"""
|
|
||||||
data = []
|
|
||||||
for subclass in all_subclasses(self.queryset.model, False):
|
|
||||||
data.append(
|
|
||||||
{
|
|
||||||
"name": verbose_name(subclass),
|
|
||||||
"description": subclass.__doc__,
|
|
||||||
"link": reverse("authentik_admin:stage-create")
|
|
||||||
+ f"?type={subclass.__name__}",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
data = sorted(data, key=lambda x: x["name"])
|
|
||||||
return Response(TypeCreateSerializer(data, many=True).data)
|
|
||||||
|
|
||||||
|
|
||||||
class FlowStageBindingSerializer(ModelSerializer):
|
|
||||||
"""FlowStageBinding Serializer"""
|
|
||||||
|
|
||||||
stage_obj = StageSerializer(read_only=True, source="stage")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
|
|
||||||
model = FlowStageBinding
|
|
||||||
fields = [
|
|
||||||
"pk",
|
|
||||||
"policybindingmodel_ptr_id",
|
|
||||||
"target",
|
|
||||||
"stage",
|
|
||||||
"stage_obj",
|
|
||||||
"evaluate_on_plan",
|
|
||||||
"re_evaluate_policies",
|
|
||||||
"order",
|
|
||||||
"policies",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class FlowStageBindingViewSet(ModelViewSet):
|
|
||||||
"""FlowStageBinding Viewset"""
|
|
||||||
|
|
||||||
queryset = FlowStageBinding.objects.all()
|
|
||||||
serializer_class = FlowStageBindingSerializer
|
|
||||||
filterset_fields = "__all__"
|
|
58
authentik/flows/api/stages.py
Normal file
58
authentik/flows/api/stages.py
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
"""Flow Stage API Views"""
|
||||||
|
from django.shortcuts import reverse
|
||||||
|
from drf_yasg2.utils import swagger_auto_schema
|
||||||
|
from rest_framework.decorators import action
|
||||||
|
from rest_framework.request import Request
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from rest_framework.serializers import ModelSerializer, SerializerMethodField
|
||||||
|
from rest_framework.viewsets import ReadOnlyModelViewSet
|
||||||
|
|
||||||
|
from authentik.core.api.utils import MetaNameSerializer, TypeCreateSerializer
|
||||||
|
from authentik.flows.models import Stage
|
||||||
|
from authentik.flows.planner import cache_key
|
||||||
|
from authentik.lib.templatetags.authentik_utils import verbose_name
|
||||||
|
from authentik.lib.utils.reflection import all_subclasses
|
||||||
|
|
||||||
|
|
||||||
|
class StageSerializer(ModelSerializer, MetaNameSerializer):
|
||||||
|
"""Stage Serializer"""
|
||||||
|
|
||||||
|
object_type = SerializerMethodField()
|
||||||
|
|
||||||
|
def get_object_type(self, obj: Stage) -> str:
|
||||||
|
"""Get object type so that we know which API Endpoint to use to get the full object"""
|
||||||
|
return obj._meta.object_name.lower().replace("stage", "")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
|
||||||
|
model = Stage
|
||||||
|
fields = ["pk", "name", "object_type", "verbose_name", "verbose_name_plural"]
|
||||||
|
|
||||||
|
|
||||||
|
class StageViewSet(ReadOnlyModelViewSet):
|
||||||
|
"""Stage Viewset"""
|
||||||
|
|
||||||
|
queryset = Stage.objects.all()
|
||||||
|
serializer_class = StageSerializer
|
||||||
|
search_fields = ["name"]
|
||||||
|
filterset_fields = ["name"]
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return Stage.objects.select_subclasses()
|
||||||
|
|
||||||
|
@swagger_auto_schema(responses={200: TypeCreateSerializer(many=True)})
|
||||||
|
@action(detail=False)
|
||||||
|
def types(self, request: Request) -> Response:
|
||||||
|
"""Get all creatable stage types"""
|
||||||
|
data = []
|
||||||
|
for subclass in all_subclasses(self.queryset.model, False):
|
||||||
|
data.append(
|
||||||
|
{
|
||||||
|
"name": verbose_name(subclass),
|
||||||
|
"description": subclass.__doc__,
|
||||||
|
"link": reverse("authentik_admin:stage-create")
|
||||||
|
+ f"?type={subclass.__name__}",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
data = sorted(data, key=lambda x: x["name"])
|
||||||
|
return Response(TypeCreateSerializer(data, many=True).data)
|
|
@ -118,7 +118,7 @@ class Flow(SerializerModel, PolicyBindingModel):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def serializer(self) -> BaseSerializer:
|
def serializer(self) -> BaseSerializer:
|
||||||
from authentik.flows.api import FlowSerializer
|
from authentik.flows.api.flows import FlowSerializer
|
||||||
|
|
||||||
return FlowSerializer
|
return FlowSerializer
|
||||||
|
|
||||||
|
@ -189,12 +189,12 @@ class FlowStageBinding(SerializerModel, PolicyBindingModel):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def serializer(self) -> BaseSerializer:
|
def serializer(self) -> BaseSerializer:
|
||||||
from authentik.flows.api import FlowStageBindingSerializer
|
from authentik.flows.api.bindings import FlowStageBindingSerializer
|
||||||
|
|
||||||
return FlowStageBindingSerializer
|
return FlowStageBindingSerializer
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f"{self.target} #{self.order} -> {self.stage}"
|
return f"{self.target} #{self.order}"
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ from django.shortcuts import reverse
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
from authentik.core.models import User
|
from authentik.core.models import User
|
||||||
from authentik.flows.api import StageSerializer, StageViewSet
|
from authentik.flows.api.stages import StageSerializer, StageViewSet
|
||||||
from authentik.flows.models import Flow, FlowDesignation, FlowStageBinding, Stage
|
from authentik.flows.models import Flow, FlowDesignation, FlowStageBinding, Stage
|
||||||
from authentik.policies.dummy.models import DummyPolicy
|
from authentik.policies.dummy.models import DummyPolicy
|
||||||
from authentik.policies.models import PolicyBinding
|
from authentik.policies.models import PolicyBinding
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""AuthenticatorStaticStage API Views"""
|
"""AuthenticatorStaticStage API Views"""
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.flows.api import StageSerializer
|
from authentik.flows.api.stages import StageSerializer
|
||||||
from authentik.stages.authenticator_static.models import AuthenticatorStaticStage
|
from authentik.stages.authenticator_static.models import AuthenticatorStaticStage
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""AuthenticatorTOTPStage API Views"""
|
"""AuthenticatorTOTPStage API Views"""
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.flows.api import StageSerializer
|
from authentik.flows.api.stages import StageSerializer
|
||||||
from authentik.stages.authenticator_totp.models import AuthenticatorTOTPStage
|
from authentik.stages.authenticator_totp.models import AuthenticatorTOTPStage
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""AuthenticatorValidateStage API Views"""
|
"""AuthenticatorValidateStage API Views"""
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.flows.api import StageSerializer
|
from authentik.flows.api.stages import StageSerializer
|
||||||
from authentik.stages.authenticator_validate.models import AuthenticatorValidateStage
|
from authentik.stages.authenticator_validate.models import AuthenticatorValidateStage
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""AuthenticateWebAuthnStage API Views"""
|
"""AuthenticateWebAuthnStage API Views"""
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.flows.api import StageSerializer
|
from authentik.flows.api.stages import StageSerializer
|
||||||
from authentik.stages.authenticator_webauthn.models import AuthenticateWebAuthnStage
|
from authentik.stages.authenticator_webauthn.models import AuthenticateWebAuthnStage
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""CaptchaStage API Views"""
|
"""CaptchaStage API Views"""
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.flows.api import StageSerializer
|
from authentik.flows.api.stages import StageSerializer
|
||||||
from authentik.stages.captcha.models import CaptchaStage
|
from authentik.stages.captcha.models import CaptchaStage
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""ConsentStage API Views"""
|
"""ConsentStage API Views"""
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.flows.api import StageSerializer
|
from authentik.flows.api.stages import StageSerializer
|
||||||
from authentik.stages.consent.models import ConsentStage
|
from authentik.stages.consent.models import ConsentStage
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""DummyStage API Views"""
|
"""DummyStage API Views"""
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.flows.api import StageSerializer
|
from authentik.flows.api.stages import StageSerializer
|
||||||
from authentik.stages.dummy.models import DummyStage
|
from authentik.stages.dummy.models import DummyStage
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""EmailStage API Views"""
|
"""EmailStage API Views"""
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.flows.api import StageSerializer
|
from authentik.flows.api.stages import StageSerializer
|
||||||
from authentik.stages.email.models import EmailStage, get_template_choices
|
from authentik.stages.email.models import EmailStage, get_template_choices
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""Identification Stage API Views"""
|
"""Identification Stage API Views"""
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.flows.api import StageSerializer
|
from authentik.flows.api.stages import StageSerializer
|
||||||
from authentik.stages.identification.models import IdentificationStage
|
from authentik.stages.identification.models import IdentificationStage
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
from rest_framework.serializers import ModelSerializer
|
from rest_framework.serializers import ModelSerializer
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.flows.api import StageSerializer
|
from authentik.flows.api.stages import StageSerializer
|
||||||
from authentik.stages.invitation.models import Invitation, InvitationStage
|
from authentik.stages.invitation.models import Invitation, InvitationStage
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""PasswordStage API Views"""
|
"""PasswordStage API Views"""
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.flows.api import StageSerializer
|
from authentik.flows.api.stages import StageSerializer
|
||||||
from authentik.stages.password.models import PasswordStage
|
from authentik.stages.password.models import PasswordStage
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ from rest_framework.serializers import CharField, ModelSerializer
|
||||||
from rest_framework.validators import UniqueValidator
|
from rest_framework.validators import UniqueValidator
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.flows.api import StageSerializer
|
from authentik.flows.api.stages import StageSerializer
|
||||||
from authentik.stages.prompt.models import Prompt, PromptStage
|
from authentik.stages.prompt.models import Prompt, PromptStage
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""User Delete Stage API Views"""
|
"""User Delete Stage API Views"""
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.flows.api import StageSerializer
|
from authentik.flows.api.stages import StageSerializer
|
||||||
from authentik.stages.user_delete.models import UserDeleteStage
|
from authentik.stages.user_delete.models import UserDeleteStage
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""Login Stage API Views"""
|
"""Login Stage API Views"""
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.flows.api import StageSerializer
|
from authentik.flows.api.stages import StageSerializer
|
||||||
from authentik.stages.user_login.models import UserLoginStage
|
from authentik.stages.user_login.models import UserLoginStage
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""Logout Stage API Views"""
|
"""Logout Stage API Views"""
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.flows.api import StageSerializer
|
from authentik.flows.api.stages import StageSerializer
|
||||||
from authentik.stages.user_logout.models import UserLogoutStage
|
from authentik.stages.user_logout.models import UserLogoutStage
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""User Write Stage API Views"""
|
"""User Write Stage API Views"""
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.flows.api import StageSerializer
|
from authentik.flows.api.stages import StageSerializer
|
||||||
from authentik.stages.user_write.models import UserWriteStage
|
from authentik.stages.user_write.models import UserWriteStage
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue