Merge lp:~abentley/launchpad/specification-policy into lp:launchpad

Proposed by Aaron Bentley on 2012-10-10
Status: Merged
Approved by: Aaron Bentley on 2012-10-10
Approved revision: no longer in the source branch.
Merged at revision: 16127
Proposed branch: lp:~abentley/launchpad/specification-policy
Merge into: lp:launchpad
Diff against target: 176 lines (+45/-16)
7 files modified
lib/lp/blueprints/browser/tests/test_specification.py (+0/-4)
lib/lp/blueprints/model/specification.py (+1/-0)
lib/lp/registry/model/product.py (+7/-2)
lib/lp/registry/services/tests/test_sharingservice.py (+4/-5)
lib/lp/registry/tests/test_product.py (+25/-1)
lib/lp/registry/tests/test_sharingjob.py (+0/-2)
lib/lp/testing/factory.py (+8/-2)
To merge this branch: bzr merge lp:~abentley/launchpad/specification-policy
Reviewer Review Type Date Requested Status
Richard Harding (community) 2012-10-10 Approve on 2012-10-10
Review via email: mp+128998@code.launchpad.net

Commit Message

Specification sharing policy creates information types.

Description of the Change

= Summary =
Fix bug #1061621: Setting specification policy to "proprietary" does not add "proprietary" to sharing table

== Proposed fix ==
Update pruneUnusedPolicies to consider specification sharing policy.

== Pre-implementation notes ==
None

== LOC Rationale ==
Part of private projects.

== Implementation details ==
There were already shared tests for policies. I included Specifications sharing policies in those tests and fixed the failures. This required adding SpecificationSharingPolicy.FORBIDDEN to SPECIFICATION_POLICY_ALLOWED_TYPES

Various tests assumed that policies would not be created, and were adjusted to assume they would.

== Tests ==
bin/test -t ProductSpecificationSharingPolicyTestCase -t test_specification -t test_sharingservice

== Demo and Q/A ==
Create a product with an open source license, then change the license to other/proprietary (so that the branch, bug, specification policies are PUBLIC).

View +sharing. "Proprietary" will not be listed under "Who it's shared with".

Change the specification policy to proprietary. "Proprietary" will be listed under "Who it's shared with".

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/registry/services/tests/test_sharingservice.py
  lib/lp/testing/factory.py
  lib/lp/blueprints/model/specification.py
  lib/lp/registry/model/product.py
  lib/lp/blueprints/browser/tests/test_specification.py
  lib/lp/registry/tests/test_product.py

To post a comment you must log in.
Richard Harding (rharding) wrote :

Thanks for the update Aaron. I think I follow along.

The comment in #49 implies there's some filtering after the fact around bug/branch policies. I just bring it up to verify there's nothing there to be added for the additional specification policy code.

