Merge ~twom/launchpad:add-restricted-files-to-spph-api into launchpad:master

Proposed by Tom Wardill
Status: Merged
Approved by: Tom Wardill
Approved revision: c02526a1a1b569f4a783e3dd9d034ee0fce19952
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~twom/launchpad:add-restricted-files-to-spph-api
Merge into: launchpad:master
Diff against target: 124 lines (+42/-17)
4 files modified
lib/lp/soyuz/browser/tests/test_publishing_webservice.py (+22/-0)
lib/lp/soyuz/interfaces/publishing.py (+5/-0)
lib/lp/soyuz/model/publishing.py (+13/-0)
lib/lp/soyuz/scripts/packagecopier.py (+2/-17)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+403967@code.launchpad.net

Commit message

Add has_restricted_files to SPPH API.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

Can this be exported as a method instead? The implementation isn't quite so trivial that I feel entirely comfortable exporting it as an attribute (which would mean that it'd be called any time somebody asks for one of these objects over the webservice).

In fact, the current interface claims that it's an attribute but the implementation is a non-property method, which probably won't quite work right. Consider renaming this to `hasRestrictedFiles` and fixing the interface to be a method with `@export_read_operation`.

Perhaps this could also do with a webservice test in `lp.soyuz.browser.tests.test_publishing_webservice`.

review: Needs Information
Revision history for this message
Colin Watson (cjwatson) :
Revision history for this message
Colin Watson (cjwatson) :
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/browser/tests/test_publishing_webservice.py b/lib/lp/soyuz/browser/tests/test_publishing_webservice.py
2index ee74d72..5a43e2f 100644
3--- a/lib/lp/soyuz/browser/tests/test_publishing_webservice.py
4+++ b/lib/lp/soyuz/browser/tests/test_publishing_webservice.py
5@@ -7,6 +7,8 @@ from __future__ import absolute_import, print_function, unicode_literals
6
7 from functools import partial
8
9+from zope.security.proxy import removeSecurityProxy
10+
11 from lp.services.librarian.browser import ProxiedLibraryFileAlias
12 from lp.services.webapp.interfaces import OAuthPermission
13 from lp.soyuz.adapters.proxiedsourcefiles import ProxiedSourceLibraryFileAlias
14@@ -82,6 +84,26 @@ class SourcePackagePublishingHistoryWebserviceTests(TestCaseWithFactory):
15 } for sprf in spph.sourcepackagerelease.files]
16 self.assertContentEqual(expected_info, info)
17
18+ def test_hasRestrictedFiles(self):
19+ person = self.factory.makePerson()
20+ webservice = webservice_for_person(
21+ person, permission=OAuthPermission.READ_PUBLIC)
22+ spph, url = self.make_spph_for(person)
23+
24+ response = webservice.named_get(
25+ url, 'hasRestrictedFiles', api_version='devel')
26+ self.assertEqual(200, response.status)
27+ self.assertFalse(response.jsonBody())
28+
29+ with person_logged_in(person):
30+ sprf = spph.sourcepackagerelease.files[0]
31+ removeSecurityProxy(sprf.libraryfile).restricted = True
32+
33+ response = webservice.named_get(
34+ url, 'hasRestrictedFiles', api_version='devel')
35+ self.assertEqual(200, response.status)
36+ self.assertTrue(response.jsonBody())
37+
38
39 class BinaryPackagePublishingHistoryWebserviceTests(TestCaseWithFactory):
40
41diff --git a/lib/lp/soyuz/interfaces/publishing.py b/lib/lp/soyuz/interfaces/publishing.py
42index fe1c424..eae5343 100644
43--- a/lib/lp/soyuz/interfaces/publishing.py
44+++ b/lib/lp/soyuz/interfaces/publishing.py
45@@ -428,6 +428,11 @@ class ISourcePackagePublishingHistoryPublic(IPublishingView):
46 `IBinaryPackagePublishingHistory`.
47 """
48
49+ @export_read_operation()
50+ @operation_for_version("devel")
51+ def hasRestrictedFiles():
52+ """Return whether or not a given source files has restricted files."""
53+
54 # Really IBuild (fixed in _schema_circular_imports.py)
55 @operation_returns_collection_of(Interface)
56 @export_read_operation()
57diff --git a/lib/lp/soyuz/model/publishing.py b/lib/lp/soyuz/model/publishing.py
58index 2c84740..3890bb0 100644
59--- a/lib/lp/soyuz/model/publishing.py
60+++ b/lib/lp/soyuz/model/publishing.py
61@@ -619,6 +619,19 @@ class SourcePackagePublishingHistory(SQLBase, ArchivePublisherBase):
62 getUtility(IPublishingSet).requestDeletion(
63 [self], removed_by, removal_comment)
64
65+ def hasRestrictedFiles(self):
66+ """See ISourcePackagePublishingHistory."""
67+ for source_file in self.sourcepackagerelease.files:
68+ if source_file.libraryfile.restricted:
69+ return True
70+
71+ for binary in self.getBuiltBinaries():
72+ for binary_file in binary.binarypackagerelease.files:
73+ if binary_file.libraryfile.restricted:
74+ return True
75+
76+ return False
77+
78
79 @implementer(IBinaryPackagePublishingHistory)
80 class BinaryPackagePublishingHistory(SQLBase, ArchivePublisherBase):
81diff --git a/lib/lp/soyuz/scripts/packagecopier.py b/lib/lp/soyuz/scripts/packagecopier.py
82index 2e4a767..b8293e3 100644
83--- a/lib/lp/soyuz/scripts/packagecopier.py
84+++ b/lib/lp/soyuz/scripts/packagecopier.py
85@@ -111,21 +111,6 @@ def update_files_privacy(pub_record):
86 return changed_files
87
88
89-# XXX cprov 2009-07-01: should be part of `ISourcePackagePublishingHistory`.
90-def has_restricted_files(source):
91- """Whether or not a given source files has restricted files."""
92- for source_file in source.sourcepackagerelease.files:
93- if source_file.libraryfile.restricted:
94- return True
95-
96- for binary in source.getBuiltBinaries():
97- for binary_file in binary.binarypackagerelease.files:
98- if binary_file.libraryfile.restricted:
99- return True
100-
101- return False
102-
103-
104 @delegate_to(ISourcePackagePublishingHistory)
105 class CheckedCopy:
106 """Representation of a copy that was checked and approved.
107@@ -508,7 +493,7 @@ class CopyChecker:
108 (ancestry.displayname, ancestry.distroseries.name))
109
110 requires_unembargo = (
111- not self.archive.private and has_restricted_files(source))
112+ not self.archive.private and source.hasRestrictedFiles())
113
114 if requires_unembargo and not self.unembargo:
115 raise CannotCopy(
116@@ -663,7 +648,7 @@ def do_copy(sources, archive, series, pocket, include_binaries=False,
117 announce_from_person=announce_from_person,
118 previous_version=old_version, logger=logger)
119 mailer.sendAll()
120- if not archive.private and has_restricted_files(source):
121+ if not archive.private and source.hasRestrictedFiles():
122 # Fix copies by unrestricting files with privacy mismatch.
123 # We must do this *after* calling mailer.sendAll (which only
124 # actually sends mail on commit), because otherwise the new

Subscribers

People subscribed via source and target branches

to status/vote changes: