Notification endpoints and url expositions

Also some changes to the footprint of the notification handler classes
This commit is contained in:
Matthew Jones
2016-02-04 11:30:40 -05:00
parent 96b0fb168f
commit 172207cd4b
7 changed files with 51 additions and 4 deletions

View File

@@ -1484,6 +1484,18 @@ class ScheduleAccess(BaseAccess):
else:
return False
class NotificationTemplateAccess(BaseAccess):
'''
I can see/use a notification template if I have permission to
'''
model = NotificationTemplate
def get_queryset(self):
qs = self.model.objects.filter(active=True).distinct()
if self.user.is_superuser:
return qs
return qs
class ActivityStreamAccess(BaseAccess):
'''
I can see activity stream events only when I have permission on all objects included in the event
@@ -1683,3 +1695,4 @@ register_access(UnifiedJob, UnifiedJobAccess)
register_access(ActivityStream, ActivityStreamAccess)
register_access(CustomInventoryScript, CustomInventoryScriptAccess)
register_access(TowerSettings, TowerSettingsAccess)
register_access(NotificationTemplate, NotificationTemplateAccess)

View File

@@ -4,6 +4,9 @@
import logging
from django.db import models
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from awx.main.models.base import * # noqa
from awx.main.notifications.email_backend import CustomEmailBackend
from awx.main.notifications.slack_backend import SlackBackend
@@ -14,6 +17,8 @@ from jsonfield import JSONField
logger = logging.getLogger('awx.main.models.notifications')
__all__ = ['NotificationTemplate']
class NotificationTemplate(CommonModel):
NOTIFICATION_TYPES = [('email', _('Email'), CustomEmailBackend),
@@ -32,6 +37,9 @@ class NotificationTemplate(CommonModel):
notification_configuration = JSONField(blank=False)
def get_absolute_url(self):
return reverse('api:notification_template_detail', args=(self.pk,))
@property
def notification_class(self):
return CLASS_FOR_NOTIFICATION_TYPE[self.notification_type]

View File

@@ -7,5 +7,10 @@ from django.core.mail.backends.smtp import EmailBackend
class CustomEmailBackend(EmailBackend):
init_parameters = ("host", "port", "username", "password",
"use_tls", "use_ssl")
init_parameters = {"host": {"label": "Host", "type": "string"},
"port": {"label": "Port", "type": "int"},
"username": {"label": "Username", "type": "string"},
"password": {"label": "Password", "type": "password"},
"use_tls": {"label": "Use TLS", "type": "bool"},
"use_ssl": {"label": "Use SSL", "type": "bool"}}

View File

@@ -10,7 +10,7 @@ logger = logging.getLogger('awx.main.notifications.slack_backend')
class SlackBackend(BaseEmailBackend):
init_parameters = ('token',)
init_parameters = {"token": {"label": "Token", "type": "password"}}
def __init__(self, token, fail_silently=False, **kwargs):
super(SlackBackend, self).__init__(fail_silently=fail_silently)

View File

@@ -11,7 +11,9 @@ logger = logging.getLogger('awx.main.notifications.twilio_backend')
class TwilioBackend(BaseEmailBackend):
init_parameters = ('account_sid', 'account_token', 'from_phone',)
init_parameters = {"account_sid": {"label": "Account SID", "type": "string"},
"account_token": {"label": "Account Token", "type": "password"},
"from_phone": {"label": "Source Phone Number", "type": "string"}}
def __init__(self, account_sid, account_token, from_phone, fail_silently=False, **kwargs):
super(TwilioBackend, self).__init__(fail_silently=fail_silently)