flows: add to api and add forms

This commit is contained in:
Jens Langhammer 2020-05-08 18:29:18 +02:00
parent f8af9d6ce0
commit 872ecd93a6
4 changed files with 103 additions and 3 deletions

View File

@ -22,6 +22,7 @@ from passbook.factors.dummy.api import DummyFactorViewSet
from passbook.factors.email.api import EmailFactorViewSet
from passbook.factors.otp.api import OTPFactorViewSet
from passbook.factors.password.api import PasswordFactorViewSet
from passbook.flows.api import FlowFactorBindingViewSet, FlowViewSet
from passbook.lib.utils.reflection import get_apps
from passbook.policies.expiry.api import PasswordExpiryPolicyViewSet
from passbook.policies.expression.api import ExpressionPolicyViewSet
@ -74,12 +75,12 @@ router.register("factors/dummy", DummyFactorViewSet)
router.register("factors/email", EmailFactorViewSet)
router.register("factors/otp", OTPFactorViewSet)
router.register("factors/password", PasswordFactorViewSet)
router.register("flows", FlowViewSet)
router.register("flows/bindings", FlowFactorBindingViewSet)
info = openapi.Info(
title="passbook API",
default_version="v2",
# description="Test description",
# terms_of_service="https://www.google.com/policies/terms/",
contact=openapi.Contact(email="hello@beryju.org"),
license=openapi.License(name="MIT License"),
)

51
passbook/flows/api.py Normal file
View File

@ -0,0 +1,51 @@
"""Flow API Views"""
from rest_framework.serializers import ModelSerializer
from rest_framework.viewsets import ModelViewSet
from passbook.flows.models import Flow, FlowFactorBinding
class FlowSerializer(ModelSerializer):
"""Flow Serializer"""
class Meta:
model = Flow
fields = [
"pk",
"name",
"slug",
"designation",
"factors",
"policies"
]
class FlowViewSet(ModelViewSet):
"""Flow Viewset"""
queryset = Flow.objects.all()
serializer_class = FlowSerializer
class FlowFactorBindingSerializer(ModelSerializer):
"""FlowFactorBinding Serializer"""
class Meta:
model = FlowFactorBinding
fields = [
"pk",
"flow",
"factor",
"re_evaluate_policies",
"order",
"policies"
]
class FlowFactorBindingViewSet(ModelViewSet):
"""FlowFactorBinding Viewset"""
queryset = FlowFactorBinding.objects.all()
serializer_class = FlowFactorBindingSerializer

View File

@ -1,3 +1,47 @@
"""factor forms"""
from django import forms
from django.contrib.admin.widgets import FilteredSelectMultiple
from django.utils.translation import gettext_lazy as _
from passbook.flows.models import Flow, FlowFactorBinding
GENERAL_FIELDS = ["name", "slug", "order", "policies", "enabled"]
class FlowForm(forms.ModelForm):
"""Flow Form"""
class Meta:
model = Flow
fields = [
"name",
"slug",
"designation",
"factors",
"policies",
]
widgets = {
"name": forms.TextInput(),
"factors": FilteredSelectMultiple(_("policies"), False),
}
class FlowFactorBindingForm(forms.ModelForm):
"""FlowFactorBinding Form"""
class Meta:
model = FlowFactorBinding
fields = [
"flow",
"factor",
"re_evaluate_policies",
"order",
"policies",
]
widgets = {
"name": forms.TextInput(),
"factors": FilteredSelectMultiple(_("policies"), False),
}

View File

@ -80,7 +80,11 @@ class FlowExecutorView(View):
# We don't save the Plan after getting the next factor
# as it hasn't been successfully passed yet
self.current_factor = self.plan.next()
LOGGER.debug("Current factor", current_factor=self.current_factor, flow_slug=self.flow.slug)
LOGGER.debug(
"Current factor",
current_factor=self.current_factor,
flow_slug=self.flow.slug,
)
factor_cls = path_to_class(self.current_factor.type)
self.current_factor_view = factor_cls(self)
self.current_factor_view.request = request