2018-11-26 17:22:38 +00:00
|
|
|
"""passbook LDAP Forms"""
|
2018-11-11 12:41:48 +00:00
|
|
|
|
2018-11-26 17:22:38 +00:00
|
|
|
from django import forms
|
2019-02-21 15:06:57 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2018-11-11 12:41:48 +00:00
|
|
|
|
2020-06-05 18:18:45 +00:00
|
|
|
from passbook.admin.fields import CodeMirrorWidget
|
2020-06-05 10:00:27 +00:00
|
|
|
from passbook.core.expression import PropertyMappingEvaluator
|
2019-10-11 10:53:48 +00:00
|
|
|
from passbook.sources.ldap.models import LDAPPropertyMapping, LDAPSource
|
2018-11-11 12:41:48 +00:00
|
|
|
|
|
|
|
|
2018-11-26 17:22:38 +00:00
|
|
|
class LDAPSourceForm(forms.ModelForm):
|
|
|
|
"""LDAPSource Form"""
|
|
|
|
|
2020-08-01 18:00:20 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.fields["property_mappings"].queryset = LDAPPropertyMapping.objects.all()
|
|
|
|
|
2018-11-26 17:22:38 +00:00
|
|
|
class Meta:
|
|
|
|
|
|
|
|
model = LDAPSource
|
2020-08-01 18:00:20 +00:00
|
|
|
fields = [
|
|
|
|
# we don't use all common fields, as we don't use flows for this
|
|
|
|
"name",
|
|
|
|
"slug",
|
|
|
|
"enabled",
|
|
|
|
# -- start of our custom fields
|
2019-12-31 11:51:16 +00:00
|
|
|
"server_uri",
|
2020-10-18 20:39:13 +00:00
|
|
|
"start_tls",
|
2019-12-31 11:51:16 +00:00
|
|
|
"bind_cn",
|
|
|
|
"bind_password",
|
|
|
|
"base_dn",
|
2020-10-18 20:39:13 +00:00
|
|
|
"sync_users",
|
|
|
|
"sync_users_password",
|
|
|
|
"sync_groups",
|
|
|
|
"property_mappings",
|
2019-12-31 11:51:16 +00:00
|
|
|
"additional_user_dn",
|
|
|
|
"additional_group_dn",
|
|
|
|
"user_object_filter",
|
|
|
|
"group_object_filter",
|
|
|
|
"user_group_membership_field",
|
|
|
|
"object_uniqueness_field",
|
|
|
|
"sync_parent_group",
|
2019-10-10 15:36:09 +00:00
|
|
|
]
|
2018-11-26 21:09:04 +00:00
|
|
|
widgets = {
|
2019-12-31 11:51:16 +00:00
|
|
|
"name": forms.TextInput(),
|
|
|
|
"server_uri": forms.TextInput(),
|
|
|
|
"bind_cn": forms.TextInput(),
|
|
|
|
"bind_password": forms.TextInput(),
|
|
|
|
"base_dn": forms.TextInput(),
|
|
|
|
"additional_user_dn": forms.TextInput(),
|
|
|
|
"additional_group_dn": forms.TextInput(),
|
|
|
|
"user_object_filter": forms.TextInput(),
|
|
|
|
"group_object_filter": forms.TextInput(),
|
|
|
|
"user_group_membership_field": forms.TextInput(),
|
|
|
|
"object_uniqueness_field": forms.TextInput(),
|
2018-11-26 21:09:04 +00:00
|
|
|
}
|
2019-10-11 10:53:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LDAPPropertyMappingForm(forms.ModelForm):
|
|
|
|
"""LDAP Property Mapping form"""
|
|
|
|
|
2020-02-17 19:30:14 +00:00
|
|
|
template_name = "ldap/property_mapping_form.html"
|
|
|
|
|
2020-06-05 10:00:27 +00:00
|
|
|
def clean_expression(self):
|
|
|
|
"""Test Syntax"""
|
|
|
|
expression = self.cleaned_data.get("expression")
|
|
|
|
evaluator = PropertyMappingEvaluator()
|
|
|
|
evaluator.validate(expression)
|
|
|
|
return expression
|
|
|
|
|
2019-10-11 10:53:48 +00:00
|
|
|
class Meta:
|
|
|
|
|
|
|
|
model = LDAPPropertyMapping
|
2020-02-17 19:38:14 +00:00
|
|
|
fields = ["name", "object_field", "expression"]
|
2019-10-11 10:53:48 +00:00
|
|
|
widgets = {
|
2019-12-31 11:51:16 +00:00
|
|
|
"name": forms.TextInput(),
|
|
|
|
"ldap_property": forms.TextInput(),
|
|
|
|
"object_field": forms.TextInput(),
|
2020-06-05 18:18:45 +00:00
|
|
|
"expression": CodeMirrorWidget(mode="python"),
|
|
|
|
}
|
|
|
|
help_texts = {
|
|
|
|
"object_field": _("Field of the user object this value is written to.")
|
2019-10-11 10:53:48 +00:00
|
|
|
}
|