From 3eb3a9eab9123e4aef3dca0d1440cdcfce55f808 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 24 Aug 2022 23:02:34 +0200 Subject: [PATCH] *: remove remaining default creation code in squashed migrations Signed-off-by: Jens Langhammer --- ...alter_notificationtransport_webhook_url.py | 132 ------------------ ...8_1542_squashed_0017_auto_20210329_1334.py | 22 --- ...01_squashed_0005_tenant_web_certificate.py | 28 ---- 3 files changed, 182 deletions(-) diff --git a/authentik/events/migrations/0001_squashed_0019_alter_notificationtransport_webhook_url.py b/authentik/events/migrations/0001_squashed_0019_alter_notificationtransport_webhook_url.py index 3f8897e7c..e5a05aad3 100644 --- a/authentik/events/migrations/0001_squashed_0019_alter_notificationtransport_webhook_url.py +++ b/authentik/events/migrations/0001_squashed_0019_alter_notificationtransport_webhook_url.py @@ -28,126 +28,6 @@ def convert_user_to_json(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): event.save() -def notify_configuration_error(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): - db_alias = schema_editor.connection.alias - Group = apps.get_model("authentik_core", "Group") - PolicyBinding = apps.get_model("authentik_policies", "PolicyBinding") - EventMatcherPolicy = apps.get_model("authentik_policies_event_matcher", "EventMatcherPolicy") - NotificationRule = apps.get_model("authentik_events", "NotificationRule") - NotificationTransport = apps.get_model("authentik_events", "NotificationTransport") - - admin_group = ( - Group.objects.using(db_alias).filter(name="authentik Admins", is_superuser=True).first() - ) - - policy, _ = EventMatcherPolicy.objects.using(db_alias).update_or_create( - name="default-match-configuration-error", - defaults={"action": EventAction.CONFIGURATION_ERROR}, - ) - trigger, _ = NotificationRule.objects.using(db_alias).update_or_create( - name="default-notify-configuration-error", - defaults={"group": admin_group, "severity": NotificationSeverity.ALERT}, - ) - trigger.transports.set( - NotificationTransport.objects.using(db_alias).filter(name="default-email-transport") - ) - trigger.save() - PolicyBinding.objects.using(db_alias).update_or_create( - target=trigger, - policy=policy, - defaults={ - "order": 0, - }, - ) - - -def notify_update(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): - db_alias = schema_editor.connection.alias - Group = apps.get_model("authentik_core", "Group") - PolicyBinding = apps.get_model("authentik_policies", "PolicyBinding") - EventMatcherPolicy = apps.get_model("authentik_policies_event_matcher", "EventMatcherPolicy") - NotificationRule = apps.get_model("authentik_events", "NotificationRule") - NotificationTransport = apps.get_model("authentik_events", "NotificationTransport") - - admin_group = ( - Group.objects.using(db_alias).filter(name="authentik Admins", is_superuser=True).first() - ) - - policy, _ = EventMatcherPolicy.objects.using(db_alias).update_or_create( - name="default-match-update", - defaults={"action": EventAction.UPDATE_AVAILABLE}, - ) - trigger, _ = NotificationRule.objects.using(db_alias).update_or_create( - name="default-notify-update", - defaults={"group": admin_group, "severity": NotificationSeverity.ALERT}, - ) - trigger.transports.set( - NotificationTransport.objects.using(db_alias).filter(name="default-email-transport") - ) - trigger.save() - PolicyBinding.objects.using(db_alias).update_or_create( - target=trigger, - policy=policy, - defaults={ - "order": 0, - }, - ) - - -def notify_exception(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): - db_alias = schema_editor.connection.alias - Group = apps.get_model("authentik_core", "Group") - PolicyBinding = apps.get_model("authentik_policies", "PolicyBinding") - EventMatcherPolicy = apps.get_model("authentik_policies_event_matcher", "EventMatcherPolicy") - NotificationRule = apps.get_model("authentik_events", "NotificationRule") - NotificationTransport = apps.get_model("authentik_events", "NotificationTransport") - - admin_group = ( - Group.objects.using(db_alias).filter(name="authentik Admins", is_superuser=True).first() - ) - - policy_policy_exc, _ = EventMatcherPolicy.objects.using(db_alias).update_or_create( - name="default-match-policy-exception", - defaults={"action": EventAction.POLICY_EXCEPTION}, - ) - policy_pm_exc, _ = EventMatcherPolicy.objects.using(db_alias).update_or_create( - name="default-match-property-mapping-exception", - defaults={"action": EventAction.PROPERTY_MAPPING_EXCEPTION}, - ) - trigger, _ = NotificationRule.objects.using(db_alias).update_or_create( - name="default-notify-exception", - defaults={"group": admin_group, "severity": NotificationSeverity.ALERT}, - ) - trigger.transports.set( - NotificationTransport.objects.using(db_alias).filter(name="default-email-transport") - ) - trigger.save() - PolicyBinding.objects.using(db_alias).update_or_create( - target=trigger, - policy=policy_policy_exc, - defaults={ - "order": 0, - }, - ) - PolicyBinding.objects.using(db_alias).update_or_create( - target=trigger, - policy=policy_pm_exc, - defaults={ - "order": 1, - }, - ) - - -def transport_email_global(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): - db_alias = schema_editor.connection.alias - NotificationTransport = apps.get_model("authentik_events", "NotificationTransport") - - NotificationTransport.objects.using(db_alias).update_or_create( - name="default-email-transport", - defaults={"mode": TransportMode.EMAIL}, - ) - - def token_view_to_secret_view(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): from authentik.events.models import EventAction @@ -432,18 +312,6 @@ class Migration(migrations.Migration): "verbose_name_plural": "Notifications", }, ), - migrations.RunPython( - code=transport_email_global, - ), - migrations.RunPython( - code=notify_configuration_error, - ), - migrations.RunPython( - code=notify_update, - ), - migrations.RunPython( - code=notify_exception, - ), migrations.AddField( model_name="notificationtransport", name="send_once", diff --git a/authentik/flows/migrations/0012_auto_20200908_1542_squashed_0017_auto_20210329_1334.py b/authentik/flows/migrations/0012_auto_20200908_1542_squashed_0017_auto_20210329_1334.py index 6f81d11d7..2002fe9bd 100644 --- a/authentik/flows/migrations/0012_auto_20200908_1542_squashed_0017_auto_20210329_1334.py +++ b/authentik/flows/migrations/0012_auto_20200908_1542_squashed_0017_auto_20210329_1334.py @@ -19,25 +19,6 @@ def update_flow_designation(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) flow.save() -# First stage for default-source-enrollment flow (prompt stage) -# needs to have its policy re-evaluated -def update_default_source_enrollment_flow_binding( - apps: Apps, schema_editor: BaseDatabaseSchemaEditor -): - Flow = apps.get_model("authentik_flows", "Flow") - FlowStageBinding = apps.get_model("authentik_flows", "FlowStageBinding") - db_alias = schema_editor.connection.alias - - flows = Flow.objects.using(db_alias).filter(slug="default-source-enrollment") - if not flows.exists(): - return - flow = flows.first() - - binding = FlowStageBinding.objects.get(target=flow, order=0) - binding.re_evaluate_policies = True - binding.save() - - class Migration(migrations.Migration): replaces = [ @@ -101,9 +82,6 @@ class Migration(migrations.Migration): help_text="When this option is enabled, the planner will re-evaluate policies bound to this binding.", ), ), - migrations.RunPython( - code=update_default_source_enrollment_flow_binding, - ), migrations.AlterField( model_name="flowstagebinding", name="re_evaluate_policies", diff --git a/authentik/tenants/migrations/0001_squashed_0005_tenant_web_certificate.py b/authentik/tenants/migrations/0001_squashed_0005_tenant_web_certificate.py index b5a6c2a3e..3164ac674 100644 --- a/authentik/tenants/migrations/0001_squashed_0005_tenant_web_certificate.py +++ b/authentik/tenants/migrations/0001_squashed_0005_tenant_web_certificate.py @@ -10,29 +10,6 @@ from django.db.backends.base.schema import BaseDatabaseSchemaEditor import authentik.lib.utils.time -def create_default_tenant(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): - Flow = apps.get_model("authentik_flows", "Flow") - Tenant = apps.get_model("authentik_tenants", "Tenant") - - db_alias = schema_editor.connection.alias - - default_authentication = ( - Flow.objects.using(db_alias).filter(slug="default-authentication-flow").first() - ) - default_invalidation = ( - Flow.objects.using(db_alias).filter(slug="default-invalidation-flow").first() - ) - - tenant, _ = Tenant.objects.using(db_alias).update_or_create( - domain="authentik-default", - default=True, - defaults={ - "flow_authentication": default_authentication, - "flow_invalidation": default_invalidation, - }, - ) - - class Migration(migrations.Migration): replaces = [ @@ -46,8 +23,6 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ("authentik_flows", "0018_oob_flows"), - ("authentik_flows", "0008_default_flows"), ("authentik_crypto", "0003_certificatekeypair_managed"), ] @@ -115,9 +90,6 @@ class Migration(migrations.Migration): "verbose_name_plural": "Tenants", }, ), - migrations.RunPython( - code=create_default_tenant, - ), migrations.AddField( model_name="tenant", name="branding_favicon",