1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 23:51:09 +03:00

Merge pull request #1413 from anoek/credential-api

Added organization to Credential summary and related fields
This commit is contained in:
Akita Noek 2016-04-06 15:11:35 -05:00
commit 38927206c7
2 changed files with 34 additions and 0 deletions

View File

@ -1526,8 +1526,26 @@ class CredentialSerializer(BaseSerializer):
activity_stream = reverse('api:credential_activity_stream_list', args=(obj.pk,)), activity_stream = reverse('api:credential_activity_stream_list', args=(obj.pk,)),
access_list = reverse('api:credential_access_list', args=(obj.pk,)), 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()))
return res return res
def get_summary_fields(self, obj):
summary_dict = super(CredentialSerializer, self).get_summary_fields(obj)
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,
}
return summary_dict
class JobOptionsSerializer(BaseSerializer): class JobOptionsSerializer(BaseSerializer):

View File

@ -123,6 +123,22 @@ def test_create_org_credential_as_admin(post, organization, org_admin):
}, org_admin) }, org_admin)
assert response.status_code == 201 assert response.status_code == 201
@pytest.mark.django_db
def test_credential_detail(post, get, organization, org_admin):
response = post(reverse('api:credential_list'), {
'name': 'Some name',
'username': 'someusername',
'organization': organization.id,
}, org_admin)
assert response.status_code == 201
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
related_fields = response.data['related']
assert 'organization' in related_fields
@pytest.mark.django_db @pytest.mark.django_db
def test_list_created_org_credentials(post, get, organization, org_admin, org_member): def test_list_created_org_credentials(post, get, organization, org_admin, org_member):
response = post(reverse('api:credential_list'), { response = post(reverse('api:credential_list'), {