mirror of
https://github.com/ansible/awx.git
synced 2026-05-20 15:27:47 -02:30
Fix UJT-related error, add notification placeholders
This commit is contained in:
@@ -3446,7 +3446,7 @@ class WorkflowApprovalTemplateSerializer(UnifiedJobTemplateSerializer):
|
|||||||
|
|
||||||
res.update(dict(
|
res.update(dict(
|
||||||
jobs = self.reverse('api:workflow_approval_template_jobs_list', kwargs={'pk': obj.pk}),
|
jobs = self.reverse('api:workflow_approval_template_jobs_list', kwargs={'pk': obj.pk}),
|
||||||
notification_templates_started = self.reverse('api:workflow_approval_template_notification_templates_started_list', kwargs={'pk': obj.pk}),
|
notification_templates_needs_approval = self.reverse('api:workflow_approval_template_notification_templates_needs_approval', kwargs={'pk': obj.pk}),
|
||||||
notification_templates_success = self.reverse('api:workflow_approval_template_notification_templates_success_list', kwargs={'pk': obj.pk}),
|
notification_templates_success = self.reverse('api:workflow_approval_template_notification_templates_success_list', kwargs={'pk': obj.pk}),
|
||||||
notification_templates_error = self.reverse('api:workflow_approval_template_notification_templates_error_list', kwargs={'pk': obj.pk}),
|
notification_templates_error = self.reverse('api:workflow_approval_template_notification_templates_error_list', kwargs={'pk': obj.pk}),
|
||||||
))
|
))
|
||||||
@@ -3520,6 +3520,8 @@ class LaunchConfigurationBaseSerializer(BaseSerializer):
|
|||||||
ujt = attrs['unified_job_template']
|
ujt = attrs['unified_job_template']
|
||||||
elif self.instance:
|
elif self.instance:
|
||||||
ujt = self.instance.unified_job_template
|
ujt = self.instance.unified_job_template
|
||||||
|
if ujt is None:
|
||||||
|
return {'workflow_job_template': attrs['workflow_job_template']}
|
||||||
|
|
||||||
# build additional field survey_passwords to track redacted variables
|
# build additional field survey_passwords to track redacted variables
|
||||||
password_dict = {}
|
password_dict = {}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from awx.api.views import (
|
|||||||
WorkflowApprovalTemplateDetail,
|
WorkflowApprovalTemplateDetail,
|
||||||
WorkflowApprovalTemplateJobsList,
|
WorkflowApprovalTemplateJobsList,
|
||||||
WorkflowApprovalTemplateNotificationTemplatesErrorList,
|
WorkflowApprovalTemplateNotificationTemplatesErrorList,
|
||||||
WorkflowApprovalTemplateNotificationTemplatesStartedList,
|
WorkflowApprovalTemplateNotificationTemplatesNeedsApprovalList,
|
||||||
WorkflowApprovalTemplateNotificationTemplatesSuccessList,
|
WorkflowApprovalTemplateNotificationTemplatesSuccessList,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,8 +15,8 @@ from awx.api.views import (
|
|||||||
urls = [
|
urls = [
|
||||||
url(r'^(?P<pk>[0-9]+)/$', WorkflowApprovalTemplateDetail.as_view(), name='workflow_approval_template_detail'),
|
url(r'^(?P<pk>[0-9]+)/$', WorkflowApprovalTemplateDetail.as_view(), name='workflow_approval_template_detail'),
|
||||||
url(r'^(?P<pk>[0-9]+)/approvals/$', WorkflowApprovalTemplateJobsList.as_view(), name='workflow_approval_template_jobs_list'),
|
url(r'^(?P<pk>[0-9]+)/approvals/$', WorkflowApprovalTemplateJobsList.as_view(), name='workflow_approval_template_jobs_list'),
|
||||||
url(r'^(?P<pk>[0-9]+)/notification_templates_started/$', WorkflowApprovalTemplateNotificationTemplatesStartedList.as_view(),
|
url(r'^(?P<pk>[0-9]+)/notification_templates_needs_approval/$', WorkflowApprovalTemplateNotificationTemplatesNeedsApprovalList.as_view(),
|
||||||
name='workflow_approval_template_notification_templates_started_list'),
|
name='workflow_approval_template_notification_templates_needs_approval'),
|
||||||
url(r'^(?P<pk>[0-9]+)/notification_templates_error/$', WorkflowApprovalTemplateNotificationTemplatesErrorList.as_view(),
|
url(r'^(?P<pk>[0-9]+)/notification_templates_error/$', WorkflowApprovalTemplateNotificationTemplatesErrorList.as_view(),
|
||||||
name='workflow_approval_template_notification_templates_error_list'),
|
name='workflow_approval_template_notification_templates_error_list'),
|
||||||
url(r'^(?P<pk>[0-9]+)/notification_templates_success/$', WorkflowApprovalTemplateNotificationTemplatesSuccessList.as_view(),
|
url(r'^(?P<pk>[0-9]+)/notification_templates_success/$', WorkflowApprovalTemplateNotificationTemplatesSuccessList.as_view(),
|
||||||
|
|||||||
@@ -4434,9 +4434,9 @@ class WorkflowApprovalTemplateNotificationTemplatesAnyList(SubListCreateAttachDe
|
|||||||
parent_model = models.WorkflowApprovalTemplate
|
parent_model = models.WorkflowApprovalTemplate
|
||||||
|
|
||||||
|
|
||||||
class WorkflowApprovalTemplateNotificationTemplatesStartedList(WorkflowApprovalTemplateNotificationTemplatesAnyList):
|
class WorkflowApprovalTemplateNotificationTemplatesNeedsApprovalList(WorkflowApprovalTemplateNotificationTemplatesAnyList):
|
||||||
|
|
||||||
relationship = 'notification_templates_started'
|
relationship = 'notification_templates_needs_approval'
|
||||||
|
|
||||||
|
|
||||||
class WorkflowApprovalTemplateNotificationTemplatesErrorList(WorkflowApprovalTemplateNotificationTemplatesAnyList):
|
class WorkflowApprovalTemplateNotificationTemplatesErrorList(WorkflowApprovalTemplateNotificationTemplatesAnyList):
|
||||||
|
|||||||
@@ -392,6 +392,13 @@ class NotificationFieldsModel(BaseModel):
|
|||||||
related_name='%(class)s_notification_templates_for_started'
|
related_name='%(class)s_notification_templates_for_started'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# &&&&&& Placeholder for workflow pause/approve notifications
|
||||||
|
# notification_templates_needs_approval = models.ManyToManyField(
|
||||||
|
# "NotificationTemplate",
|
||||||
|
# blank=True,
|
||||||
|
# related_name='%(class)s_notification_templates_for_needs_approval'
|
||||||
|
# )
|
||||||
|
|
||||||
|
|
||||||
def prevent_search(relation):
|
def prevent_search(relation):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -486,6 +486,5 @@ class JobNotificationMixin(object):
|
|||||||
def send_it(local_nt=nt, local_subject=notification_subject, local_body=notification_body):
|
def send_it(local_nt=nt, local_subject=notification_subject, local_body=notification_body):
|
||||||
def _func():
|
def _func():
|
||||||
send_notifications.delay([local_nt.generate_notification(local_subject, local_body).id],
|
send_notifications.delay([local_nt.generate_notification(local_subject, local_body).id],
|
||||||
job_id=self.id)
|
|
||||||
return _func
|
return _func
|
||||||
connection.on_commit(send_it())
|
connection.on_commit(send_it())
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ class WorkflowNodeBase(CreatedModifiedModel, LaunchTimeConfig):
|
|||||||
unified_job_template = models.ForeignKey(
|
unified_job_template = models.ForeignKey(
|
||||||
'UnifiedJobTemplate',
|
'UnifiedJobTemplate',
|
||||||
related_name='%(class)ss',
|
related_name='%(class)ss',
|
||||||
blank=False,
|
blank=True,
|
||||||
null=True,
|
null=True,
|
||||||
default=None,
|
default=None,
|
||||||
on_delete=models.SET_NULL,
|
on_delete=models.SET_NULL,
|
||||||
@@ -636,6 +636,31 @@ class WorkflowApprovalTemplate(UnifiedJobTemplate):
|
|||||||
def get_absolute_url(self, request=None):
|
def get_absolute_url(self, request=None):
|
||||||
return reverse('api:workflow_approval_template_detail', kwargs={'pk': self.pk}, request=request)
|
return reverse('api:workflow_approval_template_detail', kwargs={'pk': self.pk}, request=request)
|
||||||
|
|
||||||
|
# @property
|
||||||
|
# def notification_templates(self):
|
||||||
|
# # Return all notification_templates defined on the Job Template, on the Project, and on the Organization for each trigger type
|
||||||
|
# base_notification_templates = NotificationTemplate.objects.all()
|
||||||
|
# error_notification_templates = list(base_notification_templates.filter(
|
||||||
|
# unifiedjobtemplate_notification_templates_for_errors__in=[self]))
|
||||||
|
# needs_approval_notification_templates = list(base_notification_templates.filter(
|
||||||
|
# notification_templates_needs_approval__in=[self]))
|
||||||
|
# success_notification_templates = list(base_notification_templates.filter(
|
||||||
|
# unifiedjobtemplate_notification_templates_for_success__in=[self]))
|
||||||
|
# return dict(error=list(error_notification_templates),
|
||||||
|
# needs_approval=list(needs_approval_notification_templates),
|
||||||
|
# success=list(success_notification_templates))
|
||||||
|
# &&&&&& Approval nodes don't have orgs!
|
||||||
|
# if self.project is not None and self.project.organization is not None:
|
||||||
|
# error_notification_templates = set(error_notification_templates + list(base_notification_templates.filter(
|
||||||
|
# organization_notification_templates_for_errors=self.project.organization)))
|
||||||
|
# started_notification_templates = set(started_notification_templates + list(base_notification_templates.filter(
|
||||||
|
# organization_notification_templates_for_started=self.project.organization)))
|
||||||
|
# success_notification_templates = set(success_notification_templates + list(base_notification_templates.filter(
|
||||||
|
# organization_notification_templates_for_success=self.project.organization)))
|
||||||
|
# return dict(error=list(error_notification_templates),
|
||||||
|
# needs_approval=list(needs_approval_notification_templates),
|
||||||
|
# success=list(success_notification_templates))
|
||||||
|
|
||||||
|
|
||||||
class WorkflowApproval(UnifiedJob):
|
class WorkflowApproval(UnifiedJob):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ from awx.main.models import (
|
|||||||
Project,
|
Project,
|
||||||
ProjectUpdate,
|
ProjectUpdate,
|
||||||
SystemJob,
|
SystemJob,
|
||||||
|
# &&&&&& WorkflowApproval,
|
||||||
WorkflowJob,
|
WorkflowJob,
|
||||||
WorkflowJobTemplate
|
WorkflowJobTemplate
|
||||||
)
|
)
|
||||||
@@ -238,6 +239,11 @@ class TaskManager():
|
|||||||
task.send_notification_templates('running')
|
task.send_notification_templates('running')
|
||||||
logger.debug('Transitioning %s to running status.', task.log_format)
|
logger.debug('Transitioning %s to running status.', task.log_format)
|
||||||
schedule_task_manager()
|
schedule_task_manager()
|
||||||
|
# elif type(task) is WorkflowApproval: (&&&&&& placeholder for notification work)
|
||||||
|
# task.status = 'pending'
|
||||||
|
# task.send_notification_templates('pending')
|
||||||
|
# logger.debug('Transitioning %s to pending status.', task.log_format)
|
||||||
|
# schedule_task_manager()
|
||||||
elif not task.supports_isolation() and rampart_group.controller_id:
|
elif not task.supports_isolation() and rampart_group.controller_id:
|
||||||
# non-Ansible jobs on isolated instances run on controller
|
# non-Ansible jobs on isolated instances run on controller
|
||||||
task.instance_group = rampart_group.controller
|
task.instance_group = rampart_group.controller
|
||||||
|
|||||||
@@ -638,6 +638,25 @@ def delete_inventory_for_org(sender, instance, **kwargs):
|
|||||||
logger.debug(e)
|
logger.debug(e)
|
||||||
|
|
||||||
|
|
||||||
|
# &&&&&& Placeholder code below for approval node deletion.
|
||||||
|
# @receiver(pre_delete, sender=Job)
|
||||||
|
# def delete_detached_approval_nodes(sender, instance, **kwargs):
|
||||||
|
# for l in instance.labels.all():
|
||||||
|
# if l.is_candidate_for_detach():
|
||||||
|
# l.delete()
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# @receiver(pre_delete, sender=Organization)
|
||||||
|
# def delete_detached_approval_nodes(sender, instance, **kwargs):
|
||||||
|
# approval_node = ???
|
||||||
|
# user = get_current_user_or_none()
|
||||||
|
# for node in approval_node:
|
||||||
|
# try:
|
||||||
|
# node.schedule_deletion(user_id=getattr(user, 'id', None))
|
||||||
|
# except RuntimeError as e:
|
||||||
|
# logger.debug(e)
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=Session)
|
@receiver(post_save, sender=Session)
|
||||||
def save_user_session_membership(sender, **kwargs):
|
def save_user_session_membership(sender, **kwargs):
|
||||||
session = kwargs.get('instance', None)
|
session = kwargs.get('instance', None)
|
||||||
|
|||||||
@@ -26,26 +26,6 @@ def node(workflow_job_template, post, admin_user, job_template):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_blank_UJT_unallowed(workflow_job_template, post, admin_user):
|
|
||||||
url = reverse('api:workflow_job_template_workflow_nodes_list',
|
|
||||||
kwargs={'pk': workflow_job_template.pk})
|
|
||||||
r = post(url, {}, user=admin_user, expect=400)
|
|
||||||
assert 'unified_job_template' in r.data
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_cannot_remove_UJT(node, patch, admin_user):
|
|
||||||
r = patch(
|
|
||||||
node.get_absolute_url(),
|
|
||||||
data={'unified_job_template': None},
|
|
||||||
user=admin_user,
|
|
||||||
expect=400
|
|
||||||
)
|
|
||||||
assert 'unified_job_template' in r.data
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_node_rejects_unprompted_fields(inventory, project, workflow_job_template, post, admin_user):
|
def test_node_rejects_unprompted_fields(inventory, project, workflow_job_template, post, admin_user):
|
||||||
job_template = JobTemplate.objects.create(
|
job_template = JobTemplate.objects.create(
|
||||||
|
|||||||
Reference in New Issue
Block a user