diff --git a/awx/main/migrations/0081_v360_notify_on_start.py b/awx/main/migrations/0081_v360_notify_on_start.py index f8578e6227..4240905f40 100644 --- a/awx/main/migrations/0081_v360_notify_on_start.py +++ b/awx/main/migrations/0081_v360_notify_on_start.py @@ -5,6 +5,21 @@ from __future__ import unicode_literals from django.db import migrations, models +def forwards_split_unified_job_template_any(apps, schema_editor): + UnifiedJobTemplate = apps.get_model('main', 'unifiedjobtemplate') + for ujt in UnifiedJobTemplate.objects.all(): + for ujt_notification in ujt.notification_templates_any.all(): + ujt.notification_templates_success.add(ujt_notification) + ujt.notification_templates_error.add(ujt_notification) + +def forwards_split_organization_any(apps, schema_editor): + Organization = apps.get_model('main', 'organization') + for org in Organization.objects.all(): + for org_notification in org.notification_templates_any.all(): + org.notification_templates_success.add(org_notification) + org.notification_templates_error.add(org_notification) + + class Migration(migrations.Migration): dependencies = [ @@ -22,7 +37,8 @@ class Migration(migrations.Migration): name='notification_templates_started', field=models.ManyToManyField(blank=True, related_name='unifiedjobtemplate_notification_templates_for_started', to='main.NotificationTemplate'), ), -# migrations.RunPython() stuff goes in here + # Separate out "any" notifications into "success" and "error" before the "any" state gets deleted. + migrations.RunPython(forwards_split_unified_job_template_any, forwards_split_organization_any), migrations.RemoveField( model_name='organization', name='notification_templates_any', diff --git a/awx/main/models/notifications.py b/awx/main/models/notifications.py index eb9121fd21..cdec14f953 100644 --- a/awx/main/models/notifications.py +++ b/awx/main/models/notifications.py @@ -243,8 +243,6 @@ class JobNotificationMixin(object): notification_template_type = 'error' all_notification_templates = set(notification_templates.get(notification_template_type, [])) if len(all_notification_templates): - # if status_str != 'running': - # all_notification_templates.update(notification_templates.get('any', [])) try: (notification_subject, notification_body) = getattr(self, 'build_notification_%s_message' % status_str)() except AttributeError: