mirror of
https://github.com/ansible/awx.git
synced 2026-03-20 18:37:39 -02:30
Listing the admins of an organization.
This commit is contained in:
@@ -1,10 +1,7 @@
|
|||||||
# FIXME: do not use ResourceTestCase
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This file demonstrates two different styles of tests (one doctest and one
|
Test code for ansible commander.
|
||||||
unittest). These will both pass when you run "manage.py test".
|
|
||||||
|
|
||||||
Replace these with more appropriate tests for your application.
|
(C) 2013 AnsibleWorks <michael@ansibleworks.com>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@@ -246,9 +243,18 @@ class OrganizationsTest(BaseTest):
|
|||||||
org1_users_url = orgs['results'][1]['related']['users']
|
org1_users_url = orgs['results'][1]['related']['users']
|
||||||
org1_users = self.get(org1_users_url, expect=200, auth=self.get_normal_credentials())
|
org1_users = self.get(org1_users_url, expect=200, auth=self.get_normal_credentials())
|
||||||
self.assertEquals(org1_users['count'], 1)
|
self.assertEquals(org1_users['count'], 1)
|
||||||
|
org1_users = self.get(org1_users_url, expect=200, auth=self.get_super_credentials())
|
||||||
|
self.assertEquals(org1_users['count'], 1)
|
||||||
|
|
||||||
def test_get_item_subobjects_admins(self):
|
def test_get_item_subobjects_admins(self):
|
||||||
pass
|
|
||||||
|
# see if we can list the users added to the organization
|
||||||
|
orgs = self.get(self.collection(), expect=200, auth=self.get_super_credentials())
|
||||||
|
org1_users_url = orgs['results'][1]['related']['admins']
|
||||||
|
org1_users = self.get(org1_users_url, expect=200, auth=self.get_normal_credentials())
|
||||||
|
self.assertEquals(org1_users['count'], 1)
|
||||||
|
org1_users = self.get(org1_users_url, expect=200, auth=self.get_super_credentials())
|
||||||
|
self.assertEquals(org1_users['count'], 1)
|
||||||
|
|
||||||
def test_get_item_subobjects_tags(self):
|
def test_get_item_subobjects_tags(self):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class OrganizationsUsersList(BaseList):
|
|||||||
def _get_queryset(self):
|
def _get_queryset(self):
|
||||||
''' to list users in the organization, I must be a superuser or org admin '''
|
''' to list users in the organization, I must be a superuser or org admin '''
|
||||||
organization = Organization.objects.get(pk=self.kwargs['pk'])
|
organization = Organization.objects.get(pk=self.kwargs['pk'])
|
||||||
if not (self.request.user.is_superuser or self.request.user in organization.admins.all()):
|
if not self.request.user.is_superuser and not self.request.user in organization.admins.all():
|
||||||
raise PermissionDenied()
|
raise PermissionDenied()
|
||||||
return User.objects.filter(organizations__in = [ organization ])
|
return User.objects.filter(organizations__in = [ organization ])
|
||||||
|
|
||||||
@@ -70,9 +70,9 @@ class OrganizationsAdminsList(BaseList):
|
|||||||
def _get_queryset(self):
|
def _get_queryset(self):
|
||||||
''' to list admins in the organization, I must be a superuser or org admin '''
|
''' to list admins in the organization, I must be a superuser or org admin '''
|
||||||
organization = Organization.objects.get(pk=self.kwargs['pk'])
|
organization = Organization.objects.get(pk=self.kwargs['pk'])
|
||||||
if not self.request.user.is_superuser or self.request.user in organizations.admins.all():
|
if not self.request.user.is_superuser and not self.request.user in organization.admins.all():
|
||||||
raise PermissionDenied()
|
raise PermissionDenied()
|
||||||
return User.objects.all(admin_of_organizations__in = [ organization ])
|
return User.objects.filter(admin_of_organizations__in = [ organization ])
|
||||||
|
|
||||||
class OrganizationsProjectsList(BaseSubList):
|
class OrganizationsProjectsList(BaseSubList):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user