Merge ~twom/launchpad:export-source-properties-on-BPPH into launchpad:master

Proposed by Tom Wardill
Status: Merged
Approved by: Tom Wardill
Approved revision: bbad0dfa5227a4292f653eab5725acea473fcc6a
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~twom/launchpad:export-source-properties-on-BPPH
Merge into: launchpad:master
Diff against target: 152 lines (+79/-3)
5 files modified
lib/lp/soyuz/interfaces/binarypackagerelease.py (+2/-0)
lib/lp/soyuz/interfaces/publishing.py (+15/-2)
lib/lp/soyuz/model/binarypackagerelease.py (+5/-0)
lib/lp/soyuz/model/publishing.py (+5/-0)
lib/lp/soyuz/tests/test_publishing_models.py (+52/-1)
Reviewer Review Type Date Requested Status
Tom Wardill (community) Approve
Colin Watson (community) Approve
Ioana Lasc (community) Approve
Review via email: mp+391538@code.launchpad.net

Commit message

Export source package name and version on BPPH

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) wrote :

LGTM

review: Approve
Revision history for this message
Colin Watson (cjwatson) wrote :

This should work, but I'd like a comment somewhere about why it's needed for future reference. The problem was that indirecting through the BinaryPackageBuild via the webservice only works if it's possible to traverse to the build's URL, and because build URLs are subordinate to their original archive this doesn't work if you can't see the original archive, even though the security adapter for the build itself might permit it due to the SPR having been copied around. Doing the indirection internally avoids this problem, but is still safe because no security proxies are bypassed.

review: Approve
bbad0df... by Tom Wardill

Fix import, add comment

