mirror of
https://github.com/ansible/awx.git
synced 2026-03-24 20:35:02 -02:30
add owners summary_field for Credential
This commit is contained in:
@@ -1634,15 +1634,23 @@ class CredentialSerializer(BaseSerializer):
|
|||||||
|
|
||||||
def get_summary_fields(self, obj):
|
def get_summary_fields(self, obj):
|
||||||
summary_dict = super(CredentialSerializer, self).get_summary_fields(obj)
|
summary_dict = super(CredentialSerializer, self).get_summary_fields(obj)
|
||||||
|
summary_dict['owners'] = []
|
||||||
|
|
||||||
qs = Organization.objects.filter(admin_role__children=obj.owner_role)
|
for user in obj.owner_role.members.all():
|
||||||
if qs.count() > 0:
|
summary_dict['owners'].append({
|
||||||
org = qs[0]
|
'id': user.pk,
|
||||||
summary_dict['organization'] = {
|
'name': user.username,
|
||||||
'id': org.id,
|
'description': ' '.join([user.first_name, user.last_name]),
|
||||||
'name': org.name,
|
'url': reverse('api:user_detail', args=(user.pk,)),
|
||||||
'description': org.description,
|
})
|
||||||
}
|
|
||||||
|
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
|
return summary_dict
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user