mirror of
https://github.com/ansible/awx.git
synced 2026-01-16 04:10:44 -03:30
adjusting API for new Credential.organization
This commit is contained in:
parent
74b6ea82fb
commit
2c05df064b
@ -1619,7 +1619,7 @@ class CredentialSerializer(BaseSerializer):
|
||||
model = Credential
|
||||
fields = ('*', 'kind', 'cloud', 'host', 'username',
|
||||
'password', 'security_token', 'project', 'domain',
|
||||
'ssh_key_data', 'ssh_key_unlock',
|
||||
'ssh_key_data', 'ssh_key_unlock', 'organization',
|
||||
'become_method', 'become_username', 'become_password',
|
||||
'vault_password', 'subscription', 'tenant', 'secret', 'client',
|
||||
'authorize', 'authorize_password')
|
||||
@ -1634,13 +1634,16 @@ class CredentialSerializer(BaseSerializer):
|
||||
|
||||
def get_related(self, obj):
|
||||
res = super(CredentialSerializer, self).get_related(obj)
|
||||
|
||||
if obj.organization:
|
||||
res['organization'] = reverse('api:organization_detail', args=(obj.organization.pk,))
|
||||
|
||||
res.update(dict(
|
||||
activity_stream = reverse('api:credential_activity_stream_list', args=(obj.pk,)),
|
||||
access_list = reverse('api:credential_access_list', args=(obj.pk,)),
|
||||
object_roles = reverse('api:credential_object_roles_list', args=(obj.pk,)),
|
||||
owner_users = reverse('api:credential_owner_users_list', args=(obj.pk,)),
|
||||
owner_teams = reverse('api:credential_owner_teams_list', args=(obj.pk,)),
|
||||
owner_organizations = reverse('api:credential_owner_organizations_list', args=(obj.pk,)),
|
||||
))
|
||||
|
||||
parents = obj.owner_role.parents.exclude(object_id__isnull=True)
|
||||
|
||||
@ -168,7 +168,7 @@ credential_urls = patterns('awx.api.views',
|
||||
url(r'^(?P<pk>[0-9]+)/object_roles/$', 'credential_object_roles_list'),
|
||||
url(r'^(?P<pk>[0-9]+)/owner/users/$', 'credential_owner_users_list'),
|
||||
url(r'^(?P<pk>[0-9]+)/owner/teams/$', 'credential_owner_teams_list'),
|
||||
url(r'^(?P<pk>[0-9]+)/owner/organizations/$', 'credential_owner_organizations_list'),
|
||||
url(r'^(?P<pk>[0-9]+)/organization/$', 'credential_owner_teams_list'),
|
||||
# See also credentials resources on users/teams.
|
||||
)
|
||||
|
||||
|
||||
@ -1358,7 +1358,8 @@ class CredentialList(ListCreateAPIView):
|
||||
if 'team' in request.data:
|
||||
credential.owner_role.parents.add(team.member_role)
|
||||
if 'organization' in request.data:
|
||||
credential.owner_role.parents.add(organization.admin_role)
|
||||
credential.organization = organization
|
||||
credential.save()
|
||||
|
||||
return ret
|
||||
|
||||
@ -1388,23 +1389,6 @@ class CredentialOwnerTeamsList(SubListAPIView):
|
||||
return self.model.objects.filter(pk__in=teams)
|
||||
|
||||
|
||||
class CredentialOwnerOrganizationsList(SubListAPIView):
|
||||
model = Organization
|
||||
serializer_class = OrganizationSerializer
|
||||
parent_model = Credential
|
||||
new_in_300 = True
|
||||
|
||||
def get_queryset(self):
|
||||
credential = get_object_or_404(self.parent_model, pk=self.kwargs['pk'])
|
||||
if not self.request.user.can_access(Credential, 'read', None):
|
||||
raise PermissionDenied()
|
||||
|
||||
content_type = ContentType.objects.get_for_model(self.model)
|
||||
orgs = [c.content_object.pk for c in credential.owner_role.parents.filter(content_type=content_type)]
|
||||
|
||||
return self.model.objects.filter(pk__in=orgs)
|
||||
|
||||
|
||||
class UserCredentialsList(CredentialList):
|
||||
|
||||
model = Credential
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user