Merge lp:~stevenk/launchpad/destroy-branch-privacy into lp:launchpad

Proposed by Steve Kowalik on 2012-06-14
Status: Merged
Approved by: William Grant on 2012-06-14
Approved revision: no longer in the source branch.
Merged at revision: 15417
Proposed branch: lp:~stevenk/launchpad/destroy-branch-privacy
Merge into: lp:launchpad
Diff against target: 295 lines (+7/-248)
3 files modified
lib/lp/code/model/branch.py (+0/-18)
lib/lp/code/model/branchnamespace.py (+7/-7)
lib/lp/code/model/tests/test_branch_privacy_triggers.py (+0/-223)
To merge this branch: bzr merge lp:~stevenk/launchpad/destroy-branch-privacy
Reviewer Review Type Date Requested Status
William Grant code 2012-06-14 Approve on 2012-06-14
Review via email: mp+110274@code.launchpad.net

Commit Message

Remove explicitly_private and transitively_private from the branch model code in preparation for the columns being dropped.

Description of the Change

Sorry for the alarmist branch name. :-P

This branch removes explicitly_private and transitively_private from the branch model code in preparation for the columns being dropped. A previous branch has switched to property backed onto information_type for reading, and the columns themselves for writing. We also drop the tests that were testing the behaviour of the transitively_private triggers.

