mirror of
https://github.com/ansible/awx.git
synced 2026-05-17 14:27:42 -02:30
Notification endpoints and url expositions
Also some changes to the footprint of the notification handler classes
This commit is contained in:
@@ -209,6 +209,11 @@ system_job_urls = patterns('awx.api.views',
|
|||||||
url(r'^(?P<pk>[0-9]+)/cancel/$', 'system_job_cancel'),
|
url(r'^(?P<pk>[0-9]+)/cancel/$', 'system_job_cancel'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
notification_template_urls = patterns('awx.api.views',
|
||||||
|
url(r'^$', 'notification_template_list'),
|
||||||
|
url(r'^(?P<pk>[0-9]+)/$', 'notification_template_detail'),
|
||||||
|
)
|
||||||
|
|
||||||
schedule_urls = patterns('awx.api.views',
|
schedule_urls = patterns('awx.api.views',
|
||||||
url(r'^$', 'schedule_list'),
|
url(r'^$', 'schedule_list'),
|
||||||
url(r'^(?P<pk>[0-9]+)/$', 'schedule_detail'),
|
url(r'^(?P<pk>[0-9]+)/$', 'schedule_detail'),
|
||||||
@@ -257,6 +262,7 @@ v1_urls = patterns('awx.api.views',
|
|||||||
url(r'^ad_hoc_command_events/', include(ad_hoc_command_event_urls)),
|
url(r'^ad_hoc_command_events/', include(ad_hoc_command_event_urls)),
|
||||||
url(r'^system_job_templates/', include(system_job_template_urls)),
|
url(r'^system_job_templates/', include(system_job_template_urls)),
|
||||||
url(r'^system_jobs/', include(system_job_urls)),
|
url(r'^system_jobs/', include(system_job_urls)),
|
||||||
|
url(r'^notification_templates/', include(notification_template_urls)),
|
||||||
url(r'^unified_job_templates/$', 'unified_job_template_list'),
|
url(r'^unified_job_templates/$', 'unified_job_template_list'),
|
||||||
url(r'^unified_jobs/$', 'unified_job_list'),
|
url(r'^unified_jobs/$', 'unified_job_list'),
|
||||||
url(r'^activity_stream/', include(activity_stream_urls)),
|
url(r'^activity_stream/', include(activity_stream_urls)),
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ class ApiV1RootView(APIView):
|
|||||||
data['system_job_templates'] = reverse('api:system_job_template_list')
|
data['system_job_templates'] = reverse('api:system_job_template_list')
|
||||||
data['system_jobs'] = reverse('api:system_job_list')
|
data['system_jobs'] = reverse('api:system_job_list')
|
||||||
data['schedules'] = reverse('api:schedule_list')
|
data['schedules'] = reverse('api:schedule_list')
|
||||||
|
data['notification_templates'] = reverse('api:notification_template_list')
|
||||||
data['unified_job_templates'] = reverse('api:unified_job_template_list')
|
data['unified_job_templates'] = reverse('api:unified_job_template_list')
|
||||||
data['unified_jobs'] = reverse('api:unified_job_list')
|
data['unified_jobs'] = reverse('api:unified_job_list')
|
||||||
data['activity_stream'] = reverse('api:activity_stream_list')
|
data['activity_stream'] = reverse('api:activity_stream_list')
|
||||||
@@ -2919,6 +2920,18 @@ class AdHocCommandStdout(UnifiedJobStdout):
|
|||||||
model = AdHocCommand
|
model = AdHocCommand
|
||||||
new_in_220 = True
|
new_in_220 = True
|
||||||
|
|
||||||
|
class NotificationTemplateList(ListCreateAPIView):
|
||||||
|
|
||||||
|
model = NotificationTemplate
|
||||||
|
serializer_class = NotificationTemplateSerializer
|
||||||
|
new_in_300 = True
|
||||||
|
|
||||||
|
class NotificationTemplateDetail(RetrieveDestroyAPIView):
|
||||||
|
|
||||||
|
model = NotificationTemplate
|
||||||
|
serializer_class = NotificationTemplateSerializer
|
||||||
|
new_in_300 = True
|
||||||
|
|
||||||
class ActivityStreamList(SimpleListAPIView):
|
class ActivityStreamList(SimpleListAPIView):
|
||||||
|
|
||||||
model = ActivityStream
|
model = ActivityStream
|
||||||
|
|||||||
@@ -1484,6 +1484,18 @@ class ScheduleAccess(BaseAccess):
|
|||||||
else:
|
else:
|
||||||
return False
|
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):
|
class ActivityStreamAccess(BaseAccess):
|
||||||
'''
|
'''
|
||||||
I can see activity stream events only when I have permission on all objects included in the event
|
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(ActivityStream, ActivityStreamAccess)
|
||||||
register_access(CustomInventoryScript, CustomInventoryScriptAccess)
|
register_access(CustomInventoryScript, CustomInventoryScriptAccess)
|
||||||
register_access(TowerSettings, TowerSettingsAccess)
|
register_access(TowerSettings, TowerSettingsAccess)
|
||||||
|
register_access(NotificationTemplate, NotificationTemplateAccess)
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.db import models
|
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.models.base import * # noqa
|
||||||
from awx.main.notifications.email_backend import CustomEmailBackend
|
from awx.main.notifications.email_backend import CustomEmailBackend
|
||||||
from awx.main.notifications.slack_backend import SlackBackend
|
from awx.main.notifications.slack_backend import SlackBackend
|
||||||
@@ -14,6 +17,8 @@ from jsonfield import JSONField
|
|||||||
|
|
||||||
logger = logging.getLogger('awx.main.models.notifications')
|
logger = logging.getLogger('awx.main.models.notifications')
|
||||||
|
|
||||||
|
__all__ = ['NotificationTemplate']
|
||||||
|
|
||||||
class NotificationTemplate(CommonModel):
|
class NotificationTemplate(CommonModel):
|
||||||
|
|
||||||
NOTIFICATION_TYPES = [('email', _('Email'), CustomEmailBackend),
|
NOTIFICATION_TYPES = [('email', _('Email'), CustomEmailBackend),
|
||||||
@@ -32,6 +37,9 @@ class NotificationTemplate(CommonModel):
|
|||||||
|
|
||||||
notification_configuration = JSONField(blank=False)
|
notification_configuration = JSONField(blank=False)
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return reverse('api:notification_template_detail', args=(self.pk,))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def notification_class(self):
|
def notification_class(self):
|
||||||
return CLASS_FOR_NOTIFICATION_TYPE[self.notification_type]
|
return CLASS_FOR_NOTIFICATION_TYPE[self.notification_type]
|
||||||
|
|||||||
@@ -7,5 +7,10 @@ from django.core.mail.backends.smtp import EmailBackend
|
|||||||
|
|
||||||
class CustomEmailBackend(EmailBackend):
|
class CustomEmailBackend(EmailBackend):
|
||||||
|
|
||||||
init_parameters = ("host", "port", "username", "password",
|
init_parameters = {"host": {"label": "Host", "type": "string"},
|
||||||
"use_tls", "use_ssl")
|
"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"}}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ logger = logging.getLogger('awx.main.notifications.slack_backend')
|
|||||||
|
|
||||||
class SlackBackend(BaseEmailBackend):
|
class SlackBackend(BaseEmailBackend):
|
||||||
|
|
||||||
init_parameters = ('token',)
|
init_parameters = {"token": {"label": "Token", "type": "password"}}
|
||||||
|
|
||||||
def __init__(self, token, fail_silently=False, **kwargs):
|
def __init__(self, token, fail_silently=False, **kwargs):
|
||||||
super(SlackBackend, self).__init__(fail_silently=fail_silently)
|
super(SlackBackend, self).__init__(fail_silently=fail_silently)
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ logger = logging.getLogger('awx.main.notifications.twilio_backend')
|
|||||||
|
|
||||||
class TwilioBackend(BaseEmailBackend):
|
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):
|
def __init__(self, account_sid, account_token, from_phone, fail_silently=False, **kwargs):
|
||||||
super(TwilioBackend, self).__init__(fail_silently=fail_silently)
|
super(TwilioBackend, self).__init__(fail_silently=fail_silently)
|
||||||
|
|||||||
Reference in New Issue
Block a user