Merge lp:~stevenk/launchpad/db-software-center-agent-celebrity into lp:launchpad/db-devel

Proposed by Steve Kowalik
Status: Merged
Approved by: Steve Kowalik
Approved revision: no longer in the source branch.
Merged at revision: 9511
Proposed branch: lp:~stevenk/launchpad/db-software-center-agent-celebrity
Merge into: lp:launchpad/db-devel
Diff against target: 109 lines (+76/-0)
3 files modified
lib/canonical/launchpad/security.py (+12/-0)
lib/canonical/launchpad/utilities/celebrities.py (+2/-0)
lib/lp/soyuz/tests/test_archive_agent.py (+62/-0)
To merge this branch: bzr merge lp:~stevenk/launchpad/db-software-center-agent-celebrity
Reviewer Review Type Date Requested Status
Michael Nelson (community) Approve
Review via email: mp+28881@code.launchpad.net

Commit message

Add 'software-center-agent' as a celebrity, and give it View and Append access to commercial archives.

Description of the change

This branch adds a new 'software-center-agent' celebrity, changes the security adapter to give it access to modify and view commercial archives, and adds tests.

To post a comment you must log in.
Revision history for this message
Michael Nelson (michael.nelson) wrote :

15:33 < noodles> Great... looks good. Just some really small recommendations:
15:34 < noodles> I'd add a method makeArchivePrivate() which takes care of switching users etc., or just use removeSecurityProxy so you don't have to know
                 which user to login as afterwards. That will also enable you to log the agent in in the setup once.
15:35 < noodles> And I'd create the 'joe' user in those two methods rather than in the setup. Let me know if you disagree, but r=me as is anyway.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/security.py'
2--- lib/canonical/launchpad/security.py 2010-06-28 18:40:33 +0000
3+++ lib/canonical/launchpad/security.py 2010-06-30 13:53:28 +0000
4@@ -2060,6 +2060,12 @@
5 if archive_subs:
6 return True
7
8+ # The software center agent can view commercial archives
9+ if self.obj.commercial:
10+ agent = getUtility(ILaunchpadCelebrities).software_center_agent
11+ if user.person == agent:
12+ return True
13+
14 return False
15
16 def checkUnauthenticated(self):
17@@ -2098,6 +2104,12 @@
18 user.in_ubuntu_security):
19 return True
20
21+ # The software center agent can change commercial archives
22+ if self.obj.commercial:
23+ agent = getUtility(ILaunchpadCelebrities).software_center_agent
24+ if user.person == agent:
25+ return True
26+
27 return False
28
29
30
31=== modified file 'lib/canonical/launchpad/utilities/celebrities.py'
32--- lib/canonical/launchpad/utilities/celebrities.py 2010-01-08 14:45:17 +0000
33+++ lib/canonical/launchpad/utilities/celebrities.py 2010-06-30 13:53:28 +0000
34@@ -121,6 +121,8 @@
35
36 admin = PersonCelebrityDescriptor('admins')
37 bazaar_experts = PersonCelebrityDescriptor('bazaar-experts')
38+ software_center_agent = PersonCelebrityDescriptor(
39+ 'software-center-agent')
40 bug_importer = PersonCelebrityDescriptor('bug-importer')
41 bug_watch_updater = PersonCelebrityDescriptor('bug-watch-updater')
42 buildd_admin = PersonCelebrityDescriptor('launchpad-buildd-admins')
43
44=== added file 'lib/lp/soyuz/tests/test_archive_agent.py'
45--- lib/lp/soyuz/tests/test_archive_agent.py 1970-01-01 00:00:00 +0000
46+++ lib/lp/soyuz/tests/test_archive_agent.py 2010-06-30 13:53:28 +0000
47@@ -0,0 +1,62 @@
48+# Copyright 2010 Canonical Ltd. This software is licensed under the
49+# GNU Affero General Public License version 3 (see the file LICENSE).
50+
51+"""Test Archive software center agent celebrity."""
52+
53+from zope.component import getUtility
54+from canonical.launchpad.webapp.authorization import check_permission
55+from lp.soyuz.interfaces.archivesubscriber import IArchiveSubscriberSet
56+from canonical.testing import LaunchpadFunctionalLayer
57+from lp.testing import login, login_person, TestCaseWithFactory
58+
59+
60+class TestArchivePrivacy(TestCaseWithFactory):
61+ layer = LaunchpadFunctionalLayer
62+
63+ def setUp(self):
64+ super(TestArchivePrivacy, self).setUp()
65+ self.ppa = self._makePrivateArchive()
66+ self.ppa.commercial = True
67+ self.agent = self.factory.makePerson(name='software-center-agent')
68+ self.joe = self.factory.makePerson(name='joe')
69+
70+ def _makePrivateArchive(self):
71+ ppa = self.factory.makeArchive()
72+ login('admin@canonical.com')
73+ ppa.buildd_secret = 'blah'
74+ ppa.private = True
75+ return ppa
76+
77+ def test_check_permission(self):
78+ """The software center agent has the relevant permissions for a
79+ commercial archive, but not a private one.
80+ """
81+ login_person(self.agent)
82+ self.assertEqual(
83+ check_permission('launchpad.View', self.ppa), True)
84+ self.assertEqual(
85+ check_permission('launchpad.Append', self.ppa), True)
86+
87+ def test_check_permission_private(self):
88+ ppa = self._makePrivateArchive()
89+ login_person(self.agent)
90+ self.assertEqual(check_permission('launchpad.View', ppa), False)
91+ self.assertEqual(check_permission('launchpad.Append', ppa), False)
92+
93+ def test_add_subscription(self):
94+ login_person(self.agent)
95+ self.ppa.newSubscription(self.joe, self.agent)
96+ subscription = getUtility(
97+ IArchiveSubscriberSet).getBySubscriber(
98+ self.joe, archive=self.ppa).one()
99+ self.assertEqual(subscription.registrant, self.agent)
100+ self.assertEqual(subscription.subscriber, self.joe)
101+
102+ def test_getPrivateSourcesList(self):
103+ login_person(self.agent)
104+ sources = self.ppa.getPrivateSourcesList(self.joe)
105+ authtoken = self.ppa.getAuthToken(self.joe).token
106+ url = self.ppa.archive_url.split('http://')[1]
107+ new_url = "http://joe:%s@%s" % (authtoken, url)
108+ self.assertEqual(sources, new_url)
109+

Subscribers

People subscribed via source and target branches

to status/vote changes: