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
=== modified file 'lib/lp/code/browser/codereviewcomment.py'
--- lib/lp/code/browser/codereviewcomment.py 2012-02-01 20:03:27 +0000
+++ lib/lp/code/browser/codereviewcomment.py 2012-02-01 20:03:27 +0000
@@ -188,16 +188,19 @@
188 return download_body(188 return download_body(
189 CodeReviewDisplayComment(self.context), self.request)189 CodeReviewDisplayComment(self.context), self.request)
190190
191 # Should the comment be shown in full?
192 full_comment = True
193 # Show comment expanders?
194 show_expanders = False
195
196
197class CodeReviewCommentIndexView(CodeReviewCommentView):
198
191 def __call__(self):199 def __call__(self):
192 """View redirects to +download if comment is too long to render."""200 """View redirects to +download if comment is too long to render."""
193 if self.comment.too_long_to_render:201 if self.comment.too_long_to_render:
194 return self.request.response.redirect(self.comment.download_url)202 return self.request.response.redirect(self.comment.download_url)
195 return super(CodeReviewCommentView, self).__call__()203 return super(CodeReviewCommentIndexView, self).__call__()
196
197 # Should the comment be shown in full?
198 full_comment = True
199 # Show comment expanders?
200 show_expanders = False
201204
202205
203class CodeReviewCommentSummary(CodeReviewCommentView):206class CodeReviewCommentSummary(CodeReviewCommentView):
204207
=== modified file 'lib/lp/code/browser/configure.zcml'
--- lib/lp/code/browser/configure.zcml 2012-02-01 20:03:27 +0000
+++ lib/lp/code/browser/configure.zcml 2012-02-01 20:03:27 +0000
@@ -645,9 +645,6 @@
645 class="lp.code.browser.codereviewcomment.CodeReviewCommentView"645 class="lp.code.browser.codereviewcomment.CodeReviewCommentView"
646 permission="zope.Public">646 permission="zope.Public">
647 <browser:page647 <browser:page
648 name="+index"
649 template="../templates/codereviewcomment-index.pt"/>
650 <browser:page
651 name="+fragment"648 name="+fragment"
652 template="../templates/codereviewcomment-fragment.pt"/>649 template="../templates/codereviewcomment-fragment.pt"/>
653 <browser:page650 <browser:page
@@ -655,6 +652,13 @@
655 attribute="download"652 attribute="download"
656 />653 />
657 </browser:pages>654 </browser:pages>
655 <browser:page
656 for="lp.code.interfaces.codereviewcomment.ICodeReviewComment"
657 name="+index"
658 template="../templates/codereviewcomment-index.pt"
659 class="lp.code.browser.codereviewcomment.CodeReviewCommentIndexView"
660 permission="zope.Public"
661 />
658 <browser:pages662 <browser:pages
659 for="lp.code.browser.codereviewcomment.ICodeReviewDisplayComment"663 for="lp.code.browser.codereviewcomment.ICodeReviewDisplayComment"
660 layer="lp.code.publisher.CodeLayer"664 layer="lp.code.publisher.CodeLayer"
661665
=== modified file 'lib/lp/code/browser/tests/test_branchmergeproposal.py'
--- lib/lp/code/browser/tests/test_branchmergeproposal.py 2012-02-01 20:03:27 +0000
+++ lib/lp/code/browser/tests/test_branchmergeproposal.py 2012-02-01 20:03:27 +0000
@@ -1120,15 +1120,19 @@
1120 browser = self.getViewBrowser(comment.branch_merge_proposal)1120 browser = self.getViewBrowser(comment.branch_merge_proposal)
1121 self.assertIn('x y' * 100, browser.contents)1121 self.assertIn('x y' * 100, browser.contents)
11221122
1123 def test_long_conversation_comments_truncated(self):1123 def has_read_more(self, comment):
1124 """Long comments in a conversation should be truncated."""
1125 comment = self.factory.makeCodeReviewComment(body='x y' * 2000)
1126 url = canonical_url(comment, force_local_path=True)1124 url = canonical_url(comment, force_local_path=True)
1127 browser = self.getViewBrowser(comment.branch_merge_proposal)
1128 self.assertNotIn('x y' * 2000, browser.contents)
1129 read_more = Tag(1125 read_more = Tag(
1130 'Read more link', 'a', {'href': url}, text='Read more...')1126 'Read more link', 'a', {'href': url}, text='Read more...')
1131 self.assertThat(browser.contents, HTMLContains(read_more))1127 return HTMLContains(read_more)
1128
1129 def test_long_conversation_comments_truncated(self):
1130 """Long comments in a conversation should be truncated."""
1131 comment = self.factory.makeCodeReviewComment(body='x y' * 2000)
1132 has_read_more = self.has_read_more(comment)
1133 browser = self.getViewBrowser(comment.branch_merge_proposal)
1134 self.assertNotIn('x y' * 2000, browser.contents)
1135 self.assertThat(browser.contents, has_read_more)
11321136
1133 def test_short_conversation_comments_no_download(self):1137 def test_short_conversation_comments_no_download(self):
1134 """Short comments should not have a download link."""1138 """Short comments should not have a download link."""
@@ -1150,6 +1154,15 @@
1150 text='Download full text')1154 text='Download full text')
1151 self.assertThat(browser.contents, HTMLContains(body))1155 self.assertThat(browser.contents, HTMLContains(body))
11521156
1157 def test_excessive_conversation_comments_no_redirect(self):
1158 """An excessive comment does not force a redict on proposal page."""
1159 comment = self.factory.makeCodeReviewComment(body='x' * 10001)
1160 mp_url = canonical_url(comment.branch_merge_proposal)
1161 has_read_more = self.has_read_more(comment)
1162 browser = self.getUserBrowser(mp_url)
1163 self.assertThat(browser.contents, Not(has_read_more))
1164 self.assertEqual(mp_url, browser.url)
1165
11531166
1154class TestLatestProposalsForEachBranch(TestCaseWithFactory):1167class TestLatestProposalsForEachBranch(TestCaseWithFactory):
1155 """Confirm that the latest branch is returned."""1168 """Confirm that the latest branch is returned."""