Merge lp:~dholbach/loco-team-portal/fix-acl-checks into lp:~ltp-devs/loco-team-portal/trunk

Proposed by Daniel Holbach
Status: Merged
Merged at revision: not available
Proposed branch: lp:~dholbach/loco-team-portal/fix-acl-checks
Merge into: lp:~ltp-devs/loco-team-portal/trunk
Diff against target: 81 lines (+37/-8)
3 files modified
loco_directory/common/launchpad.py (+8/-7)
loco_directory/teams/tests.py (+28/-0)
loco_directory/teams/views.py (+1/-1)
To merge this branch: bzr merge lp:~dholbach/loco-team-portal/fix-acl-checks
Reviewer Review Type Date Requested Status
Efrain Valles Approve
Review via email: mp+14746@code.launchpad.net
To post a comment you must log in.
102. By Daniel Holbach

add two more test

Revision history for this message
Efrain Valles (effie-jayx) wrote :

The code works fine here, great coding for testing

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'loco_directory/common/launchpad.py'
2--- loco_directory/common/launchpad.py 2009-11-09 16:51:29 +0000
3+++ loco_directory/common/launchpad.py 2009-11-12 09:16:15 +0000
4@@ -43,23 +43,24 @@
5 except:
6 print >> sys.stderr, 'Something went wrong.'
7 return False
8- return user in [a for a in team.members]
9+ return user in [a.name for a in team.members]
10
11-def is_admin_or_owner(user, team):
12+def is_admin_or_owner(username, team):
13 # check just using the LD data
14- if user == team.owner:
15+ if username == team.owner:
16 return True
17- if team.admins.filter(lpid=user.username):
18+ if team.admins.filter(lpid=username):
19 return True
20
21 # more complicated check :-/
22 lp = lp_login()
23 try:
24 lp_team = lp.people[team.lp_name]
25- if lp_team.owner.is_team:
26- if filter(lambda a: a.name == user.username, lp_team.members):
27- return True
28 except:
29+ print >> sys.stderr, 'Something went wrong.'
30 return False
31+ if lp_team.team_owner.is_team:
32+ if filter(lambda a: a.name == username, lp_team.team_owner.members):
33+ return True
34 return False
35
36
37=== added file 'loco_directory/teams/tests.py'
38--- loco_directory/teams/tests.py 1970-01-01 00:00:00 +0000
39+++ loco_directory/teams/tests.py 2009-11-12 09:16:15 +0000
40@@ -0,0 +1,28 @@
41+from django.test import TestCase
42+
43+from teams.models import *
44+from common import launchpad
45+
46+class LoCoCouncilACLTestCase(TestCase):
47+ def testACLs(self):
48+ """Test if LoCo Council check works
49+ """
50+ self.assertEquals(launchpad.is_user_on_loco_council("popey"), True)
51+ self.assertEquals(launchpad.is_user_on_loco_council("jonobacon"), False)
52+
53+class ACLChecksTestCase(TestCase):
54+# to create this, run:
55+# mkdir teams/fixtures
56+# ./manage.py dumpdata --format xml teams > teams/fixtures/test_data.xml
57+ fixtures = ["test_data.xml"]
58+
59+ def testAdminIsATeamChecks(self):
60+ """Test if check for a more complicated LoCo Team setup works
61+ """
62+ teams = Team.objects.all()
63+ chile = teams.filter(lp_name="ubuntu-cl")[0]
64+ self.assertEquals(launchpad.is_admin_or_owner("pvillavi", chile), True)
65+
66+ venezuela = teams.filter(lp_name="ubuntu-ve")[0]
67+ self.assertEquals(launchpad.is_admin_or_owner("effie-jayx", venezuela), True)
68+ self.assertEquals(launchpad.is_admin_or_owner("jorge", venezuela), False)
69
70=== modified file 'loco_directory/teams/views.py'
71--- loco_directory/teams/views.py 2009-11-10 11:30:15 +0000
72+++ loco_directory/teams/views.py 2009-11-12 09:16:15 +0000
73@@ -43,7 +43,7 @@
74 'team': team,
75 }
76 if type(request.user) == AnonymousUser or \
77- not launchpad.is_admin_or_owner(request.user, team):
78+ not launchpad.is_admin_or_owner(request.user.username, team):
79 return render('teams/team_detail.html', context, context_instance=RequestContext(request))
80
81 if request.method == "POST":

Subscribers

People subscribed via source and target branches