Merge lp:~jcsackett/launchpad/code-configuration-652142 into lp:launchpad

Proposed by j.c.sackett
Status: Merged
Approved by: j.c.sackett
Approved revision: no longer in the source branch.
Merged at revision: 11720
Proposed branch: lp:~jcsackett/launchpad/code-configuration-652142
Merge into: lp:launchpad
Diff against target: 154 lines (+52/-29)
4 files modified
lib/lp/code/browser/branchlisting.py (+6/-1)
lib/lp/code/browser/tests/test_product.py (+21/-1)
lib/lp/code/stories/branches/xx-product-branches.txt (+7/-12)
lib/lp/code/templates/product-branch-summary.pt (+18/-15)
To merge this branch: bzr merge lp:~jcsackett/launchpad/code-configuration-652142
Reviewer Review Type Date Requested Status
Leonard Richardson (community) Approve
Review via email: mp+38015@code.launchpad.net

Commit message

Fixes the message displayed to users on product code pages with no branches; previously users without configuration rights were told they could set things up when they couldn't.

Description of the change

Summary
=======

The bulleted list of steps to take for a product with no branches implies that
a user can configure branches/codehosting for the product regardless of
whether or not they can.

This branch simply removes the messages about how to set up branches for the
product if the user doesn't have the permissions to configure code for the
product.

Proposed fix
============

Adds a can_configure_branches checker to the branch views, and uses that to
filter the messages displayed to users, so users who can't configure things
aren't led to believe they can.

Implementation details
======================

As above.

Tests
=====

bin/test -m lp.code.browser.tests.test_product

Demo and Q/A
============

If you go to code.launchpad.dev/mega-money-maker logged in as
<email address hidden>, you will see the bulleted list and a configuration
link.

If you logout and go to the same page, you will only see the message saying
that LP doesn't know where code is hosted, and that the product has no
branches.

Lint
====

make lint output:

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/code/browser/branchlisting.py
  lib/lp/code/browser/tests/test_product.py
  lib/lp/code/templates/product-branch-summary.pt

./lib/lp/code/templates/product-branch-summary.pt
      44: Line has trailing whitespace.

The trailing whitespace is a space needed in the displayed text on the webpage.

To post a comment you must log in.
Revision history for this message
Leonard Richardson (leonardr) wrote :

