Merge lp:~rpadovani/launchpad/unhide-comments into lp:launchpad

Proposed by Riccardo Padovani
Status: Merged
Merged at revision: 17738
Proposed branch: lp:~rpadovani/launchpad/unhide-comments
Merge into: lp:launchpad
Diff against target: 153 lines (+53/-16)
5 files modified
lib/lp/answers/browser/tests/test_questionmessages.py (+4/-9)
lib/lp/bugs/browser/bugtask.py (+2/-1)
lib/lp/bugs/browser/tests/test_bugcomment.py (+2/-2)
lib/lp/bugs/stories/bugs/xx-bug-hidden-comments.txt (+39/-4)
lib/lp/coop/answersbugs/visibility.py (+6/-0)
To merge this branch: bzr merge lp:~rpadovani/launchpad/unhide-comments
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+270950@code.launchpad.net

Commit message

Show hidden bug comments to their owners.

Description of the change

Summary

Fix bug #1391394, impossible to unhide my comment

Proposed fix

Now owner of comments could see the comment also if it's hidden

Tests

I'm a bit confused about how implementing the test.
I see there is a TestBugCommentVisibility class in bugs/browser/tests/test_bugcomment.py, and there is a method called makeHiddenMessage().

But, as far as I understand, the message created here is owned by admin.

So I think I need to create a method that creates a comment with a non-admin account, then I need to set visibility of the comment to false (comment.visible = False could work?) and then test if the comment is visible to the owner and then test if it's hide to a normal user?

Could work as approach?

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

The fact that you're modifying something in lib/lp/coop/answersbugs/ should be a clue that you need to go and look in lib/lp/answers/ for users of the same test. In this case your change is going to make TestQuestionMessageVisibility fail. As it happens, questions already behave the right way here, and there's a specific test for that. I would suggest removing TestQuestionMessageVisibility.test_commenter_can_see_comments in favour of your coop test, and adjusting TestQuestionMessageVisibility.makeHiddenMessage to match, something like this:

    if comment_owner is None:
        comment_owner = self.factory.makePerson()
    with celebrity_logged_in('admin'):
        question = self.factory.makeQuestion()
        comment = question.addComment(comment_owner, self.comment_text)
        removeSecurityProxy(comment).message.visible = False
    return question

The other thing you need to do is to do something about the presentation. Users should see their self-hidden comments in the same way that admins do, which requires having the adminHiddenContent class set (slightly inaccurate name, but no matter). That will require changing BugComment.show_for_admin; you probably want to change BugComment.__init__ to save user_owns_comment as an instance attribute, and then you can test that in show_for_admin. As far as testing for that goes, you're probably best off editing the existing pagetest in lib/lp/bugs/stories/bugs/xx-bug-hidden-comments.txt, which is the only place that tests the presence of the adminHiddenComment class at the moment.