To post a comment you must log in.
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/model/branch.py'
2--- lib/lp/code/model/branch.py 2012-06-13 23:57:43 +0000
3+++ lib/lp/code/model/branch.py 2012-06-14 09:26:24 +0000
4@@ -184,15 +184,6 @@
5 control_format = EnumCol(enum=ControlFormat, dbName='metadir_format')
6 whiteboard = StringCol(default=None)
7 mirror_status_message = StringCol(default=None)
8-
9- # This attribute signifies whether *this* branch is private, irrespective
10- # of the state of any stacked on branches.
11- _explicitly_private = BoolCol(
12- default=False, notNull=True, dbName='private')
13- # A branch is transitively private if it is private or it is stacked on a
14- # transitively private branch. The value of this attribute is maintained
15- # by a database trigger.
16- _transitively_private = BoolCol(dbName='transitively_private')
17 information_type = EnumCol(
18 enum=InformationType, default=InformationType.PUBLIC)
19
20@@ -250,14 +241,6 @@
21 raise BranchCannotBePublic()
22 self.information_type = information_type
23 self._reconcileAccess()
24- # Set the legacy values for now.
25- self._explicitly_private = private
26- # If this branch is private, then it is also transitively_private
27- # otherwise we need to reload the value.
28- if private:
29- self._transitively_private = True
30- else:
31- self._transitively_private = AutoReload
32
33 registrant = ForeignKey(
34 dbName='registrant', foreignKey='Person',
35@@ -1520,7 +1503,6 @@
36 naked_branch.unique_name = AutoReload
37 naked_branch.owner_name = AutoReload
38 naked_branch.target_suffix = AutoReload
39- naked_branch._transitively_private = AutoReload
40
41
42 def branch_modified_subscriber(branch, event):
43
44=== modified file 'lib/lp/code/model/branchnamespace.py'
45--- lib/lp/code/model/branchnamespace.py 2012-06-13 23:57:43 +0000
46+++ lib/lp/code/model/branchnamespace.py 2012-06-14 09:26:24 +0000
47@@ -115,13 +115,13 @@
48 information_type = InformationType.PUBLIC
49
50 branch = Branch(
51- registrant=registrant,
52- name=name, owner=self.owner, product=product, url=url,
53- title=title, lifecycle_status=lifecycle_status, summary=summary,
54- whiteboard=whiteboard, _explicitly_private=private,
55- information_type=information_type, date_created=date_created,
56- branch_type=branch_type, date_last_modified=date_created,
57- branch_format=branch_format, repository_format=repository_format,
58+ registrant=registrant, name=name, owner=self.owner,
59+ product=product, url=url, title=title,
60+ lifecycle_status=lifecycle_status, summary=summary,
61+ whiteboard=whiteboard, information_type=information_type,
62+ date_created=date_created, branch_type=branch_type,
63+ date_last_modified=date_created, branch_format=branch_format,
64+ repository_format=repository_format,
65 control_format=control_format, distroseries=distroseries,
66 sourcepackagename=sourcepackagename)
67
68
69=== removed file 'lib/lp/code/model/tests/test_branch_privacy_triggers.py'
70--- lib/lp/code/model/tests/test_branch_privacy_triggers.py 2012-05-10 02:33:07 +0000
71+++ lib/lp/code/model/tests/test_branch_privacy_triggers.py 1970-01-01 00:00:00 +0000
72@@ -1,223 +0,0 @@
73-# Copyright 2011-2012 Canonical Ltd. This software is licensed under the
74-# GNU Affero General Public License version 3 (see the file LICENSE).
75-
76-"""Tests that the triggers to maintain the branch table transitively_private
77- column work correctly."""
78-
79-__metaclass__ = type
80-
81-import unittest
82-
83-from lp.registry.enums import InformationType
84-from lp.services.database.sqlbase import cursor
85-from lp.testing.dbuser import switch_dbuser
86-from lp.testing.layers import LaunchpadZopelessLayer
87-
88-
89-class BranchPrivacyTriggersTestCase(unittest.TestCase):
90-
91- layer = LaunchpadZopelessLayer
92-
93- def setUp(self):
94- switch_dbuser('testadmin')
95- self.branch_ids = dict()
96-
97- def createBranches(self):
98- # Create branches 1, 2, 3, 4, 5
99- # 3 is private
100- # 4 stacked on 3 at insert time
101- # 2 stacked on 5
102- # 6 stacked on 1 at insert time
103- cur = cursor()
104- for x in range(7):
105- is_private = 'False'
106- information_type = InformationType.PUBLIC.value
107- if x == 3:
108- is_private = 'True'
109- information_type = InformationType.USERDATA.value
110- if x == 4:
111- stacked_on = self.branch_ids[3]
112- elif x == 6:
113- stacked_on = self.branch_ids[1]
114- else:
115- stacked_on = 'NULL'
116- cur.execute("""
117- INSERT INTO Branch (
118- name, private, information_type, stacked_on, owner,
119- registrant, branch_type
120- )
121- VALUES ('branch%d', %s, %s, %s, 1, 1, 1)
122- RETURNING id
123- """ % (x, is_private, information_type, stacked_on))
124- branch_id = cur.fetchone()[0]
125- self.branch_ids[x] = branch_id
126- self.updateStackedOnForBranch(2, 5)
127-
128- def check_branch_privacy(self, branch_num, expected_private,
129- expected_transitively_private):
130- # Check branch_num has the expected privacy attributes.
131- is_private = 'True' if expected_private else 'False'
132- is_transitively_private = ('True'
133- if expected_transitively_private else 'False')
134- cur = cursor()
135- cur.execute("""
136- SELECT COUNT(*)
137- FROM Branch
138- WHERE id = %s
139- AND private is %s
140- AND transitively_private is %s
141- """ % (self.branch_ids[branch_num],
142- is_private, is_transitively_private))
143- self.failUnlessEqual(cur.fetchone()[0], 1)
144-
145- def updateStackedOnForBranch(self, branch_num, stacked_on):
146- # Update the stacked_on attribute for a branch.
147- cur = cursor()
148- if stacked_on:
149- stacked_on = self.branch_ids[stacked_on]
150- else:
151- stacked_on = 'NULL'
152- cur.execute("""
153- UPDATE Branch
154- SET stacked_on = %s
155- WHERE id = %s
156- """ % (stacked_on, self.branch_ids[branch_num]))
157-
158- def updatePrivacyForBranch(self, branch_num, private):
159- # Update the private attribute for a branch.
160- is_private = 'True' if private else 'False'
161- cur = cursor()
162- cur.execute("""
163- UPDATE Branch
164- SET private = %s
165- WHERE id = %s
166- """ % (is_private, self.branch_ids[branch_num]))
167-
168- def testInitialBranches(self):
169- # Branch inserts invokes the trigger correctly.
170- self.createBranches()
171- self.check_branch_privacy(1, False, False)
172- self.check_branch_privacy(3, True, True)
173- self.check_branch_privacy(4, False, True)
174- self.check_branch_privacy(6, False, False)
175-
176- def testSetStackedOn(self):
177- # Stack 1 on 3 which is private.
178- # 1 should be transitively private.
179- self.createBranches()
180- self.updateStackedOnForBranch(1, 3)
181- self.check_branch_privacy(1, False, True)
182-
183- def testMultiLevelStackedOn(self):
184- # 2 is stacked on 5 already.
185- # Make 5 private, stack 1 on 2.
186- # 1 and 2 should be transitively private.
187- self.createBranches()
188- self.updatePrivacyForBranch(5, True)
189- self.check_branch_privacy(5, True, True)
190- self.check_branch_privacy(2, False, True)
191- self.updateStackedOnForBranch(1, 2)
192- self.check_branch_privacy(1, False, True)
193- self.check_branch_privacy(2, False, True)
194-
195- def testMultiLevelMultiStackedOn(self):
196- # 2 is stacked on 5 already.
197- # Stack 4 on 1.
198- # Make 5 private, stack 1 on 2.
199- # 1, 2 and 4 should be transitively private.
200- self.createBranches()
201- self.updateStackedOnForBranch(4, 1)
202- self.check_branch_privacy(4, False, False)
203- self.updatePrivacyForBranch(5, True)
204- self.check_branch_privacy(5, True, True)
205- self.check_branch_privacy(2, False, True)
206- self.updateStackedOnForBranch(1, 2)
207- self.check_branch_privacy(1, False, True)
208- self.check_branch_privacy(2, False, True)
209- self.check_branch_privacy(4, False, True)
210-
211- def testRemoveStackedOn(self):
212- # 5 is private, 1 stacked on 5, so 1 is transitively private.
213- # Unstack 1.
214- # 1 should no longer be transitively private.
215- self.createBranches()
216- self.updateStackedOnForBranch(1, 5)
217- self.updatePrivacyForBranch(5, True)
218- self.check_branch_privacy(1, False, True)
219- self.updateStackedOnForBranch(1, None)
220- self.check_branch_privacy(1, False, False)
221-
222- def testSetPrivateTrue(self):
223- # Stack 1 on 5, make 5 private.
224- # 1 should be transitively private.
225- self.createBranches()
226- self.updateStackedOnForBranch(1, 5)
227- self.check_branch_privacy(1, False, False)
228- self.updatePrivacyForBranch(5, True)
229- self.check_branch_privacy(5, True, True)
230- self.check_branch_privacy(1, False, True)
231-
232- def testMultiLevelSetPrivateTrue(self):
233- # 2 is stacked on 5 already.
234- # Stack 4 on 1, stack 1 on 2
235- # Make 5 private.
236- # 1, 2 and 4 should be transitively private.
237- self.createBranches()
238- self.updateStackedOnForBranch(4, 1)
239- self.check_branch_privacy(4, False, False)
240- self.updateStackedOnForBranch(1, 2)
241- self.check_branch_privacy(2, False, False)
242- self.updatePrivacyForBranch(5, True)
243- self.check_branch_privacy(5, True, True)
244- self.check_branch_privacy(1, False, True)
245- self.check_branch_privacy(2, False, True)
246- self.check_branch_privacy(4, False, True)
247-
248- def testSetPrivateFalse(self):
249- # Make 5 private, stack 1 on 5.
250- # Make 5 public.
251- # 1 should not be transitively private.
252- self.createBranches()
253- self.updatePrivacyForBranch(5, True)
254- self.updateStackedOnForBranch(1, 5)
255- self.check_branch_privacy(1, False, True)
256- self.updatePrivacyForBranch(5, False)
257- self.check_branch_privacy(5, False, False)
258- self.check_branch_privacy(1, False, False)
259-
260- def testMultlLevelSetPrivateFalse(self):
261- # 2 is stacked on 5 already.
262- # Make 5 private.
263- # Stack 4 on 1, stack 1 on 2
264- # Make 5 public.
265- # 1, 2 and 4 should not be transitively private.
266- self.createBranches()
267- self.updatePrivacyForBranch(5, True)
268- self.updateStackedOnForBranch(4, 1)
269- self.updateStackedOnForBranch(1, 2)
270- self.check_branch_privacy(1, False, True)
271- self.check_branch_privacy(2, False, True)
272- self.check_branch_privacy(4, False, True)
273- self.check_branch_privacy(5, True, True)
274- self.updatePrivacyForBranch(5, False)
275- self.check_branch_privacy(1, False, False)
276- self.check_branch_privacy(2, False, False)
277- self.check_branch_privacy(4, False, False)
278- self.check_branch_privacy(5, False, False)
279-
280- def testLoopedStackedOn(self):
281- # It's possible, although nonsensical, for branch stackings to form a
282- # loop. e.g., branch A is stacked on branch B is stacked on branch A.
283- # 2 is stacked on 5 already.
284- # Stack 1 on 2, stack 5 on 1, completing a 1->2->5 loop.
285- # Stack 3 on 3, the trivial case.
286- self.createBranches()
287- self.updateStackedOnForBranch(1, 2)
288- self.updateStackedOnForBranch(5, 1)
289- self.updateStackedOnForBranch(3, 3)
290- self.updatePrivacyForBranch(5, True)
291- self.updatePrivacyForBranch(3, False)
292- self.check_branch_privacy(5, True, True)
293- self.check_branch_privacy(1, False, True)
294- self.check_branch_privacy(2, False, True)
295- self.check_branch_privacy(3, False, False)