From dc9b6096556bdf9a9a4cebf51905ddd9a5a0455a Mon Sep 17 00:00:00 2001 From: Wayne Witzel III Date: Fri, 6 May 2016 11:49:24 -0400 Subject: [PATCH] add owners summary_field for Credential --- awx/api/serializers.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index badfb619ae..c089de70fe 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1634,15 +1634,23 @@ class CredentialSerializer(BaseSerializer): def get_summary_fields(self, obj): summary_dict = super(CredentialSerializer, self).get_summary_fields(obj) + summary_dict['owners'] = [] - qs = Organization.objects.filter(admin_role__children=obj.owner_role) - if qs.count() > 0: - org = qs[0] - summary_dict['organization'] = { - 'id': org.id, - 'name': org.name, - 'description': org.description, - } + for user in obj.owner_role.members.all(): + summary_dict['owners'].append({ + 'id': user.pk, + 'name': user.username, + 'description': ' '.join([user.first_name, user.last_name]), + 'url': reverse('api:user_detail', args=(user.pk,)), + }) + + for parent in obj.owner_role.parents.exclude(object_id__isnull=True).all(): + summary_dict['owners'].append({ + 'id': parent.content_object.pk, + 'name': parent.content_object.name, + 'description': parent.content_object.description, + 'url': parent.content_object.get_absolute_url(), + }) return summary_dict