Merge lp:~rharding/launchpad/limit_sharing_infotype_1083761 into lp:launchpad

Proposed by Richard Harding on 2012-11-29
Status: Merged
Approved by: j.c.sackett on 2012-11-29
Approved revision: no longer in the source branch.
Merged at revision: 16327
Proposed branch: lp:~rharding/launchpad/limit_sharing_infotype_1083761
Merge into: lp:launchpad
Diff against target: 174 lines (+96/-21)
3 files modified
lib/lp/registry/model/product.py (+4/-0)
lib/lp/registry/services/sharingservice.py (+44/-17)
lib/lp/registry/services/tests/test_sharingservice.py (+48/-4)
To merge this branch: bzr merge lp:~rharding/launchpad/limit_sharing_infotype_1083761
Reviewer Review Type Date Requested Status
j.c.sackett (community) 2012-11-29 Approve on 2012-11-29
Review via email: mp+137038@code.launchpad.net

Commit Message

Limit the policy options for get(Bug|Branch|Specification)SharingPolicies based on the project information type.

Description of the Change

= Summary =

Per the bug, when a project is non-public then the sharing policies should
never show that you can change the sharing policy to something that is public.

== Pre Implementation ==

Talked with Deryck and Aaron to make sure I was understanding the policies. We
decided to add back in the embargoed and proprietary option into the UI even
though it's also part of the API.

See bug #1055617 for the reason it was originally removed, but it's no longer
an issue.

== Implementation Notes ==

To make things cleaner I added the private property that other models already
have. It makes sense to keep the api onto the products now that they have
information type as well.

Since we're allowing the display of the embargoed or proprietary I removed the
old check in the getBranchSharingPolicy method. See the bug referenced ^^.

The check is pretty simple. If it's a public product and you have a commercial
subscription you can set about any policy you want. However, if it's not
public then the only two policies that apply are proprietary and
embargoed/proprietary. We don't have a reverse policy for
proprietary/embargoed so it's not listed.

There's a new test method for each getXXXSharingPolicy and a tweak to an
existing test that changed/adjusted. Note that we had to specify the
information type because the factory will allow you to set a sharing policy of
proprietary while leaving the information type of the product as public.

This is a weakness of the factory and adding all the sanity checks to the
factory would be a bit crazy, so we just tweak the test itself.

== QA ==

Create a new public product with a proprietary license and you should get a
commercial subscription. From there, the sharing ui should allow you to select
the sharing policies available.

Create a non-public product and you should only be able to change the sharing
policies to proprietary or embargoed/proprietary from the ui.

== Tests ==

lib/lp/registry/services/tests/test_sharingservice.py

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

