Merge lp:~abentley/launchpad/fix-index-download into lp:launchpad

Proposed by Aaron Bentley
Status: Merged
Merged at revision: 14749
Proposed branch: lp:~abentley/launchpad/fix-index-download
Merge into: lp:launchpad
Prerequisite: lp:~abentley/launchpad/attachment-timeout
Diff against target: 103 lines (+35/-15)
3 files modified
lib/lp/code/browser/codereviewcomment.py (+9/-6)
lib/lp/code/browser/configure.zcml (+7/-3)
lib/lp/code/browser/tests/test_branchmergeproposal.py (+19/-6)
To merge this branch: bzr merge lp:~abentley/launchpad/fix-index-download
Reviewer Review Type Date Requested Status
Deryck Hodge (community) Approve
Review via email: mp+91160@code.launchpad.net

Commit message

Only comment index pages may redirect to +download.

Description of the change

= Summary =
Fix bug #924926: comment download redirect on main merge proposal page

== Proposed fix ==
Render +index using a subclass of CodeReviewCommentView

== Pre-implementation notes ==
None

== Implementation details ==
Attempted to avoid subclassing by moving the redirect code to a method and using "attribute" to select that method in the zcml, but it did not work.

== Tests ==
bin/test -t test_excessive_conversation_comments_no_redirect -t test_excessive_comments_redirect_to_download

== Demo and Q/A ==
Create a comment that is more than 10,000 characters long. Go to its merge proposal page. The page should show normally.

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/code/browser/codereviewcomment.py
  lib/lp/code/browser/configure.zcml
  lib/lp/code/browser/tests/test_branchmergeproposal.py

To post a comment you must log in.
Revision history for this message
Deryck Hodge (deryck) :
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/codereviewcomment.py'
2--- lib/lp/code/browser/codereviewcomment.py 2012-02-01 20:03:27 +0000
3+++ lib/lp/code/browser/codereviewcomment.py 2012-02-01 20:03:27 +0000
4@@ -188,16 +188,19 @@
5 return download_body(
6 CodeReviewDisplayComment(self.context), self.request)
7
8+ # Should the comment be shown in full?
9+ full_comment = True
10+ # Show comment expanders?
11+ show_expanders = False
12+
13+
14+class CodeReviewCommentIndexView(CodeReviewCommentView):
15+
16 def __call__(self):
17 """View redirects to +download if comment is too long to render."""
18 if self.comment.too_long_to_render:
19 return self.request.response.redirect(self.comment.download_url)
20- return super(CodeReviewCommentView, self).__call__()
21-
22- # Should the comment be shown in full?
23- full_comment = True
24- # Show comment expanders?
25- show_expanders = False
26+ return super(CodeReviewCommentIndexView, self).__call__()
27
28
29 class CodeReviewCommentSummary(CodeReviewCommentView):
30
31=== modified file 'lib/lp/code/browser/configure.zcml'
32--- lib/lp/code/browser/configure.zcml 2012-02-01 20:03:27 +0000
33+++ lib/lp/code/browser/configure.zcml 2012-02-01 20:03:27 +0000
34@@ -645,9 +645,6 @@
35 class="lp.code.browser.codereviewcomment.CodeReviewCommentView"
36 permission="zope.Public">
37 <browser:page
38- name="+index"
39- template="../templates/codereviewcomment-index.pt"/>
40- <browser:page
41 name="+fragment"
42 template="../templates/codereviewcomment-fragment.pt"/>
43 <browser:page
44@@ -655,6 +652,13 @@
45 attribute="download"
46 />
47 </browser:pages>
48+ <browser:page
49+ for="lp.code.interfaces.codereviewcomment.ICodeReviewComment"
50+ name="+index"
51+ template="../templates/codereviewcomment-index.pt"
52+ class="lp.code.browser.codereviewcomment.CodeReviewCommentIndexView"
53+ permission="zope.Public"
54+ />
55 <browser:pages
56 for="lp.code.browser.codereviewcomment.ICodeReviewDisplayComment"
57 layer="lp.code.publisher.CodeLayer"
58
59=== modified file 'lib/lp/code/browser/tests/test_branchmergeproposal.py'
60--- lib/lp/code/browser/tests/test_branchmergeproposal.py 2012-02-01 20:03:27 +0000
61+++ lib/lp/code/browser/tests/test_branchmergeproposal.py 2012-02-01 20:03:27 +0000
62@@ -1120,15 +1120,19 @@
63 browser = self.getViewBrowser(comment.branch_merge_proposal)
64 self.assertIn('x y' * 100, browser.contents)
65
66- def test_long_conversation_comments_truncated(self):
67- """Long comments in a conversation should be truncated."""
68- comment = self.factory.makeCodeReviewComment(body='x y' * 2000)
69+ def has_read_more(self, comment):
70 url = canonical_url(comment, force_local_path=True)
71- browser = self.getViewBrowser(comment.branch_merge_proposal)
72- self.assertNotIn('x y' * 2000, browser.contents)
73 read_more = Tag(
74 'Read more link', 'a', {'href': url}, text='Read more...')
75- self.assertThat(browser.contents, HTMLContains(read_more))
76+ return HTMLContains(read_more)
77+
78+ def test_long_conversation_comments_truncated(self):
79+ """Long comments in a conversation should be truncated."""
80+ comment = self.factory.makeCodeReviewComment(body='x y' * 2000)
81+ has_read_more = self.has_read_more(comment)
82+ browser = self.getViewBrowser(comment.branch_merge_proposal)
83+ self.assertNotIn('x y' * 2000, browser.contents)
84+ self.assertThat(browser.contents, has_read_more)
85
86 def test_short_conversation_comments_no_download(self):
87 """Short comments should not have a download link."""
88@@ -1150,6 +1154,15 @@
89 text='Download full text')
90 self.assertThat(browser.contents, HTMLContains(body))
91
92+ def test_excessive_conversation_comments_no_redirect(self):
93+ """An excessive comment does not force a redict on proposal page."""
94+ comment = self.factory.makeCodeReviewComment(body='x' * 10001)
95+ mp_url = canonical_url(comment.branch_merge_proposal)
96+ has_read_more = self.has_read_more(comment)
97+ browser = self.getUserBrowser(mp_url)
98+ self.assertThat(browser.contents, Not(has_read_more))
99+ self.assertEqual(mp_url, browser.url)
100+
101
102 class TestLatestProposalsForEachBranch(TestCaseWithFactory):
103 """Confirm that the latest branch is returned."""