Merge lp:~deryck/launchpad/use-specification-sharing-policy into lp:launchpad

Proposed by Deryck Hodge on 2012-09-13
Status: Merged
Approved by: j.c.sackett on 2012-09-13
Approved revision: no longer in the source branch.
Merged at revision: 15964
Proposed branch: lp:~deryck/launchpad/use-specification-sharing-policy
Merge into: lp:launchpad
Prerequisite: lp:~deryck/launchpad/specification-sharing-policy-unused
Diff against target: 329 lines (+182/-4)
8 files modified
lib/lp/blueprints/interfaces/specificationtarget.py (+4/-1)
lib/lp/blueprints/model/specification.py (+12/-0)
lib/lp/registry/model/distribution.py (+4/-0)
lib/lp/registry/model/product.py (+12/-2)
lib/lp/registry/tests/test_distribution.py (+16/-0)
lib/lp/registry/tests/test_product.py (+81/-0)
lib/lp/scripts/garbo.py (+33/-1)
lib/lp/scripts/tests/test_garbo.py (+20/-0)
To merge this branch: bzr merge lp:~deryck/launchpad/use-specification-sharing-policy
Reviewer Review Type Date Requested Status
j.c.sackett (community) 2012-09-13 Approve on 2012-09-13
Review via email: mp+124240@code.launchpad.net

Commit Message

Get Product.getAllowedSpecificationInformationTypes and Product.getDefaultSpecificationInformationType working to start making use of SpecificationSharingPolicy for products.

Description of the Change

To start making use of SpecificationSharingPolicy, this branch updates or adds the methods getAllowedSpecificationInformationTypes and getDefaultSpecificationInformationType. This is largely a branch that adds tests and fixes these methods on Product. All we really care about for Specifications is Products, but I also updated the methods on Distribution to return Public for those objects.

To get this working, I needed to add SPECIFICATION_POLICY_DEFAULT_TYPES to make sure the defaults were correct. Also, there is no QA for this since it's just tests and model changes. We're also lint free. The LOC count is justified since this is for the disclosure project which already has approval for LOC increase.

To post a comment you must log in.
j.c.sackett (jcsackett) wrote :

