policies: add API for policybindings

This commit is contained in:
Jens Langhammer 2020-05-14 13:51:05 +02:00
parent fe503c8de0
commit 9859c5db0a
3 changed files with 24 additions and 1 deletions

View File

@ -18,6 +18,7 @@ from passbook.core.api.sources import SourceViewSet
from passbook.core.api.users import UserViewSet from passbook.core.api.users import UserViewSet
from passbook.flows.api import FlowStageBindingViewSet, FlowViewSet, StageViewSet from passbook.flows.api import FlowStageBindingViewSet, FlowViewSet, StageViewSet
from passbook.lib.utils.reflection import get_apps from passbook.lib.utils.reflection import get_apps
from passbook.policies.api import PolicyBindingViewSet
from passbook.policies.expiry.api import PasswordExpiryPolicyViewSet from passbook.policies.expiry.api import PasswordExpiryPolicyViewSet
from passbook.policies.expression.api import ExpressionPolicyViewSet from passbook.policies.expression.api import ExpressionPolicyViewSet
from passbook.policies.hibp.api import HaveIBeenPwendPolicyViewSet from passbook.policies.hibp.api import HaveIBeenPwendPolicyViewSet
@ -62,6 +63,7 @@ router.register("sources/ldap", LDAPSourceViewSet)
router.register("sources/oauth", OAuthSourceViewSet) router.register("sources/oauth", OAuthSourceViewSet)
router.register("policies/all", PolicyViewSet) router.register("policies/all", PolicyViewSet)
router.register("policies/bindings", PolicyBindingViewSet)
router.register("policies/expression", ExpressionPolicyViewSet) router.register("policies/expression", ExpressionPolicyViewSet)
router.register("policies/haveibeenpwned", HaveIBeenPwendPolicyViewSet) router.register("policies/haveibeenpwned", HaveIBeenPwendPolicyViewSet)
router.register("policies/password", PasswordPolicyViewSet) router.register("policies/password", PasswordPolicyViewSet)

21
passbook/policies/api.py Normal file
View File

@ -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

View File

@ -7,7 +7,7 @@ from passbook.lib.models import UUIDModel
class PolicyBindingModel(models.Model): 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( policies = models.ManyToManyField(
Policy, through="PolicyBinding", related_name="+", blank=True Policy, through="PolicyBinding", related_name="+", blank=True