Very clear.

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 2010-09-28 22:21:51 +0000
3+++ lib/lp/code/browser/branchlisting.py 2010-10-15 14:29:43 +0000
4@@ -406,7 +406,8 @@
5 @cachedproperty
6 def official_package_links_map(self):
7 """Return a map from branch id to a list of package links."""
8- links = self._query_optimiser.getOfficialSourcePackageLinksForBranches(
9+ query_optimiser = self._query_optimiser
10+ links = query_optimiser.getOfficialSourcePackageLinksForBranches(
11 self._visible_branch_ids)
12 result = {}
13 for link in links:
14@@ -1180,6 +1181,10 @@
15 'in this project.')
16 return message % self.context.displayname
17
18+ def can_configure_branches(self):
19+ """Whether or not the user can configure branches."""
20+ return check_permission("launchpad.Edit", self.context)
21+
22
23 class ProductBranchStatisticsView(BranchCountSummaryView,
24 ProductBranchListingView):
25
26=== modified file 'lib/lp/code/browser/tests/test_product.py'
27--- lib/lp/code/browser/tests/test_product.py 2010-10-04 19:50:45 +0000
28+++ lib/lp/code/browser/tests/test_product.py 2010-10-15 14:29:43 +0000
29@@ -26,6 +26,7 @@
30 BranchVisibilityRule,
31 )
32 from lp.code.interfaces.revision import IRevisionSet
33+from lp.code.publisher import CodeLayer
34 from lp.testing import (
35 ANONYMOUS,
36 BrowserTestCase,
37@@ -34,7 +35,10 @@
38 TestCaseWithFactory,
39 time_counter,
40 )
41-from lp.testing.views import create_initialized_view
42+from lp.testing.views import (
43+ create_view,
44+ create_initialized_view,
45+ )
46
47
48 class ProductTestBase(TestCaseWithFactory):
49@@ -294,5 +298,21 @@
50 self.assertTextMatchesExpressionIgnoreWhitespace(expected, text)
51
52
53+class TestCanConfigureBranches(TestCaseWithFactory):
54+
55+ layer = DatabaseFunctionalLayer
56+
57+ def test_cannot_configure_branches_product_no_edit_permission(self):
58+ product = self.factory.makeProduct()
59+ view = create_view(product, '+branches', layer=CodeLayer)
60+ self.assertEqual(False, view.can_configure_branches())
61+
62+ def test_can_configure_branches_product_with_edit_permission(self):
63+ product = self.factory.makeProduct()
64+ login_person(product.owner)
65+ view = create_view(product, '+branches', layer=CodeLayer)
66+ self.assertEqual(True, view.can_configure_branches())
67+
68+
69 def test_suite():
70 return unittest.TestLoader().loadTestsFromName(__name__)
71
72=== modified file 'lib/lp/code/stories/branches/xx-product-branches.txt'
73--- lib/lp/code/stories/branches/xx-product-branches.txt 2010-09-28 19:25:54 +0000
74+++ lib/lp/code/stories/branches/xx-product-branches.txt 2010-10-15 14:29:43 +0000
75@@ -37,14 +37,12 @@
76 ... return find_tag_by_id(browser.contents, 'branch-summary')
77 >>> summary = get_summary(browser)
78 >>> print extract_text(summary)
79- Launchpad does not know where The Gnome Panel Applets hosts its code.
80- There are no branches for Gnome Applets in Launchpad. You can change this by:
81- activating code hosting directly on Launchpad. (read more)
82- asking Launchpad to mirror a Bazaar branch hosted elsewhere. (read more)
83- asking Launchpad to import code from Git, Subversion, or CVS into a
84- Bazaar branch. (read more)
85- Getting started with code hosting in Launchpad.
86-
87+ Launchpad does not know where The Gnome Panel Applets
88+ hosts its code.
89+ There are no branches for Gnome Applets
90+ in Launchpad.
91+ Getting started
92+ with code hosting in Launchpad.
93
94 If there are Bazaar branches of Gnome Applets in a publicly
95 accessible location, Launchpad can act as a mirror of the branch
96@@ -54,13 +52,10 @@
97 Launchpad can import code from CVS, Subversion, Mercurial or Git
98 into Bazaar branches. Read more...
99
100-The 'Read more' links go to the help wiki.
101+The 'Help' links go to the help wiki.
102
103 >>> for anchor in summary.fetch('a'):
104 ... print anchor['href']
105- https://help.launchpad.net/Code/UploadingABranch
106- https://help.launchpad.net/Code/MirroredBranches
107- https://help.launchpad.net/VcsImports
108 https://help.launchpad.net/Code
109
110
111
112=== modified file 'lib/lp/code/templates/product-branch-summary.pt'
113--- lib/lp/code/templates/product-branch-summary.pt 2010-09-28 19:25:54 +0000
114+++ lib/lp/code/templates/product-branch-summary.pt 2010-10-15 14:29:43 +0000
115@@ -42,21 +42,24 @@
116
117 <tal:no-branches condition="not: view/branch_count">
118 There are no branches for <tal:project-name replace="context/displayname"/>
119- in Launchpad. You can change this by:
120-
121- <ul class="bulleted" style="margin-top:1em;">
122-
123- <li>activating code hosting directly on
124- Launchpad. (<a href="https://help.launchpad.net/Code/UploadingABranch">read
125- more</a>)</li>
126-
127- <li>asking Launchpad to mirror a Bazaar branch hosted
128- elsewhere. (<a href="https://help.launchpad.net/Code/MirroredBranches">read
129- more</a>)</li>
130-
131- <li>asking Launchpad to import code from Git, Subversion, or CVS into a
132- Bazaar branch. (<a href="https://help.launchpad.net/VcsImports">read more</a>)</li>
133- </ul>
134+ in Launchpad.
135+ <tal:can-configure condition="view/can_configure_branches">
136+ You can change this by:
137+
138+ <ul class="bulleted" style="margin-top:1em;">
139+
140+ <li>activating code hosting directly on
141+ Launchpad. (<a href="https://help.launchpad.net/Code/UploadingABranch">read
142+ more</a>)</li>
143+
144+ <li>asking Launchpad to mirror a Bazaar branch hosted
145+ elsewhere. (<a href="https://help.launchpad.net/Code/MirroredBranches">read
146+ more</a>)</li>
147+
148+ <li>asking Launchpad to import code from Git, Subversion, or CVS into a
149+ Bazaar branch. (<a href="https://help.launchpad.net/VcsImports">read more</a>)</li>
150+ </ul>
151+ </tal:can-configure>
152 </tal:no-branches>
153
154 <tal:has-branches condition="view/branch_count">