2019-10-28 16:40:57 +00:00
|
|
|
"""Source API Views"""
|
|
|
|
from rest_framework.serializers import ModelSerializer
|
|
|
|
from rest_framework.viewsets import ModelViewSet
|
|
|
|
|
|
|
|
from passbook.admin.forms.source import SOURCE_SERIALIZER_FIELDS
|
2019-10-28 16:55:36 +00:00
|
|
|
from passbook.sources.ldap.models import LDAPPropertyMapping, LDAPSource
|
2019-10-28 16:40:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LDAPSourceSerializer(ModelSerializer):
|
|
|
|
"""LDAP Source Serializer"""
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = LDAPSource
|
|
|
|
fields = SOURCE_SERIALIZER_FIELDS + [
|
2019-12-31 11:51:16 +00:00
|
|
|
"server_uri",
|
|
|
|
"bind_cn",
|
|
|
|
"bind_password",
|
|
|
|
"start_tls",
|
|
|
|
"base_dn",
|
|
|
|
"additional_user_dn",
|
|
|
|
"additional_group_dn",
|
|
|
|
"user_object_filter",
|
|
|
|
"group_object_filter",
|
|
|
|
"user_group_membership_field",
|
|
|
|
"object_uniqueness_field",
|
2020-05-23 21:01:38 +01:00
|
|
|
"sync_users",
|
2019-12-31 11:51:16 +00:00
|
|
|
"sync_groups",
|
|
|
|
"sync_parent_group",
|
|
|
|
"property_mappings",
|
2019-10-28 16:40:57 +00:00
|
|
|
]
|
2019-12-31 11:51:16 +00:00
|
|
|
extra_kwargs = {"bind_password": {"write_only": True}}
|
2019-10-28 16:40:57 +00:00
|
|
|
|
|
|
|
|
2019-10-28 16:55:36 +00:00
|
|
|
class LDAPPropertyMappingSerializer(ModelSerializer):
|
|
|
|
"""LDAP PropertyMapping Serializer"""
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = LDAPPropertyMapping
|
2020-02-17 19:38:14 +00:00
|
|
|
fields = ["pk", "name", "expression", "object_field"]
|
2019-10-28 16:55:36 +00:00
|
|
|
|
|
|
|
|
2019-10-28 16:40:57 +00:00
|
|
|
class LDAPSourceViewSet(ModelViewSet):
|
2019-10-28 16:55:36 +00:00
|
|
|
"""LDAP Source Viewset"""
|
2019-10-28 16:40:57 +00:00
|
|
|
|
|
|
|
queryset = LDAPSource.objects.all()
|
|
|
|
serializer_class = LDAPSourceSerializer
|
2019-10-28 16:55:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LDAPPropertyMappingViewSet(ModelViewSet):
|
|
|
|
"""LDAP PropertyMapping Viewset"""
|
|
|
|
|
|
|
|
queryset = LDAPPropertyMapping.objects.all()
|
|
|
|
serializer_class = LDAPPropertyMappingSerializer
|