Merge lp:~salgado/launchpad/bug-683106 into lp:launchpad

Proposed by Guilherme Salgado
Status: Merged
Merged at revision: 12011
Proposed branch: lp:~salgado/launchpad/bug-683106
Merge into: lp:launchpad
Diff against target: 141 lines (+50/-1)
5 files modified
lib/canonical/launchpad/security.py (+15/-1)
lib/lp/blueprints/interfaces/specification.py (+1/-0)
lib/lp/blueprints/tests/test_webservice.py (+16/-0)
lib/lp/testing/__init__.py (+1/-0)
lib/lp/testing/_webservice.py (+17/-0)
To merge this branch: bzr merge lp:~salgado/launchpad/bug-683106
Reviewer Review Type Date Requested Status
Jelmer Vernooij (community) Approve
Review via email: mp+42351@code.launchpad.net

Commit message

[r=jelmer][ui=none][bug=683106]

Description of the change

Add a launchpad.View security adapter for ISpecification so that collections
of it can be seen anonymously on the webservice

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/canonical/launchpad/security.py'
--- lib/canonical/launchpad/security.py 2010-11-26 18:12:16 +0000
+++ lib/canonical/launchpad/security.py 2010-12-01 13:02:06 +0000
@@ -44,7 +44,10 @@
44from lp.answers.interfaces.faqtarget import IFAQTarget44from lp.answers.interfaces.faqtarget import IFAQTarget
45from lp.answers.interfaces.question import IQuestion45from lp.answers.interfaces.question import IQuestion
46from lp.answers.interfaces.questiontarget import IQuestionTarget46from lp.answers.interfaces.questiontarget import IQuestionTarget
47from lp.blueprints.interfaces.specification import ISpecification47from lp.blueprints.interfaces.specification import (
48 ISpecification,
49 ISpecificationPublic,
50 )
48from lp.blueprints.interfaces.specificationbranch import ISpecificationBranch51from lp.blueprints.interfaces.specificationbranch import ISpecificationBranch
49from lp.blueprints.interfaces.specificationsubscription import (52from lp.blueprints.interfaces.specificationsubscription import (
50 ISpecificationSubscription,53 ISpecificationSubscription,
@@ -494,6 +497,17 @@
494 return True497 return True
495498
496499
500class AnonymousAccessToISpecificationPublic(AnonymousAuthorization):
501 """Anonymous users have launchpad.View on ISpecificationPublic.
502
503 This is only needed because lazr.restful is hard-coded to check that
504 permission before returning things in a collection.
505 """
506
507 permission = 'launchpad.View'
508 usedfor = ISpecificationPublic
509
510
497class EditSpecificationByTargetOwnerOrOwnersOrAdmins(AuthorizationBase):511class EditSpecificationByTargetOwnerOrOwnersOrAdmins(AuthorizationBase):
498 """We want everybody "related" to a specification to be able to edit it.512 """We want everybody "related" to a specification to be able to edit it.
499 You are related if you have a role on the spec, or if you have a role on513 You are related if you have a role on the spec, or if you have a role on
500514
=== modified file 'lib/lp/blueprints/interfaces/specification.py'
--- lib/lp/blueprints/interfaces/specification.py 2010-11-29 18:53:45 +0000
+++ lib/lp/blueprints/interfaces/specification.py 2010-12-01 13:02:06 +0000
@@ -14,6 +14,7 @@
14 'INewSpecificationTarget',14 'INewSpecificationTarget',
15 'INewSpecificationProjectTarget',15 'INewSpecificationProjectTarget',
16 'ISpecification',16 'ISpecification',
17 'ISpecificationPublic',
17 'ISpecificationSet',18 'ISpecificationSet',
18 'ISpecificationDelta',19 'ISpecificationDelta',
19 ]20 ]
2021
=== modified file 'lib/lp/blueprints/tests/test_webservice.py'
--- lib/lp/blueprints/tests/test_webservice.py 2010-11-29 18:53:45 +0000
+++ lib/lp/blueprints/tests/test_webservice.py 2010-12-01 13:02:06 +0000
@@ -5,6 +5,8 @@
55
6__metaclass__ = type6__metaclass__ = type
77
8from zope.security.management import endInteraction
9
8from canonical.testing import DatabaseFunctionalLayer10from canonical.testing import DatabaseFunctionalLayer
9from canonical.launchpad.testing.pages import webservice_for_person11from canonical.launchpad.testing.pages import webservice_for_person
10from lp.blueprints.interfaces.specification import (12from lp.blueprints.interfaces.specification import (
@@ -12,7 +14,9 @@
12 )14 )
13from lp.testing import (15from lp.testing import (
14 launchpadlib_for,16 launchpadlib_for,
17 launchpadlib_for_anonymous,
15 TestCaseWithFactory,18 TestCaseWithFactory,
19 ws_object,
16 )20 )
1721
1822
@@ -215,6 +219,18 @@
215 names = [s.name for s in specifications]219 names = [s.name for s in specifications]
216 self.assertContentEqual(expected_names, names)220 self.assertContentEqual(expected_names, names)
217221
222 def test_anonymous_access_to_collection(self):
223 product = self.factory.makeProduct()
224 self.factory.makeSpecification(product=product, name="spec1")
225 self.factory.makeSpecification(product=product, name="spec2")
226 # Need to endInteraction() because launchpadlib_for_anonymous() will
227 # setup a new one.
228 endInteraction()
229 lplib = launchpadlib_for_anonymous('lplib-test', version='devel')
230 ws_product = ws_object(lplib, product)
231 self.assertNamesOfSpecificationsAre(
232 ["spec1", "spec2"], ws_product.all_specifications)
233
218 def test_product_all_specifications(self):234 def test_product_all_specifications(self):
219 product = self.factory.makeProduct()235 product = self.factory.makeProduct()
220 self.factory.makeSpecification(product=product, name="spec1")236 self.factory.makeSpecification(product=product, name="spec1")
221237
=== modified file 'lib/lp/testing/__init__.py'
--- lib/lp/testing/__init__.py 2010-11-26 10:52:10 +0000
+++ lib/lp/testing/__init__.py 2010-12-01 13:02:06 +0000
@@ -154,6 +154,7 @@
154from lp.testing._webservice import (154from lp.testing._webservice import (
155 launchpadlib_credentials_for,155 launchpadlib_credentials_for,
156 launchpadlib_for,156 launchpadlib_for,
157 launchpadlib_for_anonymous,
157 oauth_access_token_for,158 oauth_access_token_for,
158 )159 )
159from lp.testing.fixture import ZopeEventHandlerFixture160from lp.testing.fixture import ZopeEventHandlerFixture
160161
=== modified file 'lib/lp/testing/_webservice.py'
--- lib/lp/testing/_webservice.py 2010-10-23 16:44:23 +0000
+++ lib/lp/testing/_webservice.py 2010-12-01 13:02:06 +0000
@@ -8,6 +8,7 @@
8__all__ = [8__all__ = [
9 'launchpadlib_credentials_for',9 'launchpadlib_credentials_for',
10 'launchpadlib_for',10 'launchpadlib_for',
11 'launchpadlib_for_anonymous',
11 'oauth_access_token_for',12 'oauth_access_token_for',
12 ]13 ]
1314
@@ -17,6 +18,7 @@
1718
18from launchpadlib.credentials import (19from launchpadlib.credentials import (
19 AccessToken,20 AccessToken,
21 AnonymousAccessToken,
20 Credentials,22 Credentials,
21 )23 )
22from launchpadlib.launchpad import Launchpad24from launchpadlib.launchpad import Launchpad
@@ -118,6 +120,21 @@
118 shutil.rmtree(cache, ignore_errors=True)120 shutil.rmtree(cache, ignore_errors=True)
119121
120122
123def launchpadlib_for_anonymous(
124 consumer_name, version=None, service_root="http://api.launchpad.dev/"):
125 """Create a Launchpad object for the anonymous user.
126
127 :param consumer_name: An OAuth consumer name.
128 :param version: The version of the web service to access.
129 :param service_root: The root URL of the web service to access.
130
131 :return: A launchpadlib.Launchpad object.
132 """
133 token = AnonymousAccessToken()
134 credentials = Credentials(consumer_name, access_token=token)
135 return Launchpad(credentials, service_root, version=version)
136
137
121def launchpadlib_for(138def launchpadlib_for(
122 consumer_name, person, permission=OAuthPermission.WRITE_PRIVATE,139 consumer_name, person, permission=OAuthPermission.WRITE_PRIVATE,
123 context=None, version=None, service_root="http://api.launchpad.dev/"):140 context=None, version=None, service_root="http://api.launchpad.dev/"):