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