This looks fine. Thanks, Deryck.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/blueprints/interfaces/specificationtarget.py'
2--- lib/lp/blueprints/interfaces/specificationtarget.py 2012-09-07 19:40:53 +0000
3+++ lib/lp/blueprints/interfaces/specificationtarget.py 2012-09-13 18:00:38 +0000
4@@ -111,7 +111,10 @@
5 """
6
7 def getAllowedSpecificationInformationTypes():
8- """Get the InformationTypes for this targets' specifications."""
9+ """Get the InformationTypes for this target's specifications."""
10+
11+ def getDefaultSpecificationInformationType():
12+ """Get the default InformationType for the target's specifications."""
13
14
15 class ISpecificationGoal(ISpecificationTarget):
16
17=== modified file 'lib/lp/blueprints/model/specification.py'
18--- lib/lp/blueprints/model/specification.py 2012-09-13 18:00:38 +0000
19+++ lib/lp/blueprints/model/specification.py 2012-09-13 18:00:38 +0000
20@@ -10,6 +10,7 @@
21 'recursive_dependent_query',
22 'Specification',
23 'SPECIFICATION_POLICY_ALLOWED_TYPES',
24+ 'SPECIFICATION_POLICY_DEFAULT_TYPES',
25 'SpecificationSet',
26 ]
27
28@@ -140,6 +141,17 @@
29 [InformationType.PROPRIETARY, InformationType.EMBARGOED],
30 }
31
32+SPECIFICATION_POLICY_DEFAULT_TYPES = {
33+ SpecificationSharingPolicy.PUBLIC: InformationType.PUBLIC,
34+ SpecificationSharingPolicy.PUBLIC_OR_PROPRIETARY: (
35+ InformationType.PUBLIC),
36+ SpecificationSharingPolicy.PROPRIETARY_OR_PUBLIC: (
37+ InformationType.PROPRIETARY),
38+ SpecificationSharingPolicy.PROPRIETARY: InformationType.PROPRIETARY,
39+ SpecificationSharingPolicy.EMBARGOED_OR_PROPRIETARY: (
40+ InformationType.EMBARGOED),
41+ }
42+
43
44 class Specification(SQLBase, BugLinkTargetMixin):
45 """See ISpecification."""
46
47=== modified file 'lib/lp/registry/model/distribution.py'
48--- lib/lp/registry/model/distribution.py 2012-09-11 19:14:06 +0000
49+++ lib/lp/registry/model/distribution.py 2012-09-13 18:00:38 +0000
50@@ -979,6 +979,10 @@
51 """See `ISpecificationTarget`."""
52 return (InformationType.PUBLIC,)
53
54+ def getDefaultSpecificationInformationType(self):
55+ """See `ISpecificationTarget`."""
56+ return InformationType.PUBLIC
57+
58 def searchQuestions(self, search_text=None,
59 status=QUESTION_STATUS_DEFAULT_SEARCH,
60 language=None, sort=None, owner=None,
61
62=== modified file 'lib/lp/registry/model/product.py'
63--- lib/lp/registry/model/product.py 2012-09-13 18:00:38 +0000
64+++ lib/lp/registry/model/product.py 2012-09-13 18:00:38 +0000
65@@ -87,6 +87,7 @@
66 HasSpecificationsMixin,
67 Specification,
68 SPECIFICATION_POLICY_ALLOWED_TYPES,
69+ SPECIFICATION_POLICY_DEFAULT_TYPES,
70 )
71 from lp.blueprints.model.sprint import HasSprintsMixin
72 from lp.bugs.interfaces.bugsummary import IBugSummaryDimension
73@@ -124,7 +125,6 @@
74 InformationType,
75 PRIVATE_INFORMATION_TYPES,
76 SpecificationSharingPolicy,
77- PUBLIC_PROPRIETARY_INFORMATION_TYPES,
78 )
79 from lp.registry.errors import CommercialSubscribersOnly
80 from lp.registry.interfaces.accesspolicy import (
81@@ -629,7 +629,17 @@
82
83 def getAllowedSpecificationInformationTypes(self):
84 """See `ISpecificationTarget`."""
85- return PUBLIC_PROPRIETARY_INFORMATION_TYPES
86+ if self.specification_sharing_policy is not None:
87+ return SPECIFICATION_POLICY_ALLOWED_TYPES[
88+ self.specification_sharing_policy]
89+ return [InformationType.PUBLIC]
90+
91+ def getDefaultSpecificationInformationType(self):
92+ """See `ISpecificationTarget`."""
93+ if self.specification_sharing_policy is not None:
94+ return SPECIFICATION_POLICY_DEFAULT_TYPES[
95+ self.specification_sharing_policy]
96+ return InformationType.PUBLIC
97
98 def _ensurePolicies(self, information_types):
99 # Ensure that the product has access policies for the specified
100
101=== modified file 'lib/lp/registry/tests/test_distribution.py'
102--- lib/lp/registry/tests/test_distribution.py 2012-09-05 06:48:36 +0000
103+++ lib/lp/registry/tests/test_distribution.py 2012-09-13 18:00:38 +0000
104@@ -286,6 +286,22 @@
105 InformationType.PUBLIC,
106 self.factory.makeDistribution().getDefaultBugInformationType())
107
108+ def test_getAllowedSpecificationInformationTypes(self):
109+ # All distros currently support only public specifications.
110+ distro = self.factory.makeDistribution()
111+ self.assertContentEqual(
112+ [InformationType.PUBLIC],
113+ distro.getAllowedSpecificationInformationTypes()
114+ )
115+
116+ def test_getDefaultSpecificationInformtationType(self):
117+ # All distros currently support only Public by default
118+ # specifications.
119+ distro = self.factory.makeDistribution()
120+ self.assertEqual(
121+ InformationType.PUBLIC,
122+ distro.getDefaultSpecificationInformationType())
123+
124
125 class TestDistributionCurrentSourceReleases(
126 CurrentSourceReleasesMixin, TestCase):
127
128=== modified file 'lib/lp/registry/tests/test_product.py'
129--- lib/lp/registry/tests/test_product.py 2012-09-03 01:35:58 +0000
130+++ lib/lp/registry/tests/test_product.py 2012-09-13 18:00:38 +0000
131@@ -34,6 +34,7 @@
132 FREE_INFORMATION_TYPES,
133 INCLUSIVE_TEAM_POLICY,
134 InformationType,
135+ SpecificationSharingPolicy,
136 )
137 from lp.registry.errors import (
138 CommercialSubscribersOnly,
139@@ -459,6 +460,86 @@
140 product.getDefaultBugInformationType())
141
142
143+class TestProductSpecificationPolicyAndInformationTypes(TestCaseWithFactory):
144+
145+ layer = DatabaseFunctionalLayer
146+
147+ def makeProductWithPolicy(self, specification_sharing_policy):
148+ product = self.factory.makeProduct()
149+ self.factory.makeCommercialSubscription(product=product)
150+ with person_logged_in(product.owner):
151+ product.setSpecificationSharingPolicy(
152+ specification_sharing_policy)
153+ return product
154+
155+ def test_no_policy(self):
156+ # Projects that have not specified a policy can use the PUBLIC
157+ # information type.
158+ product = self.factory.makeProduct()
159+ self.assertContentEqual(
160+ [InformationType.PUBLIC],
161+ product.getAllowedSpecificationInformationTypes())
162+ self.assertEqual(
163+ InformationType.PUBLIC,
164+ product.getDefaultSpecificationInformationType())
165+
166+ def test_sharing_policy_public(self):
167+ # Projects with a purely public policy should use PUBLIC
168+ # information type.
169+ product = self.makeProductWithPolicy(
170+ SpecificationSharingPolicy.PUBLIC)
171+ self.assertContentEqual(
172+ [InformationType.PUBLIC],
173+ product.getAllowedSpecificationInformationTypes())
174+ self.assertEqual(
175+ InformationType.PUBLIC,
176+ product.getDefaultSpecificationInformationType())
177+
178+ def test_sharing_policy_public_or_proprietary(self):
179+ # specification_sharing_policy can enable Proprietary.
180+ product = self.makeProductWithPolicy(
181+ SpecificationSharingPolicy.PUBLIC_OR_PROPRIETARY)
182+ self.assertContentEqual(
183+ [InformationType.PUBLIC, InformationType.PROPRIETARY],
184+ product.getAllowedSpecificationInformationTypes())
185+ self.assertEqual(
186+ InformationType.PUBLIC,
187+ product.getDefaultSpecificationInformationType())
188+
189+ def test_sharing_policy_proprietary_or_public(self):
190+ # specification_sharing_policy can enable and default to Proprietary.
191+ product = self.makeProductWithPolicy(
192+ SpecificationSharingPolicy.PROPRIETARY_OR_PUBLIC)
193+ self.assertContentEqual(
194+ [InformationType.PUBLIC, InformationType.PROPRIETARY],
195+ product.getAllowedSpecificationInformationTypes())
196+ self.assertEqual(
197+ InformationType.PROPRIETARY,
198+ product.getDefaultSpecificationInformationType())
199+
200+ def test_sharing_policy_proprietary(self):
201+ # specification_sharing_policy can enable only Proprietary.
202+ product = self.makeProductWithPolicy(
203+ SpecificationSharingPolicy.PROPRIETARY)
204+ self.assertContentEqual(
205+ [InformationType.PROPRIETARY],
206+ product.getAllowedSpecificationInformationTypes())
207+ self.assertEqual(
208+ InformationType.PROPRIETARY,
209+ product.getDefaultSpecificationInformationType())
210+
211+ def test_sharing_policy_embargoed_or_proprietary(self):
212+ # specification_sharing_policy can be embargoed and then proprietary.
213+ product = self.makeProductWithPolicy(
214+ SpecificationSharingPolicy.EMBARGOED_OR_PROPRIETARY)
215+ self.assertContentEqual(
216+ [InformationType.PROPRIETARY, InformationType.EMBARGOED],
217+ product.getAllowedSpecificationInformationTypes())
218+ self.assertEqual(
219+ InformationType.EMBARGOED,
220+ product.getDefaultSpecificationInformationType())
221+
222+
223 class ProductPermissionTestCase(TestCaseWithFactory):
224
225 layer = DatabaseFunctionalLayer
226
227=== modified file 'lib/lp/scripts/garbo.py'
228--- lib/lp/scripts/garbo.py 2012-09-03 06:41:06 +0000
229+++ lib/lp/scripts/garbo.py 2012-09-13 18:00:38 +0000
230@@ -27,7 +27,11 @@
231 import iso8601
232 from psycopg2 import IntegrityError
233 import pytz
234-from storm.expr import In
235+from storm.expr import (
236+ In,
237+ Select,
238+ Update,
239+ )
240 from storm.locals import (
241 Max,
242 Min,
243@@ -906,6 +910,33 @@
244 self._update_oldest()
245
246
247+class SpecificationSharingPolicyDefault(TunableLoop):
248+ """Set all Product.specification_sharing_policy to Public."""
249+
250+ maximum_chunk_size = 1000
251+
252+ def __init__(self, log, abort_time=None):
253+ super(SpecificationSharingPolicyDefault, self).__init__(
254+ log, abort_time)
255+ self.rows_updated = None
256+ self.store = IMasterStore(Product)
257+
258+ def isDone(self):
259+ """See `TunableLoop`."""
260+ return self.rows_updated == 0
261+
262+ def __call__(self, chunk_size):
263+ """See `TunableLoop`."""
264+ subselect = Select(
265+ Product.id, Product.specification_sharing_policy == None,
266+ limit=chunk_size)
267+ result = self.store.execute(
268+ Update({Product.specification_sharing_policy: 1},
269+ Product.id.is_in(subselect)))
270+ transaction.commit()
271+ self.rows_updated = result.rowcount
272+
273+
274 class SuggestiveTemplatesCacheUpdater(TunableLoop):
275 """Refresh the SuggestivePOTemplate cache.
276
277@@ -1300,6 +1331,7 @@
278 OldTimeLimitedTokenDeleter,
279 RevisionAuthorEmailLinker,
280 ScrubPOFileTranslator,
281+ SpecificationSharingPolicyDefault,
282 SuggestiveTemplatesCacheUpdater,
283 POTranslationPruner,
284 UnlinkedAccountPruner,
285
286=== modified file 'lib/lp/scripts/tests/test_garbo.py'
287--- lib/lp/scripts/tests/test_garbo.py 2012-09-03 06:41:06 +0000
288+++ lib/lp/scripts/tests/test_garbo.py 2012-09-13 18:00:38 +0000
289@@ -19,6 +19,7 @@
290 In,
291 Min,
292 Not,
293+ Update,
294 SQL,
295 )
296 from storm.locals import (
297@@ -58,6 +59,8 @@
298 )
299 from lp.registry.interfaces.accesspolicy import IAccessPolicySource
300 from lp.registry.interfaces.person import IPersonSet
301+from lp.registry.interfaces.product import IProductSet
302+from lp.registry.model.product import Product
303 from lp.scripts.garbo import (
304 AntiqueSessionPruner,
305 BulkPruner,
306@@ -1057,6 +1060,23 @@
307 [InformationType.PRIVATESECURITY, InformationType.PROPRIETARY],
308 self.getAccessPolicyTypes(product))
309
310+ def test_SpecificationSharingPolicyDefault(self):
311+ switch_dbuser('testadmin')
312+ # Set all existing projects to something other than None or 1.
313+ store = IMasterStore(Product)
314+ store.execute(Update(
315+ {Product.specification_sharing_policy: 2}))
316+ store.flush()
317+ # Make a new product without a specification_sharing_policy.
318+ product = self.factory.makeProduct()
319+ removeSecurityProxy(product).specification_sharing_policy = None
320+ store.flush()
321+ self.assertEqual(1, store.find(Product,
322+ Product.specification_sharing_policy == None).count())
323+ self.runDaily()
324+ self.assertEqual(0, store.find(Product,
325+ Product.specification_sharing_policy == None).count())
326+
327
328 class TestGarboTasks(TestCaseWithFactory):
329 layer = LaunchpadZopelessLayer