Notification serializers, views, and tasks

* Implement concrete Notification model for notification runs
* Implement NotificationTemplate and Notification serializers and views
* Implement ancillary views
* Implement NotificationTemplate trigger m2m fields on all job templates
  via a fields mixin
* Link NotificationTemplates with an org
* Link notifications with the activity stream
* Implement Notification celery tasks
* Extend Backend field parameters to identify sender and receiver as
  parameters needed by the message and not the backend itself
* Updates to backends to better fit the django email backend model as it
  relates to Messages
* Implement success job chain task + notifications
* Implement notifications in error job chain task
This commit is contained in:
Matthew Jones
2016-02-09 23:12:55 -05:00
parent 319deffc18
commit 8db2f60405
18 changed files with 502 additions and 20 deletions

View File

@@ -10,6 +10,7 @@ import urlparse
# Django
from django.conf import settings
from django.db import models
from django.db.models import Q
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_str, smart_text
from django.core.exceptions import ValidationError
@@ -20,6 +21,7 @@ from django.utils.timezone import now, make_aware, get_default_timezone
from awx.lib.compat import slugify
from awx.main.models.base import * # noqa
from awx.main.models.jobs import Job
from awx.main.models.notifications import NotificationTemplate
from awx.main.models.unified_jobs import * # noqa
from awx.main.utils import update_scm_url
@@ -309,6 +311,23 @@ class Project(UnifiedJobTemplate, ProjectOptions):
return True
return False
@property
def notifiers(self):
# Return all notifiers defined on the Project, and on the Organization for each trigger type
# TODO: Currently there is no org fk on project so this will need to be added back once that is
# available after the rbac pr
base_notifiers = NotificationTemplate.objects.filter(active=True)
# error_notifiers = list(base_notifiers.filter(Q(project_notifications_for_errors__in=self) |
# Q(organization_notifications_for_errors__in=self.organization)))
# success_notifiers = list(base_notifiers.filter(Q(project_notifications_for_success__in=self) |
# Q(organization_notifications_for_success__in=self.organization)))
# any_notifiers = list(base_notifiers.filter(Q(project_notifications_for_any__in=self) |
# Q(organization_notifications_for_any__in=self.organization)))
error_notifiers = list(base_notifiers.filter(unifiedjobtemplate_notifications_for_errors=self))
success_notifiers = list(base_notifiers.filter(unifiedjobtemplate_notifications_for_success=self))
any_notifiers = list(base_notifiers.filter(unifiedjobtemplate_notifications_for_any=self))
return dict(error=error_notifiers, success=success_notifiers, any=any_notifiers)
def get_absolute_url(self):
return reverse('api:project_detail', args=(self.pk,))