Merge lp:~cjwatson/launchpad/more-comment-footers into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18642
Proposed branch: lp:~cjwatson/launchpad/more-comment-footers
Merge into: lp:launchpad
Diff against target: 96 lines (+60/-1)
2 files modified
lib/lp/code/browser/tests/test_codereviewcomment.py (+57/-0)
lib/lp/services/comments/templates/comment.pt (+3/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/more-comment-footers
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+345303@code.launchpad.net

Commit message

Show spam controls for comments on non-mergeable MPs.

Description of the change

These don't show a Reply link, but they should still show the Hide/Unhide links for users who have permission to use them.

To post a comment you must log in.
Revision history for this message
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/browser/tests/test_codereviewcomment.py'
2--- lib/lp/code/browser/tests/test_codereviewcomment.py 2018-04-25 12:01:33 +0000
3+++ lib/lp/code/browser/tests/test_codereviewcomment.py 2018-05-09 16:34:28 +0000
4@@ -7,6 +7,8 @@
5
6 __metaclass__ = type
7
8+import re
9+
10 from soupmatchers import (
11 HTMLContains,
12 Tag,
13@@ -209,6 +211,61 @@
14 browser = self.getViewBrowser(comment, view_name='+reply')
15 self.assertIn(contents, browser.contents)
16
17+ def test_footer_for_mergeable_and_admin(self):
18+ """An admin sees Hide/Reply links for a comment on a mergeable MP."""
19+ comment = self.makeCodeReviewComment()
20+ display_comment = CodeReviewDisplayComment(comment)
21+ browser = self.getViewBrowser(
22+ display_comment, user=self.factory.makeAdministrator())
23+ footer = Tag('comment footer', 'div', {'class': 'boardCommentFooter'})
24+ hide_link = Tag('hide link', 'a', text=re.compile(r'\s*Hide\s*'))
25+ reply_link = Tag('reply link', 'a', text='Reply')
26+ self.assertThat(
27+ browser.contents, HTMLContains(hide_link.within(footer)))
28+ self.assertThat(
29+ browser.contents, HTMLContains(reply_link.within(footer)))
30+
31+ def test_footer_for_mergeable_and_non_admin(self):
32+ """A mortal sees a Reply link for a comment on a mergeable MP."""
33+ comment = self.makeCodeReviewComment()
34+ display_comment = CodeReviewDisplayComment(comment)
35+ browser = self.getViewBrowser(display_comment)
36+ footer = Tag('comment footer', 'div', {'class': 'boardCommentFooter'})
37+ hide_link = Tag('hide link', 'a', text=re.compile(r'\s*Hide\s*'))
38+ reply_link = Tag('reply link', 'a', text='Reply')
39+ self.assertThat(browser.contents, Not(HTMLContains(hide_link)))
40+ self.assertThat(
41+ browser.contents, HTMLContains(reply_link.within(footer)))
42+
43+ def test_footer_for_non_mergeable_and_admin(self):
44+ """An admin sees a Hide link for a comment on a non-mergeable MP."""
45+ comment = self.makeCodeReviewComment()
46+ merge_proposal = comment.branch_merge_proposal
47+ with person_logged_in(merge_proposal.registrant):
48+ merge_proposal.markAsMerged(
49+ merge_reporter=merge_proposal.registrant)
50+ display_comment = CodeReviewDisplayComment(comment)
51+ browser = self.getViewBrowser(
52+ display_comment, user=self.factory.makeAdministrator())
53+ footer = Tag('comment footer', 'div', {'class': 'boardCommentFooter'})
54+ hide_link = Tag('hide link', 'a', text=re.compile(r'\s*Hide\s*'))
55+ reply_link = Tag('reply link', 'a', text='Reply')
56+ self.assertThat(
57+ browser.contents, HTMLContains(hide_link.within(footer)))
58+ self.assertThat(browser.contents, Not(HTMLContains(reply_link)))
59+
60+ def test_no_footer_for_non_mergeable_and_non_admin(self):
61+ """A mortal sees no footer for a comment on a non-mergeable MP."""
62+ comment = self.makeCodeReviewComment()
63+ merge_proposal = comment.branch_merge_proposal
64+ with person_logged_in(merge_proposal.registrant):
65+ merge_proposal.markAsMerged(
66+ merge_reporter=merge_proposal.registrant)
67+ display_comment = CodeReviewDisplayComment(comment)
68+ browser = self.getViewBrowser(display_comment)
69+ footer = Tag('comment footer', 'div', {'class': 'boardCommentFooter'})
70+ self.assertThat(browser.contents, Not(HTMLContains(footer)))
71+
72
73 class TestCodeReviewCommentHtmlBzr(
74 TestCodeReviewCommentHtmlMixin, BrowserTestCase):
75
76=== modified file 'lib/lp/services/comments/templates/comment.pt'
77--- lib/lp/services/comments/templates/comment.pt 2018-04-25 12:01:33 +0000
78+++ lib/lp/services/comments/templates/comment.pt 2018-05-09 16:34:28 +0000
79@@ -24,7 +24,8 @@
80 </div>
81 <div class="boardCommentFooter"
82 tal:define="link context/menu:context/reply | nothing"
83- tal:condition="link/enabled | nothing">
84+ tal:condition="python: context.show_spam_controls or
85+ getattr(link, 'enabled', False)">
86 <a tal:condition="context/show_spam_controls"
87 tal:attributes="id string:mark-spam-${context/index};"
88 class="js-action mark-spam" href="#">
89@@ -32,6 +33,7 @@
90 <tal:spam condition="context/visible">Hide</tal:spam>
91 </a>
92 <a itemprop="replyToUrl"
93+ tal:condition="link/enabled | nothing"
94 tal:attributes="href link/fmt:url"
95 tal:content="link/escapedtext">
96 Reply