Merge lp:~stevenk/launchpad/branch-use-information_type into lp:launchpad
- branch-use-information_type
- Merge into devel
Status: | Merged |
---|---|
Approved by: | Steve Kowalik |
Approved revision: | no longer in the source branch. |
Merged at revision: | 15289 |
Proposed branch: | lp:~stevenk/launchpad/branch-use-information_type |
Merge into: | lp:launchpad |
Diff against target: |
355 lines (+102/-34) 9 files modified
lib/lp/code/browser/tests/test_branch.py (+6/-3) lib/lp/code/browser/tests/test_branchmergeproposal.py (+2/-1) lib/lp/code/errors.py (+5/-0) lib/lp/code/model/branch.py (+32/-11) lib/lp/code/model/tests/test_branch.py (+28/-2) lib/lp/code/model/tests/test_branchmergeproposal.py (+3/-2) lib/lp/code/model/tests/test_branchvisibility.py (+4/-7) lib/lp/code/xmlrpc/tests/test_branch.py (+4/-2) lib/lp/testing/factory.py (+18/-6) |
To merge this branch: | bzr merge lp:~stevenk/launchpad/branch-use-information_type |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
William Grant | code | Approve | |
Review via email: mp+106109@code.launchpad.net |
Commit message
Switch Branch to using information_type by default.
Description of the change
Switch Branch to using information_type by default. I have also moved the code from setPrivate to transitionToInf
I have changed the factory method makeBranch to take an information_type argument, and have also made it call IBranch.
This necessitated changing a fair number of tests, which naively just set explicitly_private by hand. I've converted them to setting information_type, but am willing to make use of IBranch.
William Grant (wgrant) wrote : | # |
121 + if (self.stacked_on and self.stacked_
122 + PRIVATE_
123 + PUBLIC_
This linebreaking is still a capital offence in several jurisdictions. One legal spelling is this:
if (self.stacked on
and self.stacked_
and information_type in PUBLIC_INFORMATION TYPES):
157 + # If the branch we are stacking on is not public, and we are,
158 + # set our information_type to the stacked on's.
This comment should explain why.
159 + if (self.stacked_on and self.stacked_
160 + PUBLIC_
161 + PUBLIC_
Another capital offence.
273 + branch = self.factory.
274 + name='branch_%s' % x, private=x > 2)
That linebreak is probably no longer required.
Preview Diff
1 | === modified file 'lib/lp/code/browser/tests/test_branch.py' | |||
2 | --- lib/lp/code/browser/tests/test_branch.py 2012-05-02 05:25:11 +0000 | |||
3 | +++ lib/lp/code/browser/tests/test_branch.py 2012-05-23 05:26:23 +0000 | |||
4 | @@ -758,7 +758,8 @@ | |||
5 | 758 | # If the target is private, the landing targets should not include it. | 758 | # If the target is private, the landing targets should not include it. |
6 | 759 | bmp = self.factory.makeBranchMergeProposal() | 759 | bmp = self.factory.makeBranchMergeProposal() |
7 | 760 | branch = bmp.source_branch | 760 | branch = bmp.source_branch |
9 | 761 | removeSecurityProxy(bmp.target_branch).explicitly_private = True | 761 | removeSecurityProxy(bmp.target_branch).information_type = ( |
10 | 762 | InformationType.USERDATA) | ||
11 | 762 | view = BranchView(branch, LaunchpadTestRequest()) | 763 | view = BranchView(branch, LaunchpadTestRequest()) |
12 | 763 | self.assertTrue(view.no_merges) | 764 | self.assertTrue(view.no_merges) |
13 | 764 | self.assertEqual([], view.landing_targets) | 765 | self.assertEqual([], view.landing_targets) |
14 | @@ -779,7 +780,8 @@ | |||
15 | 779 | # it. | 780 | # it. |
16 | 780 | bmp = self.factory.makeBranchMergeProposal() | 781 | bmp = self.factory.makeBranchMergeProposal() |
17 | 781 | branch = bmp.target_branch | 782 | branch = bmp.target_branch |
19 | 782 | removeSecurityProxy(bmp.source_branch).explicitly_private = True | 783 | removeSecurityProxy(bmp.source_branch).information_type = ( |
20 | 784 | InformationType.USERDATA) | ||
21 | 783 | view = BranchView(branch, LaunchpadTestRequest()) | 785 | view = BranchView(branch, LaunchpadTestRequest()) |
22 | 784 | self.assertTrue(view.no_merges) | 786 | self.assertTrue(view.no_merges) |
23 | 785 | self.assertEqual([], view.landing_candidates) | 787 | self.assertEqual([], view.landing_candidates) |
24 | @@ -799,7 +801,8 @@ | |||
25 | 799 | # the target is private, then the dependent_branches are not shown. | 801 | # the target is private, then the dependent_branches are not shown. |
26 | 800 | branch = self.factory.makeProductBranch() | 802 | branch = self.factory.makeProductBranch() |
27 | 801 | bmp = self.factory.makeBranchMergeProposal(prerequisite_branch=branch) | 803 | bmp = self.factory.makeBranchMergeProposal(prerequisite_branch=branch) |
29 | 802 | removeSecurityProxy(bmp.source_branch).explicitly_private = True | 804 | removeSecurityProxy(bmp.source_branch).information_type = ( |
30 | 805 | InformationType.USERDATA) | ||
31 | 803 | view = BranchView(branch, LaunchpadTestRequest()) | 806 | view = BranchView(branch, LaunchpadTestRequest()) |
32 | 804 | self.assertTrue(view.no_merges) | 807 | self.assertTrue(view.no_merges) |
33 | 805 | self.assertEqual([], view.dependent_branches) | 808 | self.assertEqual([], view.dependent_branches) |
34 | 806 | 809 | ||
35 | === modified file 'lib/lp/code/browser/tests/test_branchmergeproposal.py' | |||
36 | --- lib/lp/code/browser/tests/test_branchmergeproposal.py 2012-05-02 05:25:11 +0000 | |||
37 | +++ lib/lp/code/browser/tests/test_branchmergeproposal.py 2012-05-23 05:26:23 +0000 | |||
38 | @@ -1290,7 +1290,8 @@ | |||
39 | 1290 | bmp2 = self.factory.makeBranchMergeProposal( | 1290 | bmp2 = self.factory.makeBranchMergeProposal( |
40 | 1291 | date_created=( | 1291 | date_created=( |
41 | 1292 | datetime(year=2008, month=10, day=10, tzinfo=pytz.UTC))) | 1292 | datetime(year=2008, month=10, day=10, tzinfo=pytz.UTC))) |
43 | 1293 | removeSecurityProxy(bmp2.source_branch).explicitly_private = True | 1293 | removeSecurityProxy(bmp2.source_branch).information_type = ( |
44 | 1294 | InformationType.USERDATA) | ||
45 | 1294 | self.assertEqual( | 1295 | self.assertEqual( |
46 | 1295 | [bmp1], latest_proposals_for_each_branch([bmp1, bmp2])) | 1296 | [bmp1], latest_proposals_for_each_branch([bmp1, bmp2])) |
47 | 1296 | 1297 | ||
48 | 1297 | 1298 | ||
49 | === modified file 'lib/lp/code/errors.py' | |||
50 | --- lib/lp/code/errors.py 2012-02-21 22:46:28 +0000 | |||
51 | +++ lib/lp/code/errors.py 2012-05-23 05:26:23 +0000 | |||
52 | @@ -10,6 +10,7 @@ | |||
53 | 10 | 'BadStateTransition', | 10 | 'BadStateTransition', |
54 | 11 | 'BranchCannotBePrivate', | 11 | 'BranchCannotBePrivate', |
55 | 12 | 'BranchCannotBePublic', | 12 | 'BranchCannotBePublic', |
56 | 13 | 'BranchCannotChangeInformationType', | ||
57 | 13 | 'BranchCreationException', | 14 | 'BranchCreationException', |
58 | 14 | 'BranchCreationForbidden', | 15 | 'BranchCreationForbidden', |
59 | 15 | 'BranchCreatorNotMemberOfOwnerTeam', | 16 | 'BranchCreatorNotMemberOfOwnerTeam', |
60 | @@ -155,6 +156,10 @@ | |||
61 | 155 | """The branch cannot be made private.""" | 156 | """The branch cannot be made private.""" |
62 | 156 | 157 | ||
63 | 157 | 158 | ||
64 | 159 | class BranchCannotChangeInformationType(Exception): | ||
65 | 160 | """The information type of this branch cannot be changed.""" | ||
66 | 161 | |||
67 | 162 | |||
68 | 158 | class InvalidBranchException(Exception): | 163 | class InvalidBranchException(Exception): |
69 | 159 | """Base exception for an error resolving a branch for a component. | 164 | """Base exception for an error resolving a branch for a component. |
70 | 160 | 165 | ||
71 | 161 | 166 | ||
72 | === modified file 'lib/lp/code/model/branch.py' | |||
73 | --- lib/lp/code/model/branch.py 2012-05-04 04:52:24 +0000 | |||
74 | +++ lib/lp/code/model/branch.py 2012-05-23 05:26:23 +0000 | |||
75 | @@ -77,6 +77,7 @@ | |||
76 | 77 | AlreadyLatestFormat, | 77 | AlreadyLatestFormat, |
77 | 78 | BranchCannotBePrivate, | 78 | BranchCannotBePrivate, |
78 | 79 | BranchCannotBePublic, | 79 | BranchCannotBePublic, |
79 | 80 | BranchCannotChangeInformationType, | ||
80 | 80 | BranchMergeProposalExists, | 81 | BranchMergeProposalExists, |
81 | 81 | BranchTargetError, | 82 | BranchTargetError, |
82 | 82 | BranchTypeError, | 83 | BranchTypeError, |
83 | @@ -128,7 +129,11 @@ | |||
84 | 128 | ) | 129 | ) |
85 | 129 | from lp.code.model.seriessourcepackagebranch import SeriesSourcePackageBranch | 130 | from lp.code.model.seriessourcepackagebranch import SeriesSourcePackageBranch |
86 | 130 | from lp.codehosting.safe_open import safe_open | 131 | from lp.codehosting.safe_open import safe_open |
88 | 131 | from lp.registry.enums import InformationType | 132 | from lp.registry.enums import ( |
89 | 133 | InformationType, | ||
90 | 134 | PRIVATE_INFORMATION_TYPES, | ||
91 | 135 | PUBLIC_INFORMATION_TYPES, | ||
92 | 136 | ) | ||
93 | 132 | from lp.registry.interfaces.person import ( | 137 | from lp.registry.interfaces.person import ( |
94 | 133 | validate_person, | 138 | validate_person, |
95 | 134 | validate_public_person, | 139 | validate_public_person, |
96 | @@ -187,33 +192,42 @@ | |||
97 | 187 | 192 | ||
98 | 188 | @property | 193 | @property |
99 | 189 | def private(self): | 194 | def private(self): |
101 | 190 | return self.transitively_private | 195 | return self.information_type in PRIVATE_INFORMATION_TYPES |
102 | 191 | 196 | ||
103 | 192 | def setPrivate(self, private, user): | 197 | def setPrivate(self, private, user): |
104 | 193 | """See `IBranch`.""" | 198 | """See `IBranch`.""" |
106 | 194 | if private == self.explicitly_private: | 199 | if private: |
107 | 200 | information_type = InformationType.USERDATA | ||
108 | 201 | else: | ||
109 | 202 | information_type = InformationType.PUBLIC | ||
110 | 203 | return self.transitionToInformationType(information_type, user) | ||
111 | 204 | |||
112 | 205 | def transitionToInformationType(self, information_type, who): | ||
113 | 206 | """See `IBranch`.""" | ||
114 | 207 | if self.information_type == information_type: | ||
115 | 195 | return | 208 | return |
116 | 209 | if (self.stacked_on | ||
117 | 210 | and self.stacked_on.information_type in PRIVATE_INFORMATION_TYPES | ||
118 | 211 | and information_type in PUBLIC_INFORMATION_TYPES): | ||
119 | 212 | raise BranchCannotChangeInformationType() | ||
120 | 213 | private = information_type in PRIVATE_INFORMATION_TYPES | ||
121 | 196 | # Only check the privacy policy if the user is not special. | 214 | # Only check the privacy policy if the user is not special. |
123 | 197 | if (not user_has_special_branch_access(user)): | 215 | if (not user_has_special_branch_access(who)): |
124 | 198 | policy = IBranchNamespacePolicy(self.namespace) | 216 | policy = IBranchNamespacePolicy(self.namespace) |
125 | 199 | 217 | ||
126 | 200 | if private and not policy.canBranchesBePrivate(): | 218 | if private and not policy.canBranchesBePrivate(): |
127 | 201 | raise BranchCannotBePrivate() | 219 | raise BranchCannotBePrivate() |
128 | 202 | if not private and not policy.canBranchesBePublic(): | 220 | if not private and not policy.canBranchesBePublic(): |
129 | 203 | raise BranchCannotBePublic() | 221 | raise BranchCannotBePublic() |
130 | 222 | self.information_type = information_type | ||
131 | 223 | # Set the legacy values for now. | ||
132 | 204 | self.explicitly_private = private | 224 | self.explicitly_private = private |
133 | 205 | # If this branch is private, then it is also transitively_private | 225 | # If this branch is private, then it is also transitively_private |
134 | 206 | # otherwise we need to reload the value. | 226 | # otherwise we need to reload the value. |
135 | 207 | if private: | 227 | if private: |
136 | 208 | self.transitively_private = True | 228 | self.transitively_private = True |
137 | 209 | self.information_type = InformationType.USERDATA | ||
138 | 210 | else: | 229 | else: |
139 | 211 | self.transitively_private = AutoReload | 230 | self.transitively_private = AutoReload |
140 | 212 | self.information_type = InformationType.PUBLIC | ||
141 | 213 | |||
142 | 214 | def transitionToInformationType(self, information_type, who): | ||
143 | 215 | """See `IBranch`.""" | ||
144 | 216 | self.information_type = information_type | ||
145 | 217 | 231 | ||
146 | 218 | registrant = ForeignKey( | 232 | registrant = ForeignKey( |
147 | 219 | dbName='registrant', foreignKey='Person', | 233 | dbName='registrant', foreignKey='Person', |
148 | @@ -1052,6 +1066,13 @@ | |||
149 | 1052 | self.mirror_status_message = ( | 1066 | self.mirror_status_message = ( |
150 | 1053 | 'Invalid stacked on location: ' + stacked_on_url) | 1067 | 'Invalid stacked on location: ' + stacked_on_url) |
151 | 1054 | self.stacked_on = stacked_on_branch | 1068 | self.stacked_on = stacked_on_branch |
152 | 1069 | # If the branch we are stacking on is not public, and we are, | ||
153 | 1070 | # set our information_type to the stacked on's, since having a | ||
154 | 1071 | # public branch stacked on a private branch does not make sense. | ||
155 | 1072 | if (self.stacked_on | ||
156 | 1073 | and self.stacked_on.information_type in PRIVATE_INFORMATION_TYPES | ||
157 | 1074 | and self.information_type in PUBLIC_INFORMATION_TYPES): | ||
158 | 1075 | self.information_type = self.stacked_on.information_type | ||
159 | 1055 | if self.branch_type == BranchType.HOSTED: | 1076 | if self.branch_type == BranchType.HOSTED: |
160 | 1056 | self.last_mirrored = UTC_NOW | 1077 | self.last_mirrored = UTC_NOW |
161 | 1057 | else: | 1078 | else: |
162 | @@ -1207,7 +1228,7 @@ | |||
163 | 1207 | This method doesn't check the stacked upon branch. That is handled by | 1228 | This method doesn't check the stacked upon branch. That is handled by |
164 | 1208 | the `visibleByUser` method. | 1229 | the `visibleByUser` method. |
165 | 1209 | """ | 1230 | """ |
167 | 1210 | if not self.explicitly_private: | 1231 | if self.information_type not in PRIVATE_INFORMATION_TYPES: |
168 | 1211 | return True | 1232 | return True |
169 | 1212 | if user is None: | 1233 | if user is None: |
170 | 1213 | return False | 1234 | return False |
171 | 1214 | 1235 | ||
172 | === modified file 'lib/lp/code/model/tests/test_branch.py' | |||
173 | --- lib/lp/code/model/tests/test_branch.py 2012-05-04 04:52:24 +0000 | |||
174 | +++ lib/lp/code/model/tests/test_branch.py 2012-05-23 05:26:23 +0000 | |||
175 | @@ -56,6 +56,7 @@ | |||
176 | 56 | AlreadyLatestFormat, | 56 | AlreadyLatestFormat, |
177 | 57 | BranchCannotBePrivate, | 57 | BranchCannotBePrivate, |
178 | 58 | BranchCannotBePublic, | 58 | BranchCannotBePublic, |
179 | 59 | BranchCannotChangeInformationType, | ||
180 | 59 | BranchCreatorNotMemberOfOwnerTeam, | 60 | BranchCreatorNotMemberOfOwnerTeam, |
181 | 60 | BranchCreatorNotOwner, | 61 | BranchCreatorNotOwner, |
182 | 61 | BranchTargetError, | 62 | BranchTargetError, |
183 | @@ -2334,16 +2335,21 @@ | |||
184 | 2334 | def test_public_stacked_on_private_is_private(self): | 2335 | def test_public_stacked_on_private_is_private(self): |
185 | 2335 | # A public branch stacked on a private branch is private. | 2336 | # A public branch stacked on a private branch is private. |
186 | 2336 | stacked_on = self.factory.makeBranch(private=True) | 2337 | stacked_on = self.factory.makeBranch(private=True) |
188 | 2337 | branch = self.factory.makeBranch(stacked_on=stacked_on, private=False) | 2338 | branch = self.factory.makeBranch( |
189 | 2339 | stacked_on=stacked_on, private=False) | ||
190 | 2338 | self.assertTrue(branch.private) | 2340 | self.assertTrue(branch.private) |
191 | 2341 | self.assertEqual( | ||
192 | 2342 | stacked_on.information_type, branch.information_type) | ||
193 | 2339 | self.assertTrue(removeSecurityProxy(branch).transitively_private) | 2343 | self.assertTrue(removeSecurityProxy(branch).transitively_private) |
194 | 2340 | self.assertFalse(branch.explicitly_private) | 2344 | self.assertFalse(branch.explicitly_private) |
195 | 2341 | 2345 | ||
196 | 2342 | def test_private_stacked_on_public_is_private(self): | 2346 | def test_private_stacked_on_public_is_private(self): |
198 | 2343 | # A public branch stacked on a private branch is private. | 2347 | # A private branch stacked on a public branch is private. |
199 | 2344 | stacked_on = self.factory.makeBranch(private=False) | 2348 | stacked_on = self.factory.makeBranch(private=False) |
200 | 2345 | branch = self.factory.makeBranch(stacked_on=stacked_on, private=True) | 2349 | branch = self.factory.makeBranch(stacked_on=stacked_on, private=True) |
201 | 2346 | self.assertTrue(branch.private) | 2350 | self.assertTrue(branch.private) |
202 | 2351 | self.assertNotEqual( | ||
203 | 2352 | stacked_on.information_type, branch.information_type) | ||
204 | 2347 | self.assertTrue(removeSecurityProxy(branch).transitively_private) | 2353 | self.assertTrue(removeSecurityProxy(branch).transitively_private) |
205 | 2348 | self.assertTrue(branch.explicitly_private) | 2354 | self.assertTrue(branch.explicitly_private) |
206 | 2349 | 2355 | ||
207 | @@ -2436,6 +2442,26 @@ | |||
208 | 2436 | branch.setPrivate, | 2442 | branch.setPrivate, |
209 | 2437 | False, branch.owner) | 2443 | False, branch.owner) |
210 | 2438 | 2444 | ||
211 | 2445 | def test_cannot_transition_with_private_stacked_on(self): | ||
212 | 2446 | # If a public branch is stacked on a private branch, it can not | ||
213 | 2447 | # change its information_type to public. | ||
214 | 2448 | stacked_on = self.factory.makeBranch(private=True) | ||
215 | 2449 | branch = self.factory.makeBranch(stacked_on=stacked_on) | ||
216 | 2450 | self.assertRaises( | ||
217 | 2451 | BranchCannotChangeInformationType, | ||
218 | 2452 | branch.transitionToInformationType, InformationType.PUBLIC, | ||
219 | 2453 | branch.owner) | ||
220 | 2454 | |||
221 | 2455 | def test_can_transition_with_public_stacked_on(self): | ||
222 | 2456 | # If a private branch is stacked on a public branch, it can change | ||
223 | 2457 | # its information_type. | ||
224 | 2458 | stacked_on = self.factory.makeBranch() | ||
225 | 2459 | branch = self.factory.makeBranch(stacked_on=stacked_on, private=True) | ||
226 | 2460 | branch.transitionToInformationType( | ||
227 | 2461 | InformationType.UNEMBARGOEDSECURITY, branch.owner) | ||
228 | 2462 | self.assertEqual( | ||
229 | 2463 | InformationType.UNEMBARGOEDSECURITY, branch.information_type) | ||
230 | 2464 | |||
231 | 2439 | 2465 | ||
232 | 2440 | class TestBranchCommitsForDays(TestCaseWithFactory): | 2466 | class TestBranchCommitsForDays(TestCaseWithFactory): |
233 | 2441 | """Tests for `Branch.commitsForDays`.""" | 2467 | """Tests for `Branch.commitsForDays`.""" |
234 | 2442 | 2468 | ||
235 | === modified file 'lib/lp/code/model/tests/test_branchmergeproposal.py' | |||
236 | --- lib/lp/code/model/tests/test_branchmergeproposal.py 2012-05-02 05:25:11 +0000 | |||
237 | +++ lib/lp/code/model/tests/test_branchmergeproposal.py 2012-05-23 05:26:23 +0000 | |||
238 | @@ -929,8 +929,9 @@ | |||
239 | 929 | charlie, BranchSubscriptionNotificationLevel.NOEMAIL, None, | 929 | charlie, BranchSubscriptionNotificationLevel.NOEMAIL, None, |
240 | 930 | CodeReviewNotificationLevel.FULL, charlie) | 930 | CodeReviewNotificationLevel.FULL, charlie) |
241 | 931 | # Make both branches private. | 931 | # Make both branches private. |
244 | 932 | removeSecurityProxy(bmp.source_branch).explicitly_private = True | 932 | for branch in (bmp.source_branch, bmp.target_branch): |
245 | 933 | removeSecurityProxy(bmp.target_branch).explicitly_private = True | 933 | removeSecurityProxy(branch).information_type = ( |
246 | 934 | InformationType.USERDATA) | ||
247 | 934 | recipients = bmp.getNotificationRecipients( | 935 | recipients = bmp.getNotificationRecipients( |
248 | 935 | CodeReviewNotificationLevel.FULL) | 936 | CodeReviewNotificationLevel.FULL) |
249 | 936 | self.assertFalse(bob in recipients) | 937 | self.assertFalse(bob in recipients) |
250 | 937 | 938 | ||
251 | === modified file 'lib/lp/code/model/tests/test_branchvisibility.py' | |||
252 | --- lib/lp/code/model/tests/test_branchvisibility.py 2012-01-15 17:43:05 +0000 | |||
253 | +++ lib/lp/code/model/tests/test_branchvisibility.py 2012-05-23 05:26:23 +0000 | |||
254 | @@ -1,4 +1,4 @@ | |||
256 | 1 | # Copyright 2011 Canonical Ltd. This software is licensed under the | 1 | # Copyright 2011-2012 Canonical Ltd. This software is licensed under the |
257 | 2 | # GNU Affero General Public License version 3 (see the file LICENSE). | 2 | # GNU Affero General Public License version 3 (see the file LICENSE). |
258 | 3 | 3 | ||
259 | 4 | """Tests for visibility of branches. | 4 | """Tests for visibility of branches. |
260 | @@ -134,14 +134,11 @@ | |||
261 | 134 | private_owner = self.factory.makePerson() | 134 | private_owner = self.factory.makePerson() |
262 | 135 | test_branches = [] | 135 | test_branches = [] |
263 | 136 | for x in range(5): | 136 | for x in range(5): |
268 | 137 | # We want the first 3 public and the last 3 private | 137 | # We want the first 3 public and the last 3 private. |
269 | 138 | branch = self.factory.makeBranch(name='branch_%s' % x) | 138 | branch = self.factory.makeBranch(private=x > 2) |
266 | 139 | # The 3rd, 4th and 5th will be explicitly private. | ||
267 | 140 | branch.explicitly_private = x > 2 | ||
270 | 141 | test_branches.append(branch) | 139 | test_branches.append(branch) |
271 | 142 | test_branches.append( | 140 | test_branches.append( |
274 | 143 | self.factory.makeBranch( | 141 | self.factory.makeBranch(private=True, owner=private_owner)) |
273 | 144 | name='branch_5', private=True, owner=private_owner)) | ||
275 | 145 | 142 | ||
276 | 146 | # Anonymous users see just the public branches. | 143 | # Anonymous users see just the public branches. |
277 | 147 | branch_info = [(branch, branch.private) | 144 | branch_info = [(branch, branch.private) |
278 | 148 | 145 | ||
279 | === modified file 'lib/lp/code/xmlrpc/tests/test_branch.py' | |||
280 | --- lib/lp/code/xmlrpc/tests/test_branch.py 2012-01-01 02:58:52 +0000 | |||
281 | +++ lib/lp/code/xmlrpc/tests/test_branch.py 2012-05-23 05:26:23 +0000 | |||
282 | @@ -1,4 +1,4 @@ | |||
284 | 1 | # Copyright 2009-2011 Canonical Ltd. This software is licensed under the | 1 | # Copyright 2009-2012 Canonical Ltd. This software is licensed under the |
285 | 2 | # GNU Affero General Public License version 3 (see the file LICENSE). | 2 | # GNU Affero General Public License version 3 (see the file LICENSE). |
286 | 3 | 3 | ||
287 | 4 | """Unit tests for the public codehosting API.""" | 4 | """Unit tests for the public codehosting API.""" |
288 | @@ -16,6 +16,7 @@ | |||
289 | 16 | from lp.code.interfaces.codehosting import BRANCH_ALIAS_PREFIX | 16 | from lp.code.interfaces.codehosting import BRANCH_ALIAS_PREFIX |
290 | 17 | from lp.code.interfaces.linkedbranch import ICanHasLinkedBranch | 17 | from lp.code.interfaces.linkedbranch import ICanHasLinkedBranch |
291 | 18 | from lp.code.xmlrpc.branch import PublicCodehostingAPI | 18 | from lp.code.xmlrpc.branch import PublicCodehostingAPI |
292 | 19 | from lp.registry.enums import InformationType | ||
293 | 19 | from lp.services.xmlrpc import LaunchpadFault | 20 | from lp.services.xmlrpc import LaunchpadFault |
294 | 20 | from lp.testing import ( | 21 | from lp.testing import ( |
295 | 21 | person_logged_in, | 22 | person_logged_in, |
296 | @@ -323,7 +324,8 @@ | |||
297 | 323 | def test_private_branch_as_development_focus(self): | 324 | def test_private_branch_as_development_focus(self): |
298 | 324 | # We resolve private linked branches using the writable alias. | 325 | # We resolve private linked branches using the writable alias. |
299 | 325 | product, trunk = self.makeProdutWithTrunk() | 326 | product, trunk = self.makeProdutWithTrunk() |
301 | 326 | removeSecurityProxy(trunk).explicitly_private = True | 327 | removeSecurityProxy(trunk).information_type = ( |
302 | 328 | InformationType.USERDATA) | ||
303 | 327 | self.assertOnlyWritableResolves(product.name) | 329 | self.assertOnlyWritableResolves(product.name) |
304 | 328 | 330 | ||
305 | 329 | def test_private_branch_as_user(self): | 331 | def test_private_branch_as_user(self): |
306 | 330 | 332 | ||
307 | === modified file 'lib/lp/testing/factory.py' | |||
308 | --- lib/lp/testing/factory.py 2012-05-04 14:52:44 +0000 | |||
309 | +++ lib/lp/testing/factory.py 2012-05-23 05:26:23 +0000 | |||
310 | @@ -140,6 +140,7 @@ | |||
311 | 140 | DistroSeriesDifferenceStatus, | 140 | DistroSeriesDifferenceStatus, |
312 | 141 | DistroSeriesDifferenceType, | 141 | DistroSeriesDifferenceType, |
313 | 142 | InformationType, | 142 | InformationType, |
314 | 143 | PRIVATE_INFORMATION_TYPES, | ||
315 | 143 | ) | 144 | ) |
316 | 144 | from lp.registry.interfaces.accesspolicy import ( | 145 | from lp.registry.interfaces.accesspolicy import ( |
317 | 145 | IAccessArtifactGrantSource, | 146 | IAccessArtifactGrantSource, |
318 | @@ -1072,8 +1073,8 @@ | |||
319 | 1072 | 1073 | ||
320 | 1073 | def makeBranch(self, branch_type=None, owner=None, | 1074 | def makeBranch(self, branch_type=None, owner=None, |
321 | 1074 | name=None, product=_DEFAULT, url=_DEFAULT, registrant=None, | 1075 | name=None, product=_DEFAULT, url=_DEFAULT, registrant=None, |
324 | 1075 | private=False, stacked_on=None, sourcepackage=None, | 1076 | private=None, information_type=None, stacked_on=None, |
325 | 1076 | reviewer=None, **optional_branch_args): | 1077 | sourcepackage=None, reviewer=None, **optional_branch_args): |
326 | 1077 | """Create and return a new, arbitrary Branch of the given type. | 1078 | """Create and return a new, arbitrary Branch of the given type. |
327 | 1078 | 1079 | ||
328 | 1079 | Any parameters for `IBranchNamespace.createBranch` can be specified to | 1080 | Any parameters for `IBranchNamespace.createBranch` can be specified to |
329 | @@ -1119,11 +1120,22 @@ | |||
330 | 1119 | branch = namespace.createBranch( | 1120 | branch = namespace.createBranch( |
331 | 1120 | branch_type=branch_type, name=name, registrant=registrant, | 1121 | branch_type=branch_type, name=name, registrant=registrant, |
332 | 1121 | url=url, **optional_branch_args) | 1122 | url=url, **optional_branch_args) |
336 | 1122 | if private: | 1123 | assert information_type is None or private is None, ( |
337 | 1123 | removeSecurityProxy(branch).explicitly_private = True | 1124 | "Can not specify both information_type and private") |
338 | 1124 | removeSecurityProxy(branch).transitively_private = True | 1125 | if information_type is not None or private is not None: |
339 | 1126 | if information_type: | ||
340 | 1127 | private = information_type in PRIVATE_INFORMATION_TYPES | ||
341 | 1128 | else: | ||
342 | 1129 | information_type = ( | ||
343 | 1130 | InformationType.USERDATA if private else | ||
344 | 1131 | InformationType.PUBLIC) | ||
345 | 1132 | if private: | ||
346 | 1133 | removeSecurityProxy(branch).explicitly_private = True | ||
347 | 1134 | removeSecurityProxy(branch).transitively_private = True | ||
348 | 1135 | removeSecurityProxy(branch).information_type = information_type | ||
349 | 1125 | if stacked_on is not None: | 1136 | if stacked_on is not None: |
351 | 1126 | removeSecurityProxy(branch).stacked_on = stacked_on | 1137 | removeSecurityProxy(branch).branchChanged( |
352 | 1138 | stacked_on.unique_name, 'rev1', None, None, None) | ||
353 | 1127 | if reviewer is not None: | 1139 | if reviewer is not None: |
354 | 1128 | removeSecurityProxy(branch).reviewer = reviewer | 1140 | removeSecurityProxy(branch).reviewer = reviewer |
355 | 1129 | return branch | 1141 | return branch |
32 +def convert_ to_information_ type(private) : .USERDATA .PUBLIC
33 + if private:
34 + return InformationType
35 + else:
36 + return InformationType
I'd put this in model rather than adapters. It's not useful outside model.
101 +class BranchCannotCha ngeInformationT ype(Exception) :
102 + """The branch cannot change its information type."""
Of course it can't -- a branch isn't an actor. Do you mean that its information type can't be changed?
116 +from lazr.restful. interface import copy_field
Unused?
159 + @property ly_private n_type in PRIVATE_ INFORMATION_ TYPES
160 def private(self):
161 - return self.transitive
162 + return self.informatio
Doesn't this need to defer to transitively_ private if information_type? Depending on the way information_type is populated later, we may even need to ignore information_type completely until the migration is done.
174 + if ( on.information_ type != .PUBLIC and information_type != on.information_ type):
175 + self.stacked_on and self.stacked_
176 + InformationType
177 + self.stacked_
That is the worst line wrapping in the history of the universe.
211 + if ( on.information_ type != .PUBLIC) : n_type = self.stacked_ on.information_ type
212 + self.stacked_on and self.stacked_
213 + InformationType
214 + self.informatio
This could do with one fewer line breaks, and possibly a comment.
327 + if information_type: roxy(branch) .information_ type = information_type roxy(branch) .explicitly_ private = True roxy(branch) .transitively_ private = True roxy(branch) .information_ type = ( .USERDATA)
328 + removeSecurityP
329 if private:
330 removeSecurityP
331 removeSecurityP
332 + if not information_type:
333 + removeSecurityP
334 + InformationType
Should you perhaps merge the two information_type bits? And how close are we to eliminating makeBranch( private) ?