mirror of
https://github.com/ansible/awx.git
synced 2026-01-16 20:30:46 -03:30
Merge pull request #1834 from wwitzel3/issue-752
add owners summary_field for Credential
This commit is contained in:
commit
c050750489
@ -1627,22 +1627,34 @@ class CredentialSerializer(BaseSerializer):
|
||||
access_list = reverse('api:credential_access_list', args=(obj.pk,)),
|
||||
))
|
||||
|
||||
qs = Organization.objects.filter(admin_role__children=obj.owner_role)
|
||||
if qs.count() > 0:
|
||||
res.update(dict(organization=qs[0].get_absolute_url()))
|
||||
parents = obj.owner_role.parents.exclude(object_id__isnull=True)
|
||||
if parents.count() > 0:
|
||||
res.update({parents[0].content_type.name:parents[0].content_object.get_absolute_url()})
|
||||
elif obj.owner_role.members.count() > 0:
|
||||
user = obj.owner_role.members.first()
|
||||
res.update({'user': reverse('api:user_detail', args=(user.pk,))})
|
||||
|
||||
return res
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -137,8 +137,8 @@ def test_credential_detail(post, get, organization, org_admin):
|
||||
response = get(reverse('api:credential_detail', args=(response.data['id'],)), org_admin)
|
||||
assert response.status_code == 200
|
||||
summary_fields = response.data['summary_fields']
|
||||
assert 'organization' in summary_fields
|
||||
assert summary_fields['organization']['id'] == organization.id
|
||||
assert 'owners' in summary_fields
|
||||
assert summary_fields['owners'][0]['id'] == organization.id
|
||||
related_fields = response.data['related']
|
||||
assert 'organization' in related_fields
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user