Merge lp:~stevenk/launchpad/skip-private-dev-focus into lp:launchpad

Proposed by Steve Kowalik on 2012-10-03
Status: Merged
Merged at revision: 16077
Proposed branch: lp:~stevenk/launchpad/skip-private-dev-focus
Merge into: lp:launchpad
Diff against target: 143 lines (+36/-18)
3 files modified
lib/lp/code/browser/branchlisting.py (+11/-2)
lib/lp/code/browser/tests/test_product.py (+21/-11)
lib/lp/code/templates/product-branch-summary.pt (+4/-5)
To merge this branch: bzr merge lp:~stevenk/launchpad/skip-private-dev-focus
Reviewer Review Type Date Requested Status
Ian Booth (community) 2012-10-03 Approve on 2012-10-03
Review via email: mp+127629@code.launchpad.net

Commit Message

Deal with private imported branches on Product:+code-index.

Description of the Change

Currently, Product:+code-index assumes that import branches are public, which is wrong. I have cleaned up the TAL and written a function to decide whether to show the section only if the branch is visible as well.

I have cleaned up some whitespace as well. The net-positive in this branch will be wiped out by a branch I'm preparing for merge now.

To post a comment you must log in.
Ian Booth (wallyworld) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/browser/branchlisting.py'
2--- lib/lp/code/browser/branchlisting.py 2012-09-28 06:15:58 +0000
3+++ lib/lp/code/browser/branchlisting.py 2012-10-03 03:58:21 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Base class view for branch listings."""
10@@ -61,7 +61,10 @@
11 LaunchpadFormView,
12 )
13 from lp.app.browser.tales import MenuAPI
14-from lp.app.enums import PRIVATE_INFORMATION_TYPES
15+from lp.app.enums import (
16+ PRIVATE_INFORMATION_TYPES,
17+ ServiceUsage,
18+ )
19 from lp.app.widgets.itemswidgets import LaunchpadDropdownWidget
20 from lp.blueprints.interfaces.specificationbranch import (
21 ISpecificationBranchSet,
22@@ -1406,6 +1409,12 @@
23 set_branch.text = 'Configure code hosting'
24 return set_branch
25
26+ @property
27+ def external_visible(self):
28+ return (
29+ self.context.codehosting_usage == ServiceUsage.EXTERNAL
30+ and self.branch)
31+
32
33 class ProductBranchesView(ProductBranchListingView):
34 """View for branch listing for a product."""
35
36=== modified file 'lib/lp/code/browser/tests/test_product.py'
37--- lib/lp/code/browser/tests/test_product.py 2012-09-19 01:19:35 +0000
38+++ lib/lp/code/browser/tests/test_product.py 2012-10-03 03:58:21 +0000
39@@ -31,6 +31,7 @@
40 login,
41 login_person,
42 logout,
43+ person_logged_in,
44 TestCaseWithFactory,
45 time_counter,
46 )
47@@ -196,6 +197,20 @@
48 content = view()
49 self.assertIn('bzr push lp:~', content)
50
51+ def test_product_code_index_with_private_imported_branch(self):
52+ # Product:+code-index will not crash if the devfoocs is a private
53+ # imported branch.
54+ product, branch = self.makeProductAndDevelopmentFocusBranch(
55+ information_type=InformationType.USERDATA,
56+ branch_type=BranchType.IMPORTED)
57+ user = self.factory.makePerson()
58+ with person_logged_in(user):
59+ view = create_initialized_view(
60+ product, '+code-index', rootsite='code', principal=user)
61+ html = view()
62+ expected = 'There are no branches for %s' % product.displayname
63+ self.assertIn(expected, html)
64+
65
66 class TestProductCodeIndexServiceUsages(ProductTestBase, BrowserTestCase):
67 """Tests for the product code page, especially the usage messasges."""
68@@ -247,10 +262,8 @@
69 # A remote branch says code is hosted externally, and displays
70 # upstream data.
71 product, branch = self.makeProductAndDevelopmentFocusBranch(
72- branch_type=BranchType.REMOTE,
73- url="http://example.com/mybranch")
74- self.assertEqual(ServiceUsage.EXTERNAL,
75- product.codehosting_usage)
76+ branch_type=BranchType.REMOTE, url="http://example.com/mybranch")
77+ self.assertEqual(ServiceUsage.EXTERNAL, product.codehosting_usage)
78 browser = self.getUserBrowser(canonical_url(product, rootsite='code'))
79 login(ANONYMOUS)
80 content = find_tag_by_id(browser.contents, 'external')
81@@ -305,10 +318,8 @@
82 # Mirrors show the correct upstream url as the mirror location.
83 url = "http://example.com/mybranch"
84 product, branch = self.makeProductAndDevelopmentFocusBranch(
85- branch_type=BranchType.MIRRORED,
86- url=url)
87- view = create_initialized_view(product, '+code-index',
88- rootsite='code')
89+ branch_type=BranchType.MIRRORED, url=url)
90+ view = create_initialized_view(product, '+code-index', rootsite='code')
91 self.assertEqual(url, view.mirror_location)
92
93
94@@ -343,8 +354,7 @@
95 # If the BranchUsage is EXTERNAL then the portlets are shown.
96 url = "http://example.com/mybranch"
97 product, branch = self.makeProductAndDevelopmentFocusBranch(
98- branch_type=BranchType.MIRRORED,
99- url=url)
100+ branch_type=BranchType.MIRRORED, url=url)
101 browser = self.getUserBrowser(canonical_url(product, rootsite='code'))
102 contents = browser.contents
103 self.assertIsNot(None, find_tag_by_id(contents, 'branch-portlet'))
104@@ -397,4 +407,4 @@
105 product = self.factory.makeProduct()
106 login_person(product.owner)
107 view = create_view(product, '+branches', layer=CodeLayer)
108- self.assertEqual(True, view.can_configure_branches())
109+ self.assertTrue(view.can_configure_branches())
110
111=== modified file 'lib/lp/code/templates/product-branch-summary.pt'
112--- lib/lp/code/templates/product-branch-summary.pt 2012-07-12 13:15:10 +0000
113+++ lib/lp/code/templates/product-branch-summary.pt 2012-10-03 03:58:21 +0000
114@@ -19,8 +19,7 @@
115 </div>
116
117 <div id="external"
118- tal:condition="context/codehosting_usage/enumvalue:EXTERNAL"
119- tal:define="branch view/branch">
120+ tal:condition="view/external_visible" tal:define="branch view/branch">
121 <strong>
122 <p tal:condition="not: branch/branch_type/enumvalue:IMPORTED">
123 <tal:project_title replace="context/title" /> hosts its code at
124@@ -43,16 +42,16 @@
125 You can learn more at the project's
126 <a tal:attributes="href context/homepageurl">web page</a>.
127 </p>
128- <p tal:condition="view/branch/branch_type/enumvalue:MIRRORED">
129+ <p tal:condition="branch/branch_type/enumvalue:MIRRORED">
130 Launchpad has a mirror of the master branch and you can create branches
131 from it.
132 </p>
133- <p tal:condition="view/branch/branch_type/enumvalue:IMPORTED">
134+ <p tal:condition="branch/branch_type/enumvalue:IMPORTED">
135 Launchpad imports the master branch and you can create branches from
136 it.
137 </p>
138
139- <p tal:condition="view/branch/branch_type/enumvalue:REMOTE">
140+ <p tal:condition="branch/branch_type/enumvalue:REMOTE">
141 Launchpad does not have a copy of the remote branch.
142 </p>
143 </div>