44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
# Generated by Django 2.2.28 on 2022-04-13 14:22
|
|
|
|
from django.db import migrations
|
|
from django.utils.text import slugify
|
|
|
|
from authentic2 import app_settings as global_settings
|
|
from authentic2_auth_oidc import app_settings
|
|
|
|
|
|
def add_base_authenticators(apps, schema_editor):
|
|
kwargs_settings = getattr(global_settings, 'AUTH_FRONTENDS_KWARGS', {})
|
|
oidc_provider_settings = kwargs_settings.get('oidc', {})
|
|
show_condition = oidc_provider_settings.get('show_condition')
|
|
|
|
BaseAuthenticator = apps.get_model('authenticators', 'BaseAuthenticator')
|
|
OIDCProvider = apps.get_model('authentic2_auth_oidc', 'OIDCProvider')
|
|
|
|
for provider in OIDCProvider.objects.all():
|
|
if isinstance(show_condition, dict):
|
|
show_condition = show_condition.get(provider.slug, '')
|
|
|
|
base_authenticator = BaseAuthenticator.objects.create(
|
|
name=provider.name,
|
|
slug=provider.slug or slugify(provider.name),
|
|
ou=provider.ou,
|
|
enabled=provider.show and app_settings.ENABLE,
|
|
order=oidc_provider_settings.get('priority', 2),
|
|
show_condition=show_condition,
|
|
)
|
|
provider.baseauthenticator_ptr = base_authenticator.pk
|
|
provider.save()
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('authentic2_auth_oidc', '0009_oidcprovider_baseauthenticator_ptr'),
|
|
('authenticators', '0001_initial'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(add_base_authenticators, reverse_code=migrations.RunPython.noop),
|
|
]
|