review: Needs Fixing
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/answers/browser/tests/test_questionmessages.py'
--- lib/lp/answers/browser/tests/test_questionmessages.py 2012-12-11 04:08:19 +0000
+++ lib/lp/answers/browser/tests/test_questionmessages.py 2015-09-14 16:38:44 +0000
@@ -26,13 +26,14 @@
2626
27 layer = DatabaseFunctionalLayer27 layer = DatabaseFunctionalLayer
2828
29 def makeHiddenMessage(self):29 def makeHiddenMessage(self, comment_owner=None):
30 """Required by the mixin."""30 """Required by the mixin."""
31 administrator = getUtility(ILaunchpadCelebrities).admin.teamowner31 administrator = getUtility(ILaunchpadCelebrities).admin.teamowner
32 self.commenter = self.factory.makePerson()32 if comment_owner is None:
33 comment_owner = self.factory.makePerson()
33 with person_logged_in(administrator):34 with person_logged_in(administrator):
34 question = self.factory.makeQuestion()35 question = self.factory.makeQuestion()
35 comment = question.addComment(self.commenter, self.comment_text)36 comment = question.addComment(comment_owner, self.comment_text)
36 removeSecurityProxy(comment).message.visible = False37 removeSecurityProxy(comment).message.visible = False
37 return question38 return question
3839
@@ -44,12 +45,6 @@
44 no_login=no_login)45 no_login=no_login)
45 return view46 return view
4647
47 def test_commenter_can_see_comments(self):
48 # The author of the comment can see the hidden comment.
49 context = self.makeHiddenMessage()
50 view = self.getView(context=context, user=self.commenter)
51 self.assertIn(self.html_comment_text, view.contents)
52
5348
54class TestHideQuestionMessageControls(49class TestHideQuestionMessageControls(
55 BrowserTestCase, TestHideMessageControlMixin):50 BrowserTestCase, TestHideMessageControlMixin):
5651
=== modified file 'lib/lp/bugs/browser/bugtask.py'
--- lib/lp/bugs/browser/bugtask.py 2015-08-11 00:54:41 +0000
+++ lib/lp/bugs/browser/bugtask.py 2015-09-14 16:38:44 +0000
@@ -295,7 +295,8 @@
295 role = PersonRoles(user)295 role = PersonRoles(user)
296 strip_invisible = not (role.in_admin or role.in_registry_experts)296 strip_invisible = not (role.in_admin or role.in_registry_experts)
297 if strip_invisible:297 if strip_invisible:
298 visible_comments = [c for c in visible_comments if c.visible]298 visible_comments = [c for c in visible_comments
299 if c.visible or c.owner == user]
299300
300 return visible_comments301 return visible_comments
301302
302303
=== modified file 'lib/lp/bugs/browser/tests/test_bugcomment.py'
--- lib/lp/bugs/browser/tests/test_bugcomment.py 2012-12-26 01:32:19 +0000
+++ lib/lp/bugs/browser/tests/test_bugcomment.py 2015-09-14 16:38:44 +0000
@@ -211,12 +211,12 @@
211211
212 layer = DatabaseFunctionalLayer212 layer = DatabaseFunctionalLayer
213213
214 def makeHiddenMessage(self):214 def makeHiddenMessage(self, comment_owner=None):
215 """Required by the mixin."""215 """Required by the mixin."""
216 with celebrity_logged_in('admin'):216 with celebrity_logged_in('admin'):
217 bug = self.factory.makeBug()217 bug = self.factory.makeBug()
218 comment = self.factory.makeBugComment(218 comment = self.factory.makeBugComment(
219 bug=bug, body=self.comment_text)219 bug=bug, body=self.comment_text, owner=comment_owner)
220 comment.visible = False220 comment.visible = False
221 return bug221 return bug
222222
223223
=== modified file 'lib/lp/bugs/stories/bugs/xx-bug-hidden-comments.txt'
--- lib/lp/bugs/stories/bugs/xx-bug-hidden-comments.txt 2011-03-10 20:32:56 +0000
+++ lib/lp/bugs/stories/bugs/xx-bug-hidden-comments.txt 2015-09-14 16:38:44 +0000
@@ -37,10 +37,11 @@
37For ordinary users, the newly created message no longer appears37For ordinary users, the newly created message no longer appears
38in the list once visible has been set False.38in the list once visible has been set False.
3939
40 >>> user_browser.open(40 >>> test_browser = setupBrowser(auth="Basic test@canonical.com:test")
41 >>> test_browser.open(
41 ... 'http://bugs.launchpad.dev'42 ... 'http://bugs.launchpad.dev'
42 ... '/jokosher/+bug/11')43 ... '/jokosher/+bug/11')
43 >>> main_content = find_main_content(user_browser.contents)44 >>> main_content = find_main_content(test_browser.contents)
44 >>> last_comment = main_content('div', 'boardCommentBody')[-1]45 >>> last_comment = main_content('div', 'boardCommentBody')[-1]
45 >>> last_comment_text = extract_text(last_comment.div)46 >>> last_comment_text = extract_text(last_comment.div)
46 >>> print last_comment_text47 >>> print last_comment_text
@@ -50,11 +51,11 @@
50Ordinary users also cannot reach the message via direct link.51Ordinary users also cannot reach the message via direct link.
5152
52 >>> comments = find_tags_by_class(53 >>> comments = find_tags_by_class(
53 ... user_browser.contents, 'boardComment')54 ... test_browser.contents, 'boardComment')
54 >>> for comment in comments:55 >>> for comment in comments:
55 ... number_node = comment.find(None, 'bug-comment-index')56 ... number_node = comment.find(None, 'bug-comment-index')
56 ... latest_index = extract_text(number_node)57 ... latest_index = extract_text(number_node)
57 >>> user_browser.open(58 >>> test_browser.open(
58 ... 'http://bugs.launchpad.dev'59 ... 'http://bugs.launchpad.dev'
59 ... '/jokosher/+bug/11/comments/%d' % (int(latest_index[1:]) + 1))60 ... '/jokosher/+bug/11/comments/%d' % (int(latest_index[1:]) + 1))
60 Traceback (most recent call last):61 Traceback (most recent call last):
@@ -94,3 +95,37 @@
94 >>> last_comment_text = extract_text(last_comment.div)95 >>> last_comment_text = extract_text(last_comment.div)
95 >>> print last_comment.parent['class']96 >>> print last_comment.parent['class']
96 boardComment adminHiddenComment97 boardComment adminHiddenComment
98
99Also for the owner of comment the message is still visible in the bug page.
100
101 >>> user_browser.open(
102 ... 'http://bugs.launchpad.dev'
103 ... '/jokosher/+bug/11')
104 >>> main_content = find_main_content(user_browser.contents)
105 >>> last_comment = main_content('div', 'boardCommentBody')[-1]
106 >>> last_comment_text = extract_text(last_comment.div)
107 >>> print last_comment_text
108 This comment will not be visible when the test completes.
109
110Owner of the comment will see the hidden message highlighted with an
111'adminHiddenComment' style.
112
113 >>> print last_comment.parent['class']
114 boardComment adminHiddenComment
115
116Owner of the comment can also reach the message via direct link, and it is
117highlighted with the 'adminHiddenComment style there too.
118
119 >>> user_browser.open(
120 ... 'http://bugs.launchpad.dev'
121 ... '/jokosher/+bug/11/comments/%d' % (int(latest_index[1:]) + 1))
122 >>> contents = extract_text(user_browser.contents)
123 >>> print contents
124 Comment #7 : Bug #11 ...
125 This comment will not be visible when the test completes.
126 ...
127 >>> main_content = find_main_content(user_browser.contents)
128 >>> last_comment = main_content('div', 'boardCommentBody')[-1]
129 >>> last_comment_text = extract_text(last_comment.div)
130 >>> print last_comment.parent['class']
131 boardComment adminHiddenComment
97132
=== modified file 'lib/lp/coop/answersbugs/visibility.py'
--- lib/lp/coop/answersbugs/visibility.py 2012-12-11 04:08:19 +0000
+++ lib/lp/coop/answersbugs/visibility.py 2015-09-14 16:38:44 +0000
@@ -58,6 +58,12 @@
58 view = self.getView(context=context)58 view = self.getView(context=context)
59 self.assertNotIn(self.html_comment_text, view.contents)59 self.assertNotIn(self.html_comment_text, view.contents)
6060
61 def test_comment_owner_can_see_hidden_comment(self):
62 owner = self.factory.makePerson()
63 context = self.makeHiddenMessage(comment_owner=owner)
64 view = self.getView(context=context, user=owner)
65 self.assertIn(self.html_comment_text, view.contents)
66
6167
62class TestHideMessageControlMixin:68class TestHideMessageControlMixin:
6369