Revision history for this message
Tom Wardill (twom) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/soyuz/interfaces/binarypackagerelease.py b/lib/lp/soyuz/interfaces/binarypackagerelease.py
2index 2ee397e..592d515 100644
3--- a/lib/lp/soyuz/interfaces/binarypackagerelease.py
4+++ b/lib/lp/soyuz/interfaces/binarypackagerelease.py
5@@ -90,6 +90,8 @@ class IBinaryPackageRelease(Interface):
6 name = Attribute("Binary Package Name")
7 sourcepackagename = Attribute(
8 "The name of the source package from where this binary was built.")
9+ sourcepackageversion = Attribute(
10+ "The version of the source package from where this binary was built.")
11
12 def addFile(file):
13 """Create a BinaryPackageFile record referencing this build
14diff --git a/lib/lp/soyuz/interfaces/publishing.py b/lib/lp/soyuz/interfaces/publishing.py
15index 4443284..fe1c424 100644
16--- a/lib/lp/soyuz/interfaces/publishing.py
17+++ b/lib/lp/soyuz/interfaces/publishing.py
18@@ -604,8 +604,21 @@ class IBinaryPackagePublishingHistoryPublic(IPublishingView):
19 required=False, readonly=False)
20 binarypackagerelease = Attribute(
21 "The binary package release being published")
22- source_package_name = Attribute(
23- 'The source package name that built this binary.')
24+ # This and source_package_version are exported here to
25+ # avoid clients needing to indirectly look this up via a build.
26+ # This can cause security errors due to the differing levels of access.
27+ # Exporting here allows the lookup to happen internally.
28+ source_package_name = exported(
29+ TextLine(
30+ title=_("Source Package Name"),
31+ description=_('The source package name that built this binary.'),
32+ required=False, readonly=True))
33+ source_package_version = exported(
34+ TextLine(
35+ title=_("Source Package Version"),
36+ description=_(
37+ 'The source package version that built this binary.'),
38+ required=False, readonly=True))
39 distroarchseriesID = Int(
40 title=_("The DB id for the distroarchseries."),
41 required=False, readonly=False)
42diff --git a/lib/lp/soyuz/model/binarypackagerelease.py b/lib/lp/soyuz/model/binarypackagerelease.py
43index 3458b70..8866723 100644
44--- a/lib/lp/soyuz/model/binarypackagerelease.py
45+++ b/lib/lp/soyuz/model/binarypackagerelease.py
46@@ -125,6 +125,11 @@ class BinaryPackageRelease(SQLBase):
47 """See `IBinaryPackageRelease`."""
48 return self.build.source_package_release.sourcepackagename.name
49
50+ @property
51+ def sourcepackageversion(self):
52+ """See `IBinaryPackageRelease`."""
53+ return self.build.source_package_release.version
54+
55 @cachedproperty
56 def files(self):
57 return list(
58diff --git a/lib/lp/soyuz/model/publishing.py b/lib/lp/soyuz/model/publishing.py
59index 33390b5..86db3c1 100644
60--- a/lib/lp/soyuz/model/publishing.py
61+++ b/lib/lp/soyuz/model/publishing.py
62@@ -704,6 +704,11 @@ class BinaryPackagePublishingHistory(SQLBase, ArchivePublisherBase):
63 return self.binarypackagerelease.sourcepackagename
64
65 @property
66+ def source_package_version(self):
67+ """See `IBinaryPackagePublishingHistory`"""
68+ return self.binarypackagerelease.sourcepackageversion
69+
70+ @property
71 def architecture_specific(self):
72 """See `IBinaryPackagePublishingHistory`"""
73 return self.binarypackagerelease.architecturespecific
74diff --git a/lib/lp/soyuz/tests/test_publishing_models.py b/lib/lp/soyuz/tests/test_publishing_models.py
75index 6ed7adc..ecfcf15 100644
76--- a/lib/lp/soyuz/tests/test_publishing_models.py
77+++ b/lib/lp/soyuz/tests/test_publishing_models.py
78@@ -6,10 +6,12 @@
79 from __future__ import absolute_import, print_function, unicode_literals
80
81 from zope.component import getUtility
82+from zope.security.interfaces import Unauthorized
83 from zope.security.proxy import removeSecurityProxy
84
85 from lp.app.errors import NotFoundError
86 from lp.buildmaster.enums import BuildStatus
87+from lp.registry.enums import PersonVisibility
88 from lp.registry.interfaces.sourcepackage import SourcePackageFileType
89 from lp.services.database.constants import UTC_NOW
90 from lp.services.librarian.browser import ProxiedLibraryFileAlias
91@@ -24,7 +26,10 @@ from lp.soyuz.interfaces.publishing import (
92 PackagePublishingStatus,
93 )
94 from lp.soyuz.tests.test_binarypackagebuild import BaseTestCaseWithThreeBuilds
95-from lp.testing import TestCaseWithFactory
96+from lp.testing import (
97+ person_logged_in,
98+ TestCaseWithFactory,
99+ )
100 from lp.testing.layers import (
101 LaunchpadFunctionalLayer,
102 LaunchpadZopelessLayer,
103@@ -297,3 +302,49 @@ class TestBinaryPackagePublishingHistory(TestCaseWithFactory):
104 bpph = self.factory.makeBinaryPackagePublishingHistory(
105 binpackageformat=BinaryPackageFormat.DDEB)
106 self.assertTrue(bpph.is_debug)
107+
108+ def test_source_package_name(self):
109+ bpph = self.factory.makeBinaryPackagePublishingHistory()
110+ self.assertEqual(
111+ bpph.binarypackagerelease.sourcepackagename,
112+ bpph.source_package_name)
113+
114+ def test_source_package_name_private(self):
115+ team_owner = self.factory.makePerson()
116+ private_team = self.factory.makeTeam(
117+ owner=team_owner, visibility=PersonVisibility.PRIVATE)
118+ ppa = self.factory.makeArchive(private=True, owner=private_team)
119+ with person_logged_in(team_owner):
120+ bpph = self.factory.makeBinaryPackagePublishingHistory(
121+ archive=ppa)
122+ self.assertEqual(
123+ bpph.binarypackagerelease.sourcepackagename,
124+ bpph.source_package_name)
125+ self.assertRaises(
126+ Unauthorized,
127+ getattr,
128+ bpph,
129+ 'source_package_name')
130+
131+ def test_source_package_version(self):
132+ bpph = self.factory.makeBinaryPackagePublishingHistory()
133+ self.assertEqual(
134+ bpph.binarypackagerelease.sourcepackageversion,
135+ bpph.source_package_version)
136+
137+ def test_source_package_version_private(self):
138+ team_owner = self.factory.makePerson()
139+ private_team = self.factory.makeTeam(
140+ owner=team_owner, visibility=PersonVisibility.PRIVATE)
141+ ppa = self.factory.makeArchive(private=True, owner=private_team)
142+ with person_logged_in(team_owner):
143+ bpph = self.factory.makeBinaryPackagePublishingHistory(
144+ archive=ppa)
145+ self.assertEqual(
146+ bpph.binarypackagerelease.sourcepackageversion,
147+ bpph.source_package_version)
148+ self.assertRaises(
149+ Unauthorized,
150+ getattr,
151+ bpph,
152+ 'source_package_version')

Subscribers

People subscribed via source and target branches

to status/vote changes: