From e9bb583b32cffe5763bd80db22d79f7ac3fa4617 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 14 Dec 2020 10:47:49 +0100 Subject: [PATCH] providers/proxy: ensure pb_proxy is deleted and ak_proxy is created --- .../migrations/0008_auto_20200930_0810.py | 29 ------------- .../migrations/0010_auto_20201214_0942.py | 41 +++++++++++++++++++ 2 files changed, 41 insertions(+), 29 deletions(-) create mode 100644 authentik/providers/proxy/migrations/0010_auto_20201214_0942.py diff --git a/authentik/providers/proxy/migrations/0008_auto_20200930_0810.py b/authentik/providers/proxy/migrations/0008_auto_20200930_0810.py index 444ba2c79..39c245029 100644 --- a/authentik/providers/proxy/migrations/0008_auto_20200930_0810.py +++ b/authentik/providers/proxy/migrations/0008_auto_20200930_0810.py @@ -1,34 +1,6 @@ # Generated by Django 3.1.1 on 2020-09-30 08:10 -from django.apps.registry import Apps from django.db import migrations, models -from django.db.backends.base.schema import BaseDatabaseSchemaEditor - -SCOPE_AK_PROXY_EXPRESSION = """return { - "ak_proxy": { - "user_attributes": user.group_attributes() - } -}""" - - -def create_proxy_scope(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): - from authentik.providers.proxy.models import SCOPE_AK_PROXY, ProxyProvider - - ScopeMapping = apps.get_model("authentik_providers_oauth2", "ScopeMapping") - - ScopeMapping.objects.update_or_create( - scope_name=SCOPE_AK_PROXY, - defaults={ - "name": "Autogenerated OAuth2 Mapping: authentik Proxy", - "scope_name": SCOPE_AK_PROXY, - "description": "", - "expression": SCOPE_AK_PROXY_EXPRESSION, - }, - ) - - for provider in ProxyProvider.objects.all(): - provider.set_oauth_defaults() - provider.save() class Migration(migrations.Migration): @@ -74,5 +46,4 @@ class Migration(migrations.Migration): verbose_name="HTTP-Basic Username", ), ), - migrations.RunPython(create_proxy_scope), ] diff --git a/authentik/providers/proxy/migrations/0010_auto_20201214_0942.py b/authentik/providers/proxy/migrations/0010_auto_20201214_0942.py new file mode 100644 index 000000000..35bb3c570 --- /dev/null +++ b/authentik/providers/proxy/migrations/0010_auto_20201214_0942.py @@ -0,0 +1,41 @@ +# Generated by Django 3.1.4 on 2020-12-14 09:42 +from django.apps.registry import Apps +from django.db import migrations +from django.db.backends.base.schema import BaseDatabaseSchemaEditor + +SCOPE_AK_PROXY_EXPRESSION = """return { + "ak_proxy": { + "user_attributes": user.group_attributes() + } +}""" + + +def create_proxy_scope(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): + from authentik.providers.proxy.models import SCOPE_AK_PROXY, ProxyProvider + + ScopeMapping = apps.get_model("authentik_providers_oauth2", "ScopeMapping") + + ScopeMapping.objects.filter(scope_name="pb_proxy").delete() + + ScopeMapping.objects.update_or_create( + scope_name=SCOPE_AK_PROXY, + defaults={ + "name": "Autogenerated OAuth2 Mapping: authentik Proxy", + "scope_name": SCOPE_AK_PROXY, + "description": "", + "expression": SCOPE_AK_PROXY_EXPRESSION, + }, + ) + + for provider in ProxyProvider.objects.all(): + provider.set_oauth_defaults() + provider.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ("authentik_providers_proxy", "0009_auto_20201007_1721"), + ] + + operations = [migrations.RunPython(create_proxy_scope)]