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),
|
||||
]
|
@ -1,4 +1,4 @@
|
||||
# Generated by Django 2.2.6 on 2019-10-07 14:07
|
||||
# Generated by Django 3.0.6 on 2020-05-19 22:08
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
@ -28,10 +28,24 @@ class Migration(migrations.Migration):
|
||||
),
|
||||
),
|
||||
("provider_type", models.CharField(max_length=255)),
|
||||
("request_token_url", models.CharField(blank=True, max_length=255)),
|
||||
("authorization_url", models.CharField(max_length=255)),
|
||||
("access_token_url", models.CharField(max_length=255)),
|
||||
("profile_url", models.CharField(max_length=255)),
|
||||
(
|
||||
"request_token_url",
|
||||
models.CharField(
|
||||
blank=True, max_length=255, verbose_name="Request Token URL"
|
||||
),
|
||||
),
|
||||
(
|
||||
"authorization_url",
|
||||
models.CharField(max_length=255, verbose_name="Authorization URL"),
|
||||
),
|
||||
(
|
||||
"access_token_url",
|
||||
models.CharField(max_length=255, verbose_name="Access Token URL"),
|
||||
),
|
||||
(
|
||||
"profile_url",
|
||||
models.CharField(max_length=255, verbose_name="Profile URL"),
|
||||
),
|
||||
("consumer_key", models.TextField()),
|
||||
("consumer_secret", models.TextField()),
|
||||
],
|
||||
|
@ -1,35 +0,0 @@
|
||||
# Generated by Django 3.0.3 on 2020-02-17 15:26
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("passbook_sources_oauth", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="oauthsource",
|
||||
name="access_token_url",
|
||||
field=models.CharField(max_length=255, verbose_name="Access Token URL"),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="oauthsource",
|
||||
name="authorization_url",
|
||||
field=models.CharField(max_length=255, verbose_name="Authorization URL"),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="oauthsource",
|
||||
name="profile_url",
|
||||
field=models.CharField(max_length=255, verbose_name="Profile URL"),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="oauthsource",
|
||||
name="request_token_url",
|
||||
field=models.CharField(
|
||||
blank=True, max_length=255, verbose_name="Request Token URL"
|
||||
),
|
||||
),
|
||||
]
|
@ -60,6 +60,9 @@ class OAuthSource(Source):
|
||||
view_name=reverse((view_name), kwargs={"source_slug": self.slug}),
|
||||
)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"OAuth Source {self.name}"
|
||||
|
||||
class Meta:
|
||||
|
||||
verbose_name = _("Generic OAuth Source")
|
||||
|
@ -13,7 +13,7 @@ class OpenIDConnectOAuthRedirect(OAuthRedirect):
|
||||
|
||||
def get_additional_parameters(self, source: OAuthSource):
|
||||
return {
|
||||
"scope": "openid email",
|
||||
"scope": "openid email profile",
|
||||
}
|
||||
|
||||
|
||||
@ -26,9 +26,9 @@ class OpenIDConnectOAuth2Callback(OAuthCallback):
|
||||
|
||||
def get_or_create_user(self, source: OAuthSource, access, info: Dict[str, str]):
|
||||
user_data = {
|
||||
"username": info.get("username"),
|
||||
"username": info.get("nickname"),
|
||||
"email": info.get("email"),
|
||||
"name": info.get("username"),
|
||||
"name": info.get("name"),
|
||||
"password": None,
|
||||
}
|
||||
return user_get_or_create(**user_data)
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Generated by Django 2.2.6 on 2019-11-07 13:54
|
||||
# Generated by Django 3.0.6 on 2020-05-19 22:08
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
@ -9,7 +9,8 @@ class Migration(migrations.Migration):
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
("passbook_core", "0005_merge_20191025_2022"),
|
||||
("passbook_crypto", "0001_initial"),
|
||||
("passbook_core", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
@ -27,15 +28,41 @@ class Migration(migrations.Migration):
|
||||
to="passbook_core.Source",
|
||||
),
|
||||
),
|
||||
("acs_url", models.URLField()),
|
||||
("slo_url", models.URLField()),
|
||||
("entity_id", models.TextField(blank=True, default=None)),
|
||||
("idp_url", models.URLField()),
|
||||
(
|
||||
"issuer",
|
||||
models.TextField(
|
||||
blank=True,
|
||||
default=None,
|
||||
help_text="Also known as Entity ID. Defaults the Metadata URL.",
|
||||
verbose_name="Issuer",
|
||||
),
|
||||
),
|
||||
("idp_url", models.URLField(verbose_name="IDP URL")),
|
||||
(
|
||||
"idp_logout_url",
|
||||
models.URLField(
|
||||
blank=True,
|
||||
default=None,
|
||||
null=True,
|
||||
verbose_name="IDP Logout URL",
|
||||
),
|
||||
),
|
||||
("auto_logout", models.BooleanField(default=False)),
|
||||
("signing_cert", models.TextField()),
|
||||
("signing_key", models.TextField()),
|
||||
(
|
||||
"signing_kp",
|
||||
models.ForeignKey(
|
||||
default=None,
|
||||
help_text="Certificate Key Pair of the IdP which Assertions are validated against.",
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
to="passbook_crypto.CertificateKeyPair",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={"abstract": False,},
|
||||
options={
|
||||
"verbose_name": "SAML Source",
|
||||
"verbose_name_plural": "SAML Sources",
|
||||
},
|
||||
bases=("passbook_core.source",),
|
||||
),
|
||||
]
|
||||
|
@ -1,22 +0,0 @@
|
||||
# Generated by Django 2.2.6 on 2019-11-07 15:05
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("passbook_sources_saml", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name="samlsource",
|
||||
options={
|
||||
"verbose_name": "SAML Source",
|
||||
"verbose_name_plural": "SAML Sources",
|
||||
},
|
||||
),
|
||||
migrations.RemoveField(model_name="samlsource", name="acs_url",),
|
||||
migrations.RemoveField(model_name="samlsource", name="slo_url",),
|
||||
]
|
@ -1,19 +0,0 @@
|
||||
# Generated by Django 2.2.6 on 2019-11-07 15:50
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("passbook_sources_saml", "0002_auto_20191107_1505"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(model_name="samlsource", name="signing_key",),
|
||||
migrations.AddField(
|
||||
model_name="samlsource",
|
||||
name="idp_logout_url",
|
||||
field=models.URLField(blank=True, default=None, null=True),
|
||||
),
|
||||
]
|
@ -1,30 +0,0 @@
|
||||
# Generated by Django 3.0.3 on 2020-02-17 15:26
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("passbook_sources_saml", "0003_auto_20191107_1550"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="samlsource",
|
||||
name="entity_id",
|
||||
field=models.TextField(blank=True, default=None, verbose_name="Entity ID"),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="samlsource",
|
||||
name="idp_logout_url",
|
||||
field=models.URLField(
|
||||
blank=True, default=None, null=True, verbose_name="IDP Logout URL"
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="samlsource",
|
||||
name="idp_url",
|
||||
field=models.URLField(verbose_name="IDP URL"),
|
||||
),
|
||||
]
|
@ -1,26 +0,0 @@
|
||||
# Generated by Django 3.0.3 on 2020-02-20 16:21
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("passbook_sources_saml", "0004_auto_20200217_1526"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name="samlsource", old_name="entity_id", new_name="issuer",
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="samlsource",
|
||||
name="issuer",
|
||||
field=models.TextField(
|
||||
blank=True,
|
||||
default=None,
|
||||
help_text="Also known as Entity ID. Defaults the Metadata URL.",
|
||||
verbose_name="Issuer",
|
||||
),
|
||||
),
|
||||
]
|
@ -1,27 +0,0 @@
|
||||
# Generated by Django 3.0.3 on 2020-03-03 22:01
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("passbook_crypto", "0001_initial"),
|
||||
("passbook_sources_saml", "0005_auto_20200220_1621"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(model_name="samlsource", name="signing_cert",),
|
||||
migrations.AddField(
|
||||
model_name="samlsource",
|
||||
name="signing_kp",
|
||||
field=models.ForeignKey(
|
||||
default=None,
|
||||
help_text="Certificate Key Pair of the IdP which Assertions are validated against.",
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
to="passbook_crypto.CertificateKeyPair",
|
||||
),
|
||||
),
|
||||
]
|
Reference in New Issue
Block a user