migrate to per-model UUID Primary key, remove UUIDModel (#26)
* *: migrate to per-model UUID Primary key, remove UUIDModel * *: fix import order, fix unittests
This commit is contained in:
		| @ -1,4 +1,4 @@ | ||||
| # Generated by Django 2.2.6 on 2019-10-08 20:43 | ||||
| # Generated by Django 3.0.6 on 2020-05-19 22:08 | ||||
|  | ||||
| import django.core.validators | ||||
| import django.db.models.deletion | ||||
| @ -28,10 +28,12 @@ class Migration(migrations.Migration): | ||||
|                         to="passbook_core.PropertyMapping", | ||||
|                     ), | ||||
|                 ), | ||||
|                 ("ldap_property", models.TextField()), | ||||
|                 ("object_field", models.TextField()), | ||||
|             ], | ||||
|             options={"abstract": False,}, | ||||
|             options={ | ||||
|                 "verbose_name": "LDAP Property Mapping", | ||||
|                 "verbose_name_plural": "LDAP Property Mappings", | ||||
|             }, | ||||
|             bases=("passbook_core.propertymapping",), | ||||
|         ), | ||||
|         migrations.CreateModel( | ||||
| @ -50,38 +52,71 @@ class Migration(migrations.Migration): | ||||
|                 ), | ||||
|                 ( | ||||
|                     "server_uri", | ||||
|                     models.URLField( | ||||
|                     models.TextField( | ||||
|                         validators=[ | ||||
|                             django.core.validators.URLValidator( | ||||
|                                 schemes=["ldap", "ldaps"] | ||||
|                             ) | ||||
|                         ] | ||||
|                         ], | ||||
|                         verbose_name="Server URI", | ||||
|                     ), | ||||
|                 ), | ||||
|                 ("bind_cn", models.TextField()), | ||||
|                 ("bind_cn", models.TextField(verbose_name="Bind CN")), | ||||
|                 ("bind_password", models.TextField()), | ||||
|                 ("start_tls", models.BooleanField(default=False)), | ||||
|                 ("base_dn", models.TextField()), | ||||
|                 ( | ||||
|                     "start_tls", | ||||
|                     models.BooleanField(default=False, verbose_name="Enable Start TLS"), | ||||
|                 ), | ||||
|                 ("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( | ||||
|                         default="(objectCategory=Person)", | ||||
|                         help_text="Consider Objects matching this filter to be Users.", | ||||
|                     ), | ||||
|                 ), | ||||
|                 ( | ||||
|                     "user_group_membership_field", | ||||
|                     models.TextField( | ||||
|                         default="memberOf", | ||||
|                         help_text="Field which contains Groups of user.", | ||||
|                     ), | ||||
|                 ), | ||||
|                 ( | ||||
|                     "group_object_filter", | ||||
|                     models.TextField( | ||||
|                         default="(objectCategory=Group)", | ||||
|                         help_text="Consider Objects matching this filter to be Groups.", | ||||
|                     ), | ||||
|                 ), | ||||
|                 ( | ||||
|                     "object_uniqueness_field", | ||||
|                     models.TextField( | ||||
|                         default="objectSid", | ||||
|                         help_text="Field which contains a unique Identifier.", | ||||
|                     ), | ||||
|                 ), | ||||
|                 ("user_object_filter", models.TextField()), | ||||
|                 ("group_object_filter", models.TextField()), | ||||
|                 ("sync_groups", models.BooleanField(default=True)), | ||||
|                 ( | ||||
|                     "sync_parent_group", | ||||
|                     models.ForeignKey( | ||||
|                         blank=True, | ||||
|                         default=None, | ||||
|                         null=True, | ||||
|                         on_delete=django.db.models.deletion.SET_DEFAULT, | ||||
|                         to="passbook_core.Group", | ||||
|                     ), | ||||
|  | ||||
| @ -1,20 +0,0 @@ | ||||
| # Generated by Django 2.2.6 on 2019-10-11 08:25 | ||||
|  | ||||
| from django.db import migrations | ||||
|  | ||||
|  | ||||
| class Migration(migrations.Migration): | ||||
|  | ||||
|     dependencies = [ | ||||
|         ("passbook_sources_ldap", "0001_initial"), | ||||
|     ] | ||||
|  | ||||
|     operations = [ | ||||
|         migrations.AlterModelOptions( | ||||
|             name="ldappropertymapping", | ||||
|             options={ | ||||
|                 "verbose_name": "LDAP Property Mapping", | ||||
|                 "verbose_name_plural": "LDAP Property Mappings", | ||||
|             }, | ||||
|         ), | ||||
|     ] | ||||
| @ -1,33 +0,0 @@ | ||||
| # Generated by Django 2.2.6 on 2019-10-11 08:25 | ||||
|  | ||||
| from django.apps.registry import Apps | ||||
| from django.db import migrations | ||||
|  | ||||
|  | ||||
| def create_default_ad_property_mappings(apps: Apps, schema_editor): | ||||
|     LDAPPropertyMapping = apps.get_model("passbook_sources_ldap", "LDAPPropertyMapping") | ||||
|     mapping = { | ||||
|         "name": "name", | ||||
|         "givenName": "first_name", | ||||
|         "sn": "last_name", | ||||
|         "sAMAccountName": "username", | ||||
|         "mail": "email", | ||||
|     } | ||||
|     db_alias = schema_editor.connection.alias | ||||
|     for ldap_property, object_field in mapping.items(): | ||||
|         LDAPPropertyMapping.objects.using(db_alias).get_or_create( | ||||
|             ldap_property=ldap_property, | ||||
|             object_field=object_field, | ||||
|             defaults={ | ||||
|                 "name": f"Autogenerated LDAP Mapping: {ldap_property} -> {object_field}" | ||||
|             }, | ||||
|         ) | ||||
|  | ||||
|  | ||||
| class Migration(migrations.Migration): | ||||
|  | ||||
|     dependencies = [ | ||||
|         ("passbook_sources_ldap", "0002_auto_20191011_0825"), | ||||
|     ] | ||||
|  | ||||
|     operations = [migrations.RunPython(create_default_ad_property_mappings)] | ||||
| @ -1,35 +0,0 @@ | ||||
| # Generated by Django 2.2.6 on 2019-10-11 08:39 | ||||
|  | ||||
| import django.core.validators | ||||
| import django.db.models.deletion | ||||
| from django.db import migrations, models | ||||
|  | ||||
|  | ||||
| class Migration(migrations.Migration): | ||||
|  | ||||
|     dependencies = [ | ||||
|         ("passbook_sources_ldap", "0003_auto_20191011_0825"), | ||||
|     ] | ||||
|  | ||||
|     operations = [ | ||||
|         migrations.AlterField( | ||||
|             model_name="ldapsource", | ||||
|             name="server_uri", | ||||
|             field=models.TextField( | ||||
|                 validators=[ | ||||
|                     django.core.validators.URLValidator(schemes=["ldap", "ldaps"]) | ||||
|                 ] | ||||
|             ), | ||||
|         ), | ||||
|         migrations.AlterField( | ||||
|             model_name="ldapsource", | ||||
|             name="sync_parent_group", | ||||
|             field=models.ForeignKey( | ||||
|                 blank=True, | ||||
|                 default=None, | ||||
|                 null=True, | ||||
|                 on_delete=django.db.models.deletion.SET_DEFAULT, | ||||
|                 to="passbook_core.Group", | ||||
|             ), | ||||
|         ), | ||||
|     ] | ||||
| @ -1,44 +0,0 @@ | ||||
| # Generated by Django 2.2.6 on 2019-10-11 10:59 | ||||
|  | ||||
| from django.db import migrations, models | ||||
|  | ||||
|  | ||||
| class Migration(migrations.Migration): | ||||
|  | ||||
|     dependencies = [ | ||||
|         ("passbook_sources_ldap", "0004_auto_20191011_0839"), | ||||
|     ] | ||||
|  | ||||
|     operations = [ | ||||
|         migrations.AddField( | ||||
|             model_name="ldapsource", | ||||
|             name="object_uniqueness_field", | ||||
|             field=models.TextField( | ||||
|                 default="objectSid", | ||||
|                 help_text="Field which contains a unique Identifier.", | ||||
|             ), | ||||
|         ), | ||||
|         migrations.AddField( | ||||
|             model_name="ldapsource", | ||||
|             name="user_group_membership_field", | ||||
|             field=models.TextField( | ||||
|                 default="memberOf", help_text="Field which contains Groups of user." | ||||
|             ), | ||||
|         ), | ||||
|         migrations.AlterField( | ||||
|             model_name="ldapsource", | ||||
|             name="group_object_filter", | ||||
|             field=models.TextField( | ||||
|                 default="(objectCategory=Group)", | ||||
|                 help_text="Consider Objects matching this filter to be Groups.", | ||||
|             ), | ||||
|         ), | ||||
|         migrations.AlterField( | ||||
|             model_name="ldapsource", | ||||
|             name="user_object_filter", | ||||
|             field=models.TextField( | ||||
|                 default="(objectCategory=Person)", | ||||
|                 help_text="Consider Objects matching this filter to be Users.", | ||||
|             ), | ||||
|         ), | ||||
|     ] | ||||
| @ -1,60 +0,0 @@ | ||||
| # 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"), | ||||
|         ), | ||||
|     ] | ||||
| @ -1,46 +0,0 @@ | ||||
| # Generated by Django 3.0.3 on 2020-02-17 16:19 | ||||
|  | ||||
| from django.apps.registry import Apps | ||||
| from django.db import migrations | ||||
|  | ||||
|  | ||||
| def cleanup_old_autogenerated(apps, schema_editor): | ||||
|     LDAPPropertyMapping = apps.get_model("passbook_sources_ldap", "LDAPPropertyMapping") | ||||
|     db_alias = schema_editor.connection.alias | ||||
|     LDAPPropertyMapping.objects.using(db_alias).filter( | ||||
|         name__startswith="Autogenerated" | ||||
|     ).delete() | ||||
|  | ||||
|  | ||||
| def create_default_ad_property_mappings(apps: Apps, schema_editor): | ||||
|     LDAPPropertyMapping = apps.get_model("passbook_sources_ldap", "LDAPPropertyMapping") | ||||
|     mapping = { | ||||
|         "name": "{{ ldap.name }}", | ||||
|         "first_name": "{{ ldap.givenName }}", | ||||
|         "last_name": "{{ ldap.sn }}", | ||||
|         "username": "{{ ldap.sAMAccountName }}", | ||||
|         "email": "{{ ldap.mail }}", | ||||
|     } | ||||
|     db_alias = schema_editor.connection.alias | ||||
|     for object_field, expression in mapping.items(): | ||||
|         LDAPPropertyMapping.objects.using(db_alias).get_or_create( | ||||
|             expression=expression, | ||||
|             object_field=object_field, | ||||
|             defaults={ | ||||
|                 "name": f"Autogenerated LDAP Mapping: {expression} -> {object_field}" | ||||
|             }, | ||||
|         ) | ||||
|  | ||||
|  | ||||
| class Migration(migrations.Migration): | ||||
|  | ||||
|     dependencies = [ | ||||
|         ("passbook_sources_ldap", "0006_auto_20200216_1116"), | ||||
|         ("passbook_core", "0007_auto_20200217_1934"), | ||||
|     ] | ||||
|  | ||||
|     operations = [ | ||||
|         migrations.RunPython(cleanup_old_autogenerated), | ||||
|         migrations.RemoveField(model_name="ldappropertymapping", name="ldap_property",), | ||||
|         migrations.RunPython(create_default_ad_property_mappings), | ||||
|     ] | ||||
		Reference in New Issue
	
	Block a user
	 Jens L
					Jens L