<NME> 0018_update_disabled_accounts_aliases.py
<BEF> ADDFILE
<MSG> Add migration to disable disabled accounts' aliases

<DFF> @@ -0,0 +1,28 @@
+# Generated by Django 2.2.17 on 2021-01-28 13:40
+
+from django.db import migrations
+
+
+def update_disabled_accounts_aliases(apps, schema_editor):
+    User = apps.get_model('core', 'User')
+    Alias = apps.get_model('admin', 'Alias')
+
+    disabled_accounts = User.objects.filter(
+        mailbox__isnull=False, is_active=False)
+
+    Alias.objects.filter(
+        address__in=list(disabled_accounts.values_list('email', flat=True)),
+        enabled=True,
+    ).update(enabled=False)
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('admin', '0017_alarm'),
+        ('core', '0022_user_tfa_enabled'),
+    ]
+
+    operations = [
+        migrations.RunPython(update_disabled_accounts_aliases),
+    ]

Add migration to disable disabled accounts' aliases