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:
commit
38927206c7
@ -1526,8 +1526,26 @@ class CredentialSerializer(BaseSerializer):
|
||||
activity_stream = reverse('api:credential_activity_stream_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
|
||||
|
||||
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):
|
||||
|
||||
|
@ -123,6 +123,22 @@ def test_create_org_credential_as_admin(post, organization, org_admin):
|
||||
}, org_admin)
|
||||
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
|
||||
def test_list_created_org_credentials(post, get, organization, org_admin, org_member):
|
||||
response = post(reverse('api:credential_list'), {
|
||||
|
Loading…
Reference in New Issue
Block a user