1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 15:21:13 +03:00

Merge pull request #365 from ryanpetrello/fix-7521

include extra_credentials data in summary fields for JT/Job detail view
This commit is contained in:
Ryan Petrello 2017-08-31 09:53:21 -04:00 committed by GitHub
commit 5f416cce74
4 changed files with 37 additions and 3 deletions

View File

@ -89,8 +89,8 @@ SUMMARIZABLE_FK_FIELDS = {
'project': DEFAULT_SUMMARY_FIELDS + ('status', 'scm_type'),
'source_project': DEFAULT_SUMMARY_FIELDS + ('status', 'scm_type'),
'project_update': DEFAULT_SUMMARY_FIELDS + ('status', 'failed',),
'credential': DEFAULT_SUMMARY_FIELDS + ('kind', 'cloud'),
'vault_credential': DEFAULT_SUMMARY_FIELDS + ('kind', 'cloud'),
'credential': DEFAULT_SUMMARY_FIELDS + ('kind', 'cloud', 'credential_type_id'),
'vault_credential': DEFAULT_SUMMARY_FIELDS + ('kind', 'cloud', 'credential_type_id'),
'job': DEFAULT_SUMMARY_FIELDS + ('status', 'failed', 'elapsed'),
'job_template': DEFAULT_SUMMARY_FIELDS,
'workflow_job_template': DEFAULT_SUMMARY_FIELDS,
@ -2490,6 +2490,22 @@ class JobTemplateSerializer(JobTemplateMixin, UnifiedJobTemplateSerializer, JobO
def validate_extra_vars(self, value):
return vars_validate_or_raise(value)
def get_summary_fields(self, obj):
summary_fields = super(JobTemplateSerializer, self).get_summary_fields(obj)
if 'pk' in self.context['view'].kwargs and self.version > 1: # TODO: remove version check in 3.3
extra_creds = []
for cred in obj.extra_credentials.all():
extra_creds.append({
'id': cred.pk,
'name': cred.name,
'description': cred.description,
'kind': cred.kind,
'credential_type_id': cred.credential_type_id
})
summary_fields['extra_credentials'] = extra_creds
return summary_fields
class JobSerializer(UnifiedJobSerializer, JobOptionsSerializer):
@ -2577,6 +2593,21 @@ class JobSerializer(UnifiedJobSerializer, JobOptionsSerializer):
ret['extra_vars'] = obj.display_extra_vars()
return ret
def get_summary_fields(self, obj):
summary_fields = super(JobSerializer, self).get_summary_fields(obj)
if 'pk' in self.context['view'].kwargs and self.version > 1: # TODO: remove version check in 3.3
extra_creds = []
for cred in obj.extra_credentials.all():
extra_creds.append({
'id': cred.pk,
'name': cred.name,
'description': cred.description,
'kind': cred.kind,
'credential_type_id': cred.credential_type_id
})
summary_fields['extra_credentials'] = extra_creds
return summary_fields
class JobCancelSerializer(JobSerializer):

View File

@ -73,6 +73,7 @@ class TestJobTemplateCopyEdit:
fake_view = FakeView()
fake_view.request = request
fake_view.kwargs = {'pk': '42'}
context = {}
context['view'] = fake_view
context['request'] = request

View File

@ -1,4 +1,4 @@
import mock
import pytest
@ -39,6 +39,7 @@ def get_summary_fields_assert():
def get_summary_fields_mock_and_run():
def fn(serializer_class, model_obj):
serializer = serializer_class()
serializer.context['view'] = mock.Mock(kwargs={})
return serializer.get_summary_fields(model_obj)
return fn

View File

@ -108,6 +108,7 @@ class TestJobTemplateSerializerGetSummaryFields():
request.user = user
view = JobTemplateDetail()
view.request = request
view.kwargs = {}
serializer.context['view'] = view
with mocker.patch("awx.api.serializers.role_summary_fields_generator", return_value='Can eat pie'):