From 75b687ecbe9672907ce58c16221bf6381c2e6bf9 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 16 Feb 2020 12:30:45 +0100 Subject: [PATCH] sources/ldap: move labels from form to models --- passbook/sources/ldap/forms.py | 8 --- .../migrations/0003_auto_20191011_0825.py | 3 +- .../migrations/0006_auto_20200216_1116.py | 60 +++++++++++++++++++ passbook/sources/ldap/models.py | 21 ++++--- 4 files changed, 75 insertions(+), 17 deletions(-) create mode 100644 passbook/sources/ldap/migrations/0006_auto_20200216_1116.py diff --git a/passbook/sources/ldap/forms.py b/passbook/sources/ldap/forms.py index 6846c9e81..e940b132c 100644 --- a/passbook/sources/ldap/forms.py +++ b/passbook/sources/ldap/forms.py @@ -45,14 +45,6 @@ class LDAPSourceForm(forms.ModelForm): "policies": FilteredSelectMultiple(_("policies"), False), "property_mappings": FilteredSelectMultiple(_("Property Mappings"), False), } - labels = { - "server_uri": _("Server URI"), - "bind_cn": _("Bind CN"), - "start_tls": _("Enable Start TLS"), - "base_dn": _("Base DN"), - "additional_user_dn": _("Addition User DN"), - "additional_group_dn": _("Addition Group DN"), - } class LDAPPropertyMappingForm(forms.ModelForm): diff --git a/passbook/sources/ldap/migrations/0003_auto_20191011_0825.py b/passbook/sources/ldap/migrations/0003_auto_20191011_0825.py index 57347eb2c..e7bf40f42 100644 --- a/passbook/sources/ldap/migrations/0003_auto_20191011_0825.py +++ b/passbook/sources/ldap/migrations/0003_auto_20191011_0825.py @@ -13,8 +13,9 @@ def create_default_ad_property_mappings(apps: Apps, schema_editor): "sAMAccountName": "username", "mail": "email", } + db_alias = schema_editor.connection.alias for ldap_property, object_field in mapping.items(): - LDAPPropertyMapping.objects.get_or_create( + LDAPPropertyMapping.objects.using(db_alias).get_or_create( ldap_property=ldap_property, object_field=object_field, defaults={ diff --git a/passbook/sources/ldap/migrations/0006_auto_20200216_1116.py b/passbook/sources/ldap/migrations/0006_auto_20200216_1116.py new file mode 100644 index 000000000..e0d646c86 --- /dev/null +++ b/passbook/sources/ldap/migrations/0006_auto_20200216_1116.py @@ -0,0 +1,60 @@ +# Generated by Django 2.2.9 on 2020-02-16 11:16 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("passbook_sources_ldap", "0005_auto_20191011_1059"), + ] + + operations = [ + migrations.AlterField( + model_name="ldappropertymapping", + name="ldap_property", + field=models.TextField(verbose_name="LDAP Property"), + ), + migrations.AlterField( + model_name="ldapsource", + name="additional_group_dn", + field=models.TextField( + help_text="Prepended to Base DN for Group-queries.", + verbose_name="Addition Group DN", + ), + ), + migrations.AlterField( + model_name="ldapsource", + name="additional_user_dn", + field=models.TextField( + help_text="Prepended to Base DN for User-queries.", + verbose_name="Addition User DN", + ), + ), + migrations.AlterField( + model_name="ldapsource", + name="base_dn", + field=models.TextField(verbose_name="Base DN"), + ), + migrations.AlterField( + model_name="ldapsource", + name="bind_cn", + field=models.TextField(verbose_name="Bind CN"), + ), + migrations.AlterField( + model_name="ldapsource", + name="server_uri", + field=models.TextField( + validators=[ + django.core.validators.URLValidator(schemes=["ldap", "ldaps"]) + ], + verbose_name="Server URI", + ), + ), + migrations.AlterField( + model_name="ldapsource", + name="start_tls", + field=models.BooleanField(default=False, verbose_name="Enable Start TLS"), + ), + ] diff --git a/passbook/sources/ldap/models.py b/passbook/sources/ldap/models.py index 4e91546cd..045864dc3 100644 --- a/passbook/sources/ldap/models.py +++ b/passbook/sources/ldap/models.py @@ -2,7 +2,7 @@ from django.core.validators import URLValidator from django.db import models -from django.utils.translation import gettext as _ +from django.utils.translation import gettext_lazy as _ from passbook.core.models import Group, PropertyMapping, Source @@ -10,17 +10,22 @@ from passbook.core.models import Group, PropertyMapping, Source class LDAPSource(Source): """LDAP Authentication source""" - server_uri = models.TextField(validators=[URLValidator(schemes=["ldap", "ldaps"])]) - bind_cn = models.TextField() + server_uri = models.TextField( + validators=[URLValidator(schemes=["ldap", "ldaps"])], + verbose_name=_("Server URI"), + ) + bind_cn = models.TextField(verbose_name=_("Bind CN")) bind_password = models.TextField() - start_tls = models.BooleanField(default=False) + start_tls = models.BooleanField(default=False, verbose_name=_("Enable Start TLS")) - base_dn = models.TextField() + base_dn = models.TextField(verbose_name=_("Base DN")) additional_user_dn = models.TextField( - help_text=_("Prepended to Base DN for User-queries.") + help_text=_("Prepended to Base DN for User-queries."), + verbose_name=_("Addition User DN"), ) additional_group_dn = models.TextField( - help_text=_("Prepended to Base DN for Group-queries.") + help_text=_("Prepended to Base DN for Group-queries."), + verbose_name=_("Addition Group DN"), ) user_object_filter = models.TextField( @@ -54,7 +59,7 @@ class LDAPSource(Source): class LDAPPropertyMapping(PropertyMapping): """Map LDAP Property to User or Group object""" - ldap_property = models.TextField() + ldap_property = models.TextField(verbose_name=_("LDAP Property")) object_field = models.TextField() form = "passbook.sources.ldap.forms.LDAPPropertyMappingForm"