mirror of
https://github.com/ansible/awx.git
synced 2026-02-28 08:18:43 -03:30
Merge pull request #4108 from AlanCoding/wfjt_ssf
Add WFJT survey and recent_jobs
This commit is contained in:
@@ -1867,7 +1867,28 @@ class JobOptionsSerializer(LabelsListMixin, BaseSerializer):
|
|||||||
return super(JobOptionsSerializer, self).validate(attrs)
|
return super(JobOptionsSerializer, self).validate(attrs)
|
||||||
|
|
||||||
|
|
||||||
class JobTemplateSerializer(UnifiedJobTemplateSerializer, JobOptionsSerializer):
|
class JobTemplateMixin(object):
|
||||||
|
'''
|
||||||
|
Provide recent jobs and survey details in summary_fields
|
||||||
|
'''
|
||||||
|
|
||||||
|
def _recent_jobs(self, obj):
|
||||||
|
if hasattr(obj, 'workflow_jobs'):
|
||||||
|
job_mgr = obj.workflow_jobs
|
||||||
|
else:
|
||||||
|
job_mgr = obj.jobs
|
||||||
|
return [{'id': x.id, 'status': x.status, 'finished': x.finished}
|
||||||
|
for x in job_mgr.all().order_by('-created')[:10]]
|
||||||
|
|
||||||
|
def get_summary_fields(self, obj):
|
||||||
|
d = super(JobTemplateMixin, self).get_summary_fields(obj)
|
||||||
|
if obj.survey_spec is not None and ('name' in obj.survey_spec and 'description' in obj.survey_spec):
|
||||||
|
d['survey'] = dict(title=obj.survey_spec['name'], description=obj.survey_spec['description'])
|
||||||
|
d['recent_jobs'] = self._recent_jobs(obj)
|
||||||
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
class JobTemplateSerializer(JobTemplateMixin, UnifiedJobTemplateSerializer, JobOptionsSerializer):
|
||||||
show_capabilities = ['start', 'schedule', 'copy', 'edit', 'delete']
|
show_capabilities = ['start', 'schedule', 'copy', 'edit', 'delete']
|
||||||
|
|
||||||
status = serializers.ChoiceField(choices=JobTemplate.JOB_TEMPLATE_STATUS_CHOICES, read_only=True, required=False)
|
status = serializers.ChoiceField(choices=JobTemplate.JOB_TEMPLATE_STATUS_CHOICES, read_only=True, required=False)
|
||||||
@@ -1897,16 +1918,6 @@ class JobTemplateSerializer(UnifiedJobTemplateSerializer, JobOptionsSerializer):
|
|||||||
res['callback'] = reverse('api:job_template_callback', args=(obj.pk,))
|
res['callback'] = reverse('api:job_template_callback', args=(obj.pk,))
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _recent_jobs(self, obj):
|
|
||||||
return [{'id': x.id, 'status': x.status, 'finished': x.finished} for x in obj.jobs.all().order_by('-created')[:10]]
|
|
||||||
|
|
||||||
def get_summary_fields(self, obj):
|
|
||||||
d = super(JobTemplateSerializer, self).get_summary_fields(obj)
|
|
||||||
if obj.survey_spec is not None and ('name' in obj.survey_spec and 'description' in obj.survey_spec):
|
|
||||||
d['survey'] = dict(title=obj.survey_spec['name'], description=obj.survey_spec['description'])
|
|
||||||
d['recent_jobs'] = self._recent_jobs(obj)
|
|
||||||
return d
|
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
survey_enabled = attrs.get('survey_enabled', self.instance and self.instance.survey_enabled or False)
|
survey_enabled = attrs.get('survey_enabled', self.instance and self.instance.survey_enabled or False)
|
||||||
job_type = attrs.get('job_type', self.instance and self.instance.job_type or None)
|
job_type = attrs.get('job_type', self.instance and self.instance.job_type or None)
|
||||||
@@ -2202,7 +2213,7 @@ class SystemJobCancelSerializer(SystemJobSerializer):
|
|||||||
fields = ('can_cancel',)
|
fields = ('can_cancel',)
|
||||||
|
|
||||||
|
|
||||||
class WorkflowJobTemplateSerializer(LabelsListMixin, UnifiedJobTemplateSerializer):
|
class WorkflowJobTemplateSerializer(JobTemplateMixin, LabelsListMixin, UnifiedJobTemplateSerializer):
|
||||||
show_capabilities = ['start', 'edit', 'copy', 'delete']
|
show_capabilities = ['start', 'edit', 'copy', 'delete']
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ from awx.main.models import (
|
|||||||
Role,
|
Role,
|
||||||
User,
|
User,
|
||||||
Job,
|
Job,
|
||||||
|
JobTemplate,
|
||||||
)
|
)
|
||||||
from rest_framework.test import APIRequestFactory
|
from rest_framework.test import APIRequestFactory
|
||||||
|
|
||||||
@@ -24,7 +25,9 @@ def mock_JT_resource_data():
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def job_template(mocker):
|
def job_template(mocker):
|
||||||
mock_jt = mocker.MagicMock(pk=5)
|
mock_jt = mocker.MagicMock(spec=JobTemplate)
|
||||||
|
mock_jt.pk = 5
|
||||||
|
mock_jt.host_config_key = '9283920492'
|
||||||
mock_jt.resource_validation_data = mock_JT_resource_data
|
mock_jt.resource_validation_data = mock_JT_resource_data
|
||||||
return mock_jt
|
return mock_jt
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user