From 9859c5db0af46277809314beeda2c55349e7778c Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 14 May 2020 13:51:05 +0200 Subject: [PATCH] policies: add API for policybindings --- passbook/api/v2/urls.py | 2 ++ passbook/policies/api.py | 21 +++++++++++++++++++++ passbook/policies/models.py | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 passbook/policies/api.py diff --git a/passbook/api/v2/urls.py b/passbook/api/v2/urls.py index f00e6f636..c9482cfff 100644 --- a/passbook/api/v2/urls.py +++ b/passbook/api/v2/urls.py @@ -18,6 +18,7 @@ from passbook.core.api.sources import SourceViewSet from passbook.core.api.users import UserViewSet from passbook.flows.api import FlowStageBindingViewSet, FlowViewSet, StageViewSet from passbook.lib.utils.reflection import get_apps +from passbook.policies.api import PolicyBindingViewSet from passbook.policies.expiry.api import PasswordExpiryPolicyViewSet from passbook.policies.expression.api import ExpressionPolicyViewSet from passbook.policies.hibp.api import HaveIBeenPwendPolicyViewSet @@ -62,6 +63,7 @@ router.register("sources/ldap", LDAPSourceViewSet) router.register("sources/oauth", OAuthSourceViewSet) router.register("policies/all", PolicyViewSet) +router.register("policies/bindings", PolicyBindingViewSet) router.register("policies/expression", ExpressionPolicyViewSet) router.register("policies/haveibeenpwned", HaveIBeenPwendPolicyViewSet) router.register("policies/password", PasswordPolicyViewSet) diff --git a/passbook/policies/api.py b/passbook/policies/api.py new file mode 100644 index 000000000..7bf1be18a --- /dev/null +++ b/passbook/policies/api.py @@ -0,0 +1,21 @@ +"""policy API Views""" +from rest_framework.serializers import ModelSerializer +from rest_framework.viewsets import ModelViewSet + +from passbook.policies.models import PolicyBinding + + +class PolicyBindingSerializer(ModelSerializer): + """PolicyBinding Serializer""" + + class Meta: + + model = PolicyBinding + fields = ["policy", "target", "enabled", "order"] + + +class PolicyBindingViewSet(ModelViewSet): + """PolicyBinding Viewset""" + + queryset = PolicyBinding.objects.all() + serializer_class = PolicyBindingSerializer diff --git a/passbook/policies/models.py b/passbook/policies/models.py index 033c818a0..e2c35786b 100644 --- a/passbook/policies/models.py +++ b/passbook/policies/models.py @@ -7,7 +7,7 @@ from passbook.lib.models import UUIDModel class PolicyBindingModel(models.Model): - """Base Model for objects which have Policies applied to them""" + """Base Model for objects that have policies applied to them.""" policies = models.ManyToManyField( Policy, through="PolicyBinding", related_name="+", blank=True