From 1c36462b1b930dae632245cdf241c805edae280d Mon Sep 17 00:00:00 2001 From: Aaron Tan Date: Mon, 21 Nov 2016 16:49:24 -0500 Subject: [PATCH] Hook up activity stream with workflow. --- awx/api/serializers.py | 2 ++ awx/api/urls.py | 2 ++ awx/api/views.py | 46 +++++++++++++++++++++++++++++++++---- awx/main/models/__init__.py | 2 ++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index fbf0f84730..e4d77a739d 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -2216,6 +2216,7 @@ class WorkflowJobTemplateSerializer(LabelsListMixin, UnifiedJobTemplateSerialize launch = reverse('api:workflow_job_template_launch', args=(obj.pk,)), workflow_nodes = reverse('api:workflow_job_template_workflow_nodes_list', args=(obj.pk,)), labels = reverse('api:workflow_job_template_label_list', args=(obj.pk,)), + activity_stream = reverse('api:workflow_job_template_activity_stream_list', args=(obj.pk,)), notification_templates_any = reverse('api:workflow_job_template_notification_templates_any_list', args=(obj.pk,)), notification_templates_success = reverse('api:workflow_job_template_notification_templates_success_list', args=(obj.pk,)), notification_templates_error = reverse('api:workflow_job_template_notification_templates_error_list', args=(obj.pk,)), @@ -2248,6 +2249,7 @@ class WorkflowJobSerializer(LabelsListMixin, UnifiedJobSerializer): res['notifications'] = reverse('api:workflow_job_notifications_list', args=(obj.pk,)) res['workflow_nodes'] = reverse('api:workflow_job_workflow_nodes_list', args=(obj.pk,)) res['labels'] = reverse('api:workflow_job_label_list', args=(obj.pk,)) + res['activity_stream'] = reverse('api:workflow_job_activity_stream_list', args=(obj.pk,)) if obj.can_cancel or True: res['cancel'] = reverse('api:workflow_job_cancel', args=(obj.pk,)) return res diff --git a/awx/api/urls.py b/awx/api/urls.py index d62768224b..c4349303b6 100644 --- a/awx/api/urls.py +++ b/awx/api/urls.py @@ -265,6 +265,7 @@ workflow_job_template_urls = patterns('awx.api.views', url(r'^(?P[0-9]+)/schedules/$', 'workflow_job_template_schedules_list'), url(r'^(?P[0-9]+)/survey_spec/$', 'workflow_job_template_survey_spec'), url(r'^(?P[0-9]+)/workflow_nodes/$', 'workflow_job_template_workflow_nodes_list'), + url(r'^(?P[0-9]+)/activity_stream/$', 'workflow_job_template_activity_stream_list'), url(r'^(?P[0-9]+)/notification_templates_any/$', 'workflow_job_template_notification_templates_any_list'), url(r'^(?P[0-9]+)/notification_templates_error/$', 'workflow_job_template_notification_templates_error_list'), url(r'^(?P[0-9]+)/notification_templates_success/$', 'workflow_job_template_notification_templates_success_list'), @@ -280,6 +281,7 @@ workflow_job_urls = patterns('awx.api.views', url(r'^(?P[0-9]+)/labels/$', 'workflow_job_label_list'), url(r'^(?P[0-9]+)/cancel/$', 'workflow_job_cancel'), url(r'^(?P[0-9]+)/notifications/$', 'workflow_job_notifications_list'), + url(r'^(?P[0-9]+)/activity_stream/$', 'workflow_job_activity_stream_list'), ) diff --git a/awx/api/views.py b/awx/api/views.py index b22be1771d..60fddf4bb7 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -3026,6 +3026,32 @@ class WorkflowJobTemplateNotificationTemplatesSuccessList(SubListCreateAttachDet new_in_310 = True +class WorkflowJobTemplateAccessList(ResourceAccessList): + + model = User # needs to be User for AccessLists's + resource_model = WorkflowJobTemplate + new_in_310 = True + + +class WorkflowJobTemplateActivityStreamList(SubListAPIView): + + model = ActivityStream + serializer_class = ActivityStreamSerializer + parent_model = WorkflowJobTemplate + relationship = 'activitystream_set' + new_in_310 = True + + def get(self, request, *args, **kwargs): + # Sanity check: Does this license allow activity streams? + # If not, forbid this request. + if not feature_enabled('activity_streams'): + raise LicenseForbids(_('Your license does not allow use of ' + 'the activity stream.')) + + # Okay, let it through. + return super(WorkflowJobTemplateActivityStreamList, self).get(request, *args, **kwargs) + + # TODO: class WorkflowJobList(ListCreateAPIView): @@ -3080,11 +3106,23 @@ class WorkflowJobNotificationsList(SubListAPIView): new_in_310 = True -class WorkflowJobTemplateAccessList(ResourceAccessList): +class WorkflowJobActivityStreamList(SubListAPIView): - model = User # needs to be User for AccessLists's - resource_model = WorkflowJobTemplate - new_in_310 = True + model = ActivityStream + serializer_class = ActivityStreamSerializer + parent_model = WorkflowJob + relationship = 'activitystream_set' + new_in_310 = True + + def get(self, request, *args, **kwargs): + # Sanity check: Does this license allow activity streams? + # If not, forbid this request. + if not feature_enabled('activity_streams'): + raise LicenseForbids(_('Your license does not allow use of ' + 'the activity stream.')) + + # Okay, let it through. + return super(WorkflowJobActivityStreamList, self).get(request, *args, **kwargs) class SystemJobTemplateList(ListAPIView): diff --git a/awx/main/models/__init__.py b/awx/main/models/__init__.py index 321c340a92..10413cc15a 100644 --- a/awx/main/models/__init__.py +++ b/awx/main/models/__init__.py @@ -115,3 +115,5 @@ activity_stream_registrar.connect(NotificationTemplate) activity_stream_registrar.connect(Notification) activity_stream_registrar.connect(Label) activity_stream_registrar.connect(User) +activity_stream_registrar.connect(WorkflowJobTemplate) +activity_stream_registrar.connect(WorkflowJob)