From 2484f7eb4a0bba6db97d234c812f41b7c10b04a3 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Sat, 23 Mar 2013 15:43:59 -0400 Subject: [PATCH] Listing the admins of an organization. --- lib/main/tests.py | 18 ++++++++++++------ lib/main/views.py | 6 +++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/main/tests.py b/lib/main/tests.py index 26bdd2d601..d81b6ac82b 100644 --- a/lib/main/tests.py +++ b/lib/main/tests.py @@ -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 """ @@ -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 diff --git a/lib/main/views.py b/lib/main/views.py index cce35f4b80..e0f14c36fa 100644 --- a/lib/main/views.py +++ b/lib/main/views.py @@ -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):