mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 09:57:35 -02:30
adjusting API for new Credential.organization
This commit is contained in:
@@ -1619,7 +1619,7 @@ class CredentialSerializer(BaseSerializer):
|
|||||||
model = Credential
|
model = Credential
|
||||||
fields = ('*', 'kind', 'cloud', 'host', 'username',
|
fields = ('*', 'kind', 'cloud', 'host', 'username',
|
||||||
'password', 'security_token', 'project', 'domain',
|
'password', 'security_token', 'project', 'domain',
|
||||||
'ssh_key_data', 'ssh_key_unlock',
|
'ssh_key_data', 'ssh_key_unlock', 'organization',
|
||||||
'become_method', 'become_username', 'become_password',
|
'become_method', 'become_username', 'become_password',
|
||||||
'vault_password', 'subscription', 'tenant', 'secret', 'client',
|
'vault_password', 'subscription', 'tenant', 'secret', 'client',
|
||||||
'authorize', 'authorize_password')
|
'authorize', 'authorize_password')
|
||||||
@@ -1634,13 +1634,16 @@ class CredentialSerializer(BaseSerializer):
|
|||||||
|
|
||||||
def get_related(self, obj):
|
def get_related(self, obj):
|
||||||
res = super(CredentialSerializer, self).get_related(obj)
|
res = super(CredentialSerializer, self).get_related(obj)
|
||||||
|
|
||||||
|
if obj.organization:
|
||||||
|
res['organization'] = reverse('api:organization_detail', args=(obj.organization.pk,))
|
||||||
|
|
||||||
res.update(dict(
|
res.update(dict(
|
||||||
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,)),
|
||||||
object_roles = reverse('api:credential_object_roles_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_users = reverse('api:credential_owner_users_list', args=(obj.pk,)),
|
||||||
owner_teams = reverse('api:credential_owner_teams_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)
|
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]+)/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/users/$', 'credential_owner_users_list'),
|
||||||
url(r'^(?P<pk>[0-9]+)/owner/teams/$', 'credential_owner_teams_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.
|
# See also credentials resources on users/teams.
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1358,7 +1358,8 @@ class CredentialList(ListCreateAPIView):
|
|||||||
if 'team' in request.data:
|
if 'team' in request.data:
|
||||||
credential.owner_role.parents.add(team.member_role)
|
credential.owner_role.parents.add(team.member_role)
|
||||||
if 'organization' in request.data:
|
if 'organization' in request.data:
|
||||||
credential.owner_role.parents.add(organization.admin_role)
|
credential.organization = organization
|
||||||
|
credential.save()
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@@ -1388,23 +1389,6 @@ class CredentialOwnerTeamsList(SubListAPIView):
|
|||||||
return self.model.objects.filter(pk__in=teams)
|
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):
|
class UserCredentialsList(CredentialList):
|
||||||
|
|
||||||
model = Credential
|
model = Credential
|
||||||
|
|||||||
Reference in New Issue
Block a user