Edit: never mind, but can you update the comment to also note specification types to reflect the update.

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/browser/tests/test_specification.py'
2--- lib/lp/blueprints/browser/tests/test_specification.py 2012-10-08 10:07:11 +0000
3+++ lib/lp/blueprints/browser/tests/test_specification.py 2012-10-10 19:20:29 +0000
4@@ -460,9 +460,6 @@
5 if sharing_policy is not None:
6 self.factory.makeCommercialSubscription(product)
7 product.setSpecificationSharingPolicy(sharing_policy)
8- policy = self.factory.makeAccessPolicy(product, information_type)
9- self.factory.makeAccessPolicyGrant(
10- policy, grantee=self.user, grantor=self.user)
11 browser = self.getViewBrowser(product, view_name='+addspec')
12 control = browser.getControl(information_type.title)
13 if not control.selected:
14@@ -619,7 +616,6 @@
15 self.assertEqual(spec.information_type, InformationType.EMBARGOED)
16
17
18-
19 class TestNewSpecificationDefaultInformationTypeProduct(
20 BrowserTestCase, BaseNewSpecificationInformationTypeDefaultMixin):
21
22
23=== modified file 'lib/lp/blueprints/model/specification.py'
24--- lib/lp/blueprints/model/specification.py 2012-10-03 13:05:31 +0000
25+++ lib/lp/blueprints/model/specification.py 2012-10-10 19:20:29 +0000
26@@ -143,6 +143,7 @@
27 SpecificationSharingPolicy.PROPRIETARY: [InformationType.PROPRIETARY],
28 SpecificationSharingPolicy.EMBARGOED_OR_PROPRIETARY:
29 [InformationType.PROPRIETARY, InformationType.EMBARGOED],
30+ SpecificationSharingPolicy.FORBIDDEN: [],
31 }
32
33 SPECIFICATION_POLICY_DEFAULT_TYPES = {
34
35=== modified file 'lib/lp/registry/model/product.py'
36--- lib/lp/registry/model/product.py 2012-10-09 13:25:28 +0000
37+++ lib/lp/registry/model/product.py 2012-10-10 19:20:29 +0000
38@@ -731,10 +731,15 @@
39 allowed_branch_types = set(
40 BRANCH_POLICY_ALLOWED_TYPES.get(
41 self.branch_sharing_policy, FREE_INFORMATION_TYPES))
42+ allowed_specification_types = set(
43+ SPECIFICATION_POLICY_ALLOWED_TYPES.get(
44+ self.specification_sharing_policy, [InformationType.PUBLIC])
45+ )
46 allowed_types = allowed_bug_types.union(allowed_branch_types)
47+ allowed_types = allowed_types.union(allowed_specification_types)
48 # Fetch all APs, and after filtering out ones that are forbidden
49- # by the bug and branch policies, the APs that have no APAs are
50- # unused and can be deleted.
51+ # by the bug, branch, and specification policies, the APs that have no
52+ # APAs are unused and can be deleted.
53 ap_source = getUtility(IAccessPolicySource)
54 access_policies = set(ap_source.findByPillar([self]))
55 apa_source = getUtility(IAccessPolicyArtifactSource)
56
57=== modified file 'lib/lp/registry/services/tests/test_sharingservice.py'
58--- lib/lp/registry/services/tests/test_sharingservice.py 2012-10-10 02:45:36 +0000
59+++ lib/lp/registry/services/tests/test_sharingservice.py 2012-10-10 19:20:29 +0000
60@@ -892,7 +892,8 @@
61 artifacts.extend(branches)
62 if specifications:
63 artifacts.extend(specifications)
64- policy = self.factory.makeAccessPolicy(pillar=pillar)
65+ policy = self.factory.makeAccessPolicy(pillar=pillar,
66+ check_existing=True)
67 # Grant access to a grantee and another person.
68 grantee = self.factory.makePerson()
69 someone = self.factory.makePerson()
70@@ -981,8 +982,6 @@
71 product = self.factory.makeProduct(
72 owner=owner, specification_sharing_policy=(
73 SpecificationSharingPolicy.EMBARGOED_OR_PROPRIETARY))
74- self.factory.makeAccessPolicy(
75- pillar=product, type=InformationType.EMBARGOED)
76 login_person(owner)
77 specification = self.factory.makeSpecification(
78 product=product, owner=owner,
79@@ -998,7 +997,8 @@
80 artifacts.extend(branches)
81 if specifications:
82 artifacts.extend(specifications)
83- policy = self.factory.makeAccessPolicy(pillar=pillar)
84+ policy = self.factory.makeAccessPolicy(pillar=pillar,
85+ check_existing=True)
86
87 person_grantee = self.factory.makePerson()
88 team_owner = self.factory.makePerson()
89@@ -1089,7 +1089,6 @@
90 product = self.factory.makeProduct(
91 owner=owner, specification_sharing_policy=(
92 SpecificationSharingPolicy.EMBARGOED_OR_PROPRIETARY))
93- self.factory.makeAccessPolicy(product, InformationType.EMBARGOED)
94 login_person(owner)
95 specification = self.factory.makeSpecification(
96 product=product, owner=owner,
97
98=== modified file 'lib/lp/registry/tests/test_product.py'
99--- lib/lp/registry/tests/test_product.py 2012-10-10 12:18:43 +0000
100+++ lib/lp/registry/tests/test_product.py 2012-10-10 19:20:29 +0000
101@@ -1212,7 +1212,7 @@
102 [policy.type for policy in
103 getUtility(IAccessPolicySource).findByPillar([self.product])])
104 self.setSharingPolicy(
105- BranchSharingPolicy.EMBARGOED_OR_PROPRIETARY,
106+ self.enum.EMBARGOED_OR_PROPRIETARY,
107 self.commercial_admin)
108 self.assertEqual(
109 [InformationType.PRIVATESECURITY, InformationType.USERDATA,
110@@ -1229,6 +1229,30 @@
111 self.product.owner))
112
113
114+class ProductSpecificationSharingPolicyTestCase(
115+ ProductBranchSharingPolicyTestCase):
116+ """Test Product.specification_sharing_policy."""
117+
118+ layer = DatabaseFunctionalLayer
119+
120+ enum = SpecificationSharingPolicy
121+ public_policy = SpecificationSharingPolicy.PUBLIC
122+ commercial_policies = (
123+ SpecificationSharingPolicy.PUBLIC_OR_PROPRIETARY,
124+ SpecificationSharingPolicy.PROPRIETARY_OR_PUBLIC,
125+ SpecificationSharingPolicy.PROPRIETARY,
126+ SpecificationSharingPolicy.EMBARGOED_OR_PROPRIETARY,
127+ )
128+
129+ def setSharingPolicy(self, policy, user):
130+ with person_logged_in(user):
131+ result = self.product.setSpecificationSharingPolicy(policy)
132+ return result
133+
134+ def getSharingPolicy(self):
135+ return self.product.specification_sharing_policy
136+
137+
138 class ProductSnapshotTestCase(TestCaseWithFactory):
139 """Test product snapshots.
140
141
142=== modified file 'lib/lp/registry/tests/test_sharingjob.py'
143--- lib/lp/registry/tests/test_sharingjob.py 2012-09-24 14:08:00 +0000
144+++ lib/lp/registry/tests/test_sharingjob.py 2012-10-10 19:20:29 +0000
145@@ -286,8 +286,6 @@
146 product = self.factory.makeProduct(
147 specification_sharing_policy=(
148 SpecificationSharingPolicy.EMBARGOED_OR_PROPRIETARY))
149- self.factory.makeAccessPolicy(product, InformationType.PROPRIETARY)
150- self.factory.makeAccessPolicy(product, InformationType.EMBARGOED)
151 owner = self.factory.makePerson()
152 [policy] = getUtility(IAccessPolicySource).find(
153 [(product, InformationType.USERDATA)])
154
155=== modified file 'lib/lp/testing/factory.py'
156--- lib/lp/testing/factory.py 2012-10-08 10:07:11 +0000
157+++ lib/lp/testing/factory.py 2012-10-10 19:20:29 +0000
158@@ -4217,10 +4217,16 @@
159 package_version=package_version, requester=requester)
160
161 def makeAccessPolicy(self, pillar=None,
162- type=InformationType.PROPRIETARY):
163+ type=InformationType.PROPRIETARY,
164+ check_existing=False):
165 if pillar is None:
166 pillar = self.makeProduct()
167- policies = getUtility(IAccessPolicySource).create([(pillar, type)])
168+ policy_source = getUtility(IAccessPolicySource)
169+ if check_existing:
170+ policy = policy_source.find([(pillar, type)]).one()
171+ if policy is not None:
172+ return policy
173+ policies = policy_source.create([(pillar, type)])
174 return policies[0]
175
176 def makeAccessArtifact(self, concrete=None):