Merge lp:~cjwatson/launchpad/livefs-minimal-privacy into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 19033
Proposed branch: lp:~cjwatson/launchpad/livefs-minimal-privacy
Merge into: lp:launchpad
Diff against target: 196 lines (+46/-9)
6 files modified
lib/lp/soyuz/interfaces/livefs.py (+2/-1)
lib/lp/soyuz/interfaces/livefsbuild.py (+3/-2)
lib/lp/soyuz/model/livefs.py (+7/-0)
lib/lp/soyuz/model/livefsbuild.py (+3/-1)
lib/lp/soyuz/tests/test_livefs.py (+21/-2)
lib/lp/soyuz/tests/test_livefsbuild.py (+10/-3)
To merge this branch: bzr merge lp:~cjwatson/launchpad/livefs-minimal-privacy
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+370759@code.launchpad.net

Commit message

Make LiveFS and LiveFSBuild implement IPrivacy, so that the privacy banner works.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) wrote :

This isn't quite accurate, since the files' privacy doesn't follow the owner's, but that's rare enough that it probably doesn't matter.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/soyuz/interfaces/livefs.py'
2--- lib/lp/soyuz/interfaces/livefs.py 2019-06-12 10:59:25 +0000
3+++ lib/lp/soyuz/interfaces/livefs.py 2019-07-30 10:36:05 +0000
4@@ -59,6 +59,7 @@
5
6 from lp import _
7 from lp.app.errors import NameLookupFailed
8+from lp.app.interfaces.launchpad import IPrivacy
9 from lp.app.validators.name import name_validator
10 from lp.registry.interfaces.distroseries import IDistroSeries
11 from lp.registry.interfaces.person import IPerson
12@@ -139,7 +140,7 @@
13 """This live filesystem cannot be deleted."""
14
15
16-class ILiveFSView(Interface):
17+class ILiveFSView(IPrivacy):
18 """`ILiveFS` attributes that require launchpad.View permission."""
19
20 id = exported(Int(title=_("ID"), required=True, readonly=True))
21
22=== modified file 'lib/lp/soyuz/interfaces/livefsbuild.py'
23--- lib/lp/soyuz/interfaces/livefsbuild.py 2015-09-15 20:16:47 +0000
24+++ lib/lp/soyuz/interfaces/livefsbuild.py 2019-07-30 10:36:05 +0000
25@@ -1,4 +1,4 @@
26-# Copyright 2014-2015 Canonical Ltd. This software is licensed under the
27+# Copyright 2014-2019 Canonical Ltd. This software is licensed under the
28 # GNU Affero General Public License version 3 (see the file LICENSE).
29
30 """Live filesystem build interfaces."""
31@@ -30,6 +30,7 @@
32 )
33
34 from lp import _
35+from lp.app.interfaces.launchpad import IPrivacy
36 from lp.buildmaster.interfaces.buildfarmjob import ISpecificBuildFarmJobSource
37 from lp.buildmaster.interfaces.packagebuild import IPackageBuild
38 from lp.registry.interfaces.person import IPerson
39@@ -54,7 +55,7 @@
40 required=True, readonly=True)
41
42
43-class ILiveFSBuildView(IPackageBuild):
44+class ILiveFSBuildView(IPackageBuild, IPrivacy):
45 """`ILiveFSBuild` attributes that require launchpad.View permission."""
46
47 requester = exported(Reference(
48
49=== modified file 'lib/lp/soyuz/model/livefs.py'
50--- lib/lp/soyuz/model/livefs.py 2019-06-12 10:59:25 +0000
51+++ lib/lp/soyuz/model/livefs.py 2019-07-30 10:36:05 +0000
52@@ -139,6 +139,13 @@
53 self.keep_binary_files_days = keep_binary_files_days
54
55 @property
56+ def private(self):
57+ """See `IPrivacy`."""
58+ # A LiveFS has no privacy support of its own, but it is private if
59+ # its owner is.
60+ return self.owner.private
61+
62+ @property
63 def keep_binary_files_days(self):
64 """See `ILiveFS`."""
65 # Rounding up preserves the "at least this many days" part of the
66
67=== modified file 'lib/lp/soyuz/model/livefsbuild.py'
68--- lib/lp/soyuz/model/livefsbuild.py 2017-07-18 16:22:03 +0000
69+++ lib/lp/soyuz/model/livefsbuild.py 2019-07-30 10:36:05 +0000
70@@ -1,4 +1,4 @@
71-# Copyright 2014-2017 Canonical Ltd. This software is licensed under the
72+# Copyright 2014-2019 Canonical Ltd. This software is licensed under the
73 # GNU Affero General Public License version 3 (see the file LICENSE).
74
75 __metaclass__ = type
76@@ -171,6 +171,8 @@
77 """See `IBuildFarmJob`."""
78 return self.livefs.owner.private or self.archive.private
79
80+ private = is_private
81+
82 @property
83 def title(self):
84 das = self.distro_arch_series
85
86=== modified file 'lib/lp/soyuz/tests/test_livefs.py'
87--- lib/lp/soyuz/tests/test_livefs.py 2019-06-12 10:59:25 +0000
88+++ lib/lp/soyuz/tests/test_livefs.py 2019-07-30 10:36:05 +0000
89@@ -20,6 +20,7 @@
90 from zope.security.interfaces import Unauthorized
91 from zope.security.proxy import removeSecurityProxy
92
93+from lp.app.interfaces.launchpad import IPrivacy
94 from lp.buildmaster.enums import (
95 BuildQueueStatus,
96 BuildStatus,
97@@ -85,10 +86,11 @@
98 self.useFixture(FeatureFixture({LIVEFS_FEATURE_FLAG: "on"}))
99
100 def test_implements_interfaces(self):
101- # LiveFS implements ILiveFS.
102+ # LiveFS implements ILiveFS and IPrivacy.
103 livefs = self.factory.makeLiveFS()
104 with person_logged_in(livefs.owner):
105 self.assertProvides(livefs, ILiveFS)
106+ self.assertProvides(livefs, IPrivacy)
107
108 def test_avoids_problematic_snapshots(self):
109 self.assertThat(
110@@ -112,6 +114,20 @@
111 self.assertSqlAttributeEqualsDate(
112 livefs, "date_last_modified", UTC_NOW)
113
114+ def test_private_owner(self):
115+ # A LiveFS is private if its owner is.
116+ person = self.factory.makePerson()
117+ team = self.factory.makeTeam(
118+ owner=person, visibility=PersonVisibility.PRIVATE)
119+ with person_logged_in(person):
120+ livefs = self.factory.makeLiveFS(registrant=person, owner=team)
121+ self.assertTrue(livefs.private)
122+
123+ def test_public(self):
124+ # A LiveFS is public if its owner is.
125+ livefs = self.factory.makeLiveFS()
126+ self.assertFalse(livefs.private)
127+
128 def test_relative_build_score(self):
129 # Buildd admins can change the relative build score of a LiveFS, but
130 # ordinary users cannot.
131@@ -665,7 +681,10 @@
132 private=True)
133 archive_url = api_url(archive)
134 livefs, _ = self.makeLiveFS(distroseries=distroseries)
135- response = self.webservice.named_post(
136+ private_webservice = webservice_for_person(
137+ self.person, permission=OAuthPermission.WRITE_PRIVATE)
138+ private_webservice.default_api_version = "devel"
139+ response = private_webservice.named_post(
140 livefs["self_link"], "requestBuild", archive=archive_url,
141 distro_arch_series=distroarchseries_url, pocket="Release")
142 self.assertEqual(201, response.status)
143
144=== modified file 'lib/lp/soyuz/tests/test_livefsbuild.py'
145--- lib/lp/soyuz/tests/test_livefsbuild.py 2019-05-22 14:57:45 +0000
146+++ lib/lp/soyuz/tests/test_livefsbuild.py 2019-07-30 10:36:05 +0000
147@@ -1,4 +1,4 @@
148-# Copyright 2014-2018 Canonical Ltd. This software is licensed under the
149+# Copyright 2014-2019 Canonical Ltd. This software is licensed under the
150 # GNU Affero General Public License version 3 (see the file LICENSE).
151
152 """Test live filesystem build features."""
153@@ -21,7 +21,10 @@
154 from zope.security.proxy import removeSecurityProxy
155
156 from lp.app.errors import NotFoundError
157-from lp.app.interfaces.launchpad import ILaunchpadCelebrities
158+from lp.app.interfaces.launchpad import (
159+ ILaunchpadCelebrities,
160+ IPrivacy,
161+ )
162 from lp.buildmaster.enums import BuildStatus
163 from lp.buildmaster.interfaces.buildqueue import IBuildQueue
164 from lp.buildmaster.interfaces.packagebuild import IPackageBuild
165@@ -96,9 +99,10 @@
166 self.build = self.factory.makeLiveFSBuild()
167
168 def test_implements_interfaces(self):
169- # LiveFSBuild implements IPackageBuild and ILiveFSBuild.
170+ # LiveFSBuild implements IPackageBuild, ILiveFSBuild, and IPrivacy.
171 self.assertProvides(self.build, IPackageBuild)
172 self.assertProvides(self.build, ILiveFSBuild)
173+ self.assertProvides(self.build, IPrivacy)
174
175 def test_queueBuild(self):
176 # LiveFSBuild can create the queue entry for itself.
177@@ -127,16 +131,19 @@
178 def test_is_private(self):
179 # A LiveFSBuild is private iff its LiveFS and archive are.
180 self.assertFalse(self.build.is_private)
181+ self.assertFalse(self.build.private)
182 private_team = self.factory.makeTeam(
183 visibility=PersonVisibility.PRIVATE)
184 with person_logged_in(private_team.teamowner):
185 build = self.factory.makeLiveFSBuild(
186 requester=private_team.teamowner, owner=private_team)
187 self.assertTrue(build.is_private)
188+ self.assertTrue(build.private)
189 private_archive = self.factory.makeArchive(private=True)
190 with person_logged_in(private_archive.owner):
191 build = self.factory.makeLiveFSBuild(archive=private_archive)
192 self.assertTrue(build.is_private)
193+ self.assertTrue(build.private)
194
195 def test_can_be_cancelled(self):
196 # For all states that can be cancelled, can_be_cancelled returns True.