Listing the admins of an organization.

This commit is contained in:
Michael DeHaan 2013-03-23 15:43:59 -04:00
parent 6a45aa2823
commit 2484f7eb4a
2 changed files with 15 additions and 9 deletions

View File

@ -1,10 +1,7 @@
# FIXME: do not use ResourceTestCase
"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Test code for ansible commander.
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 = 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_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):
pass

View File

@ -57,7 +57,7 @@ class OrganizationsUsersList(BaseList):
def _get_queryset(self):
''' to list users in the organization, I must be a superuser or org admin '''
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()
return User.objects.filter(organizations__in = [ organization ])
@ -70,9 +70,9 @@ class OrganizationsAdminsList(BaseList):
def _get_queryset(self):
''' to list admins in the organization, I must be a superuser or org admin '''
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()
return User.objects.all(admin_of_organizations__in = [ organization ])
return User.objects.filter(admin_of_organizations__in = [ organization ])
class OrganizationsProjectsList(BaseSubList):