51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
# Generated by Django 4.0.4 on 2022-05-30 18:08
|
|
from django.apps.registry import Apps
|
|
from django.db import migrations, models
|
|
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
|
|
|
from authentik.events.models import TransportMode
|
|
|
|
|
|
def notify_local_transport(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
|
db_alias = schema_editor.connection.alias
|
|
NotificationTransport = apps.get_model("authentik_events", "NotificationTransport")
|
|
NotificationRule = apps.get_model("authentik_events", "NotificationRule")
|
|
|
|
local_transport, _ = NotificationTransport.objects.using(db_alias).update_or_create(
|
|
name="default-local-transport",
|
|
defaults={"mode": TransportMode.LOCAL},
|
|
)
|
|
|
|
for trigger in NotificationRule.objects.using(db_alias).filter(
|
|
name__in=[
|
|
"default-notify-configuration-error",
|
|
"default-notify-exception",
|
|
"default-notify-update",
|
|
]
|
|
):
|
|
trigger.transports.add(local_transport)
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
("authentik_events", "0001_squashed_0019_alter_notificationtransport_webhook_url"),
|
|
]
|
|
|
|
operations = [
|
|
migrations.AlterField(
|
|
model_name="notificationtransport",
|
|
name="mode",
|
|
field=models.TextField(
|
|
choices=[
|
|
("local", "authentik inbuilt notifications"),
|
|
("webhook", "Generic Webhook"),
|
|
("webhook_slack", "Slack Webhook (Slack/Discord)"),
|
|
("email", "Email"),
|
|
],
|
|
default="local",
|
|
),
|
|
),
|
|
migrations.RunPython(notify_local_transport),
|
|
]
|