Looks good. Thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/model/product.py'
2--- lib/lp/registry/model/product.py 2012-11-27 13:43:33 +0000
3+++ lib/lp/registry/model/product.py 2012-11-29 20:29:22 +0000
4@@ -1786,6 +1786,10 @@
5 def people(self):
6 return getUtility(IPersonSet)
7
8+ @property
9+ def private(self):
10+ return self.information_type in PRIVATE_INFORMATION_TYPES
11+
12 @classmethod
13 def latest(cls, user, quantity=5):
14 """See `IProductSet`."""
15
16=== modified file 'lib/lp/registry/services/sharingservice.py'
17--- lib/lp/registry/services/sharingservice.py 2012-11-12 23:03:24 +0000
18+++ lib/lp/registry/services/sharingservice.py 2012-11-29 20:29:22 +0000
19@@ -439,17 +439,24 @@
20 # default to Public.
21 # If the branch sharing policy is EMBARGOED_OR_PROPRIETARY, then we
22 # do not allow any other policies.
23- allowed_policies = []
24- if (pillar.branch_sharing_policy !=
25- BranchSharingPolicy.EMBARGOED_OR_PROPRIETARY):
26- allowed_policies = [BranchSharingPolicy.PUBLIC]
27- # Commercial projects also allow proprietary branches.
28- if (IProduct.providedBy(pillar)
29- and pillar.has_current_commercial_subscription):
30- allowed_policies.extend([
31+ allowed_policies = [BranchSharingPolicy.PUBLIC]
32+ # Commercial projects also allow proprietary branches.
33+ if (IProduct.providedBy(pillar)
34+ and pillar.has_current_commercial_subscription):
35+
36+ if pillar.private:
37+ allowed_policies = [
38+ BranchSharingPolicy.EMBARGOED_OR_PROPRIETARY,
39+ BranchSharingPolicy.PROPRIETARY,
40+ ]
41+ else:
42+ allowed_policies = [
43+ BranchSharingPolicy.PUBLIC,
44 BranchSharingPolicy.PUBLIC_OR_PROPRIETARY,
45 BranchSharingPolicy.PROPRIETARY_OR_PUBLIC,
46- BranchSharingPolicy.PROPRIETARY])
47+ BranchSharingPolicy.PROPRIETARY,
48+ ]
49+
50 if (pillar.branch_sharing_policy and
51 not pillar.branch_sharing_policy in allowed_policies):
52 allowed_policies.append(pillar.branch_sharing_policy)
53@@ -464,10 +471,20 @@
54 # Commercial projects also allow proprietary bugs.
55 if (IProduct.providedBy(pillar)
56 and pillar.has_current_commercial_subscription):
57- allowed_policies.extend([
58- BugSharingPolicy.PUBLIC_OR_PROPRIETARY,
59- BugSharingPolicy.PROPRIETARY_OR_PUBLIC,
60- BugSharingPolicy.PROPRIETARY])
61+
62+ if pillar.private:
63+ allowed_policies = [
64+ BugSharingPolicy.EMBARGOED_OR_PROPRIETARY,
65+ BugSharingPolicy.PROPRIETARY,
66+ ]
67+ else:
68+ allowed_policies = [
69+ BugSharingPolicy.PUBLIC,
70+ BugSharingPolicy.PUBLIC_OR_PROPRIETARY,
71+ BugSharingPolicy.PROPRIETARY_OR_PUBLIC,
72+ BugSharingPolicy.PROPRIETARY,
73+ ]
74+
75 if (pillar.bug_sharing_policy and
76 not pillar.bug_sharing_policy in allowed_policies):
77 allowed_policies.append(pillar.bug_sharing_policy)
78@@ -482,10 +499,20 @@
79 # Commercial projects also allow proprietary specifications.
80 if (IProduct.providedBy(pillar)
81 and pillar.has_current_commercial_subscription):
82- allowed_policies.extend([
83- SpecificationSharingPolicy.PUBLIC_OR_PROPRIETARY,
84- SpecificationSharingPolicy.PROPRIETARY_OR_PUBLIC,
85- SpecificationSharingPolicy.PROPRIETARY])
86+
87+ if pillar.private:
88+ allowed_policies = [
89+ SpecificationSharingPolicy.EMBARGOED_OR_PROPRIETARY,
90+ SpecificationSharingPolicy.PROPRIETARY,
91+ ]
92+ else:
93+ allowed_policies = [
94+ SpecificationSharingPolicy.PUBLIC,
95+ SpecificationSharingPolicy.PUBLIC_OR_PROPRIETARY,
96+ SpecificationSharingPolicy.PROPRIETARY_OR_PUBLIC,
97+ SpecificationSharingPolicy.PROPRIETARY,
98+ ]
99+
100 if (pillar.specification_sharing_policy and
101 not pillar.specification_sharing_policy in allowed_policies):
102 allowed_policies.append(pillar.specification_sharing_policy)
103
104=== modified file 'lib/lp/registry/services/tests/test_sharingservice.py'
105--- lib/lp/registry/services/tests/test_sharingservice.py 2012-10-12 14:53:10 +0000
106+++ lib/lp/registry/services/tests/test_sharingservice.py 2012-11-29 20:29:22 +0000
107@@ -192,6 +192,45 @@
108 BranchSharingPolicy.PROPRIETARY_OR_PUBLIC,
109 BranchSharingPolicy.PROPRIETARY])
110
111+ def test_getBugSharingPolicies_non_public_product(self):
112+ # When the product is non-public the policy options are limited to
113+ # only proprietary or embargoed/proprietary.
114+ owner = self.factory.makePerson()
115+ product = self.factory.makeProduct(
116+ information_type=InformationType.PROPRIETARY,
117+ owner=owner,
118+ )
119+ with person_logged_in(owner):
120+ self._assert_getBugSharingPolicies(
121+ product, [BugSharingPolicy.EMBARGOED_OR_PROPRIETARY,
122+ BugSharingPolicy.PROPRIETARY])
123+
124+ def test_getBranchSharingPolicies_non_public_product(self):
125+ # When the product is non-public the policy options are limited to
126+ # only proprietary or embargoed/proprietary.
127+ owner = self.factory.makePerson()
128+ product = self.factory.makeProduct(
129+ information_type=InformationType.PROPRIETARY,
130+ owner=owner
131+ )
132+ with person_logged_in(owner):
133+ self._assert_getBranchSharingPolicies(
134+ product, [BranchSharingPolicy.EMBARGOED_OR_PROPRIETARY,
135+ BranchSharingPolicy.PROPRIETARY])
136+
137+ def test_getSpecificationSharingPolicies_non_public_product(self):
138+ # When the product is non-public the policy options are limited to
139+ # only proprietary or embargoed/proprietary.
140+ owner = self.factory.makePerson()
141+ product = self.factory.makeProduct(
142+ information_type=InformationType.PROPRIETARY,
143+ owner=owner,
144+ )
145+ with person_logged_in(owner):
146+ self._assert_getSpecificationSharingPolicies(
147+ product, [SpecificationSharingPolicy.EMBARGOED_OR_PROPRIETARY,
148+ SpecificationSharingPolicy.PROPRIETARY])
149+
150 def test_getBranchSharingPolicies_disallowed_policy(self):
151 # getBranchSharingPolicies includes a pillar's current policy even if
152 # it is nominally not allowed.
153@@ -204,12 +243,17 @@
154 [BranchSharingPolicy.PUBLIC, BranchSharingPolicy.FORBIDDEN])
155
156 def test_getBranchSharingPolicies_product_with_embargoed(self):
157- # If the current sharing policy is embargoed, that is all that is
158- # allowed.
159+ # If the current sharing policy is embargoed, it can still be made
160+ # proprietary.
161+ owner = self.factory.makePerson()
162 product = self.factory.makeProduct(
163+ information_type=InformationType.EMBARGOED,
164+ owner=owner,
165 branch_sharing_policy=BranchSharingPolicy.EMBARGOED_OR_PROPRIETARY)
166- self._assert_getBranchSharingPolicies(
167- product, [BranchSharingPolicy.EMBARGOED_OR_PROPRIETARY])
168+ with person_logged_in(owner):
169+ self._assert_getBranchSharingPolicies(
170+ product, [BranchSharingPolicy.EMBARGOED_OR_PROPRIETARY,
171+ BranchSharingPolicy.PROPRIETARY])
172
173 def test_getBranchSharingPolicies_distro(self):
174 distro = self.factory.makeDistribution()