From 0d41b7bf07d65d8b881e651f9d2b0b12c5013722 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Mon, 1 Apr 2013 18:49:32 -0400 Subject: [PATCH] A user can access what teams they are on. --- lib/main/models/__init__.py | 4 ++-- lib/main/tests/projects.py | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/main/models/__init__.py b/lib/main/models/__init__.py index 3d1725ebd8..db86e17e34 100644 --- a/lib/main/models/__init__.py +++ b/lib/main/models/__init__.py @@ -110,7 +110,7 @@ class UserHelper(object): return 'partial' if user.is_superuser: return True - matching_orgs = len(set(obj.organizations.all()) & set(user.admin_of_organizations.all())) + matching_orgs = obj.organizations.filter(admins__in = [user]).count() return matching_orgs @classmethod @@ -123,7 +123,7 @@ class UserHelper(object): def can_user_delete(cls, user, obj): if user.is_superuser: return True - matching_orgs = len(set(obj.organizations.all()) & set(user.admin_of_organizations.all())) + matching_orgs = obj.organizations.filter(admins__in = [user]).count() return matching_orgs diff --git a/lib/main/tests/projects.py b/lib/main/tests/projects.py index 9884e727b6..d9f1165ebb 100644 --- a/lib/main/tests/projects.py +++ b/lib/main/tests/projects.py @@ -246,12 +246,30 @@ class ProjectsTest(BaseTest): self.assertEquals(Team.objects.get(pk=team.pk).users.count(), 0) + # ===================================================================== + # USER TEAMS + # from a user, can see what teams they are on (related resource) - print "TEAMS?" - print User.objects.get(username = 'other').teams.all() + other = User.objects.get(username = 'other') + url = '/api/v1/users/%s/teams/' % other.pk + self.get(url, expect=401) + self.get(url, expect=401, auth=self.get_invalid_credentials()) + self.get(url, expect=403, auth=self.get_nobody_credentials()) + other.organizations.add(Organization.objects.get(pk=2)) + other.save() + my_teams1 = self.get(url, expect=200, auth=self.get_normal_credentials()) + my_teams2 = self.get(url, expect=200, auth=self.get_other_credentials()) + self.assertEqual(my_teams1['count'], 2) + self.assertEqual(my_teams1, my_teams2) + + # ===================================================================== + # USER PROJECTS + + url = '/api/v1/users/%s/projects/' % other.pk # from a user, can see what projects they can see based on team association # though this resource doesn't do anything else + raise Exception("STOP") # ===================================================================== # CREDENTIALS