launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #04873
[Merge] lp:~dev-nigelj/launchpad/bug-674854 into lp:launchpad
Nigel Jones has proposed merging lp:~dev-nigelj/launchpad/bug-674854 into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #841658 in Launchpad itself: "DistroSeries/DistroArchSeries API link does not return any entries"
https://bugs.launchpad.net/launchpad/+bug/841658
For more details, see:
https://code.launchpad.net/~dev-nigelj/launchpad/bug-674854/+merge/74064
Summary
The API currently does not return entries for the DistroSeries/DistroArchSeries link when requested by an unauthenticated user. An example of which:
$ curl -k https://api.launchpad.dev/devel/ubuntu/hoary/architectures
{"total_size": 3, "start": 0, "entries": [], "resource_type_link" : "https://api.launchpad.dev/devel/#distro_arch_series-page-resource"}
Proposed/Implemented Fix
The proposed fix (thanks to a lot of nudging in the right direction by wgrant) is alter lib/canonical/launchpad/security.py to allow read anonymous access to the DistroArchSeries interface.
Implementation Details
The "ViewDistroArchSeries(AnonymousAuthorization)" class specifies the IDistroArchSeries interface for anonymous API access.
In addition, a new test in lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py tests that the architectures entries property is filled properly for anonymous users.
Tests
All tests expected to pass (there are some passes that seem to fail on natty consistently), pass without issue.
Demo / QA
$ curl -k https://api.launchpad.dev/devel/ubuntu/hoary/architectures
Should return entries
and the python code
from launchpadlib.launchpad import Launchpad
launchpad = Launchpad.login_anonymously('test', 'https://api.launchpad.dev')
ubuntudistro = launchpad.distributions["ubuntu"]
print ubuntudistro.current_series.architectures.entries
should also return the same entries as in the database.
Lint
= Launchpad lint =
Checking for conflicts and issues in changed files.
Linting changed files:
lib/canonical/launchpad/security.py
lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py
--
https://code.launchpad.net/~dev-nigelj/launchpad/bug-674854/+merge/74064
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~dev-nigelj/launchpad/bug-674854 into lp:launchpad.
=== modified file 'lib/canonical/launchpad/security.py'
--- lib/canonical/launchpad/security.py 2011-08-31 19:45:02 +0000
+++ lib/canonical/launchpad/security.py 2011-09-05 09:40:26 +0000
@@ -175,6 +175,7 @@
IBinaryPackageReleaseDownloadCount,
)
from lp.soyuz.interfaces.buildfarmbuildjob import IBuildFarmBuildJob
+from lp.soyuz.interfaces.distroarchseries import IDistroArchSeries
from lp.soyuz.interfaces.packagecopyjob import IPlainPackageCopyJob
from lp.soyuz.interfaces.packageset import (
IPackageset,
@@ -1045,6 +1046,11 @@
return EditByOwnersOrAdmins.checkAuthenticated(self, user)
+class ViewDistroArchSeries(AnonymousAuthorization):
+ """Anyone can view a DistroArchSeries."""
+ usedfor = IDistroArchSeries
+
+
class ViewAnnouncement(AuthorizationBase):
permission = 'launchpad.View'
usedfor = IAnnouncement
=== added file 'lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py'
--- lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py 1970-01-01 00:00:00 +0000
+++ lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py 2011-09-05 09:40:26 +0000
@@ -0,0 +1,33 @@
+# Copyright 2010-2011 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+__metaclass__ = type
+
+from zope.security.management import endInteraction
+
+from canonical.testing.layers import DatabaseFunctionalLayer
+from lp.testing import (
+ launchpadlib_for,
+ ws_object,
+ TestCaseWithFactory,
+ )
+
+
+class TestDistroArchSeriesWebservice(TestCaseWithFactory):
+ layer = DatabaseFunctionalLayer
+
+ def setUp(self):
+ TestCaseWithFactory.setUp(self)
+ distro = self.factory.makeDistribution()
+ distroseries = self.factory.makeDistroSeries(
+ distribution=distro)
+ self.factory.makeDistroArchSeries(
+ distroseries=distroseries)
+
+ self.distroseries = distroseries
+
+ def test_distroseries_architectures(self):
+ endInteraction()
+ launchpad = launchpadlib_for('test', None, version='devel')
+ ws_distroseries = ws_object(launchpad, self.distroseries)
+ self.assertEqual(1, len(ws_distroseries.architectures))