diff --git a/passbook/api/v2/urls.py b/passbook/api/v2/urls.py index 061c16831..524de960e 100644 --- a/passbook/api/v2/urls.py +++ b/passbook/api/v2/urls.py @@ -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"), ) diff --git a/passbook/flows/api.py b/passbook/flows/api.py new file mode 100644 index 000000000..09599ca6e --- /dev/null +++ b/passbook/flows/api.py @@ -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 diff --git a/passbook/flows/forms.py b/passbook/flows/forms.py index 6bc2443bb..b7936891e 100644 --- a/passbook/flows/forms.py +++ b/passbook/flows/forms.py @@ -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), + } diff --git a/passbook/flows/views.py b/passbook/flows/views.py index 25a3ae890..1cf812d05 100644 --- a/passbook/flows/views.py +++ b/passbook/flows/views.py @@ -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