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
1=== modified file 'lib/lp/answers/browser/tests/test_questionmessages.py'
2--- lib/lp/answers/browser/tests/test_questionmessages.py 2012-12-11 04:08:19 +0000
3+++ lib/lp/answers/browser/tests/test_questionmessages.py 2015-09-14 16:38:44 +0000
4@@ -26,13 +26,14 @@
5
6 layer = DatabaseFunctionalLayer
7
8- def makeHiddenMessage(self):
9+ def makeHiddenMessage(self, comment_owner=None):
10 """Required by the mixin."""
11 administrator = getUtility(ILaunchpadCelebrities).admin.teamowner
12- self.commenter = self.factory.makePerson()
13+ if comment_owner is None:
14+ comment_owner = self.factory.makePerson()
15 with person_logged_in(administrator):
16 question = self.factory.makeQuestion()
17- comment = question.addComment(self.commenter, self.comment_text)
18+ comment = question.addComment(comment_owner, self.comment_text)
19 removeSecurityProxy(comment).message.visible = False
20 return question
21
22@@ -44,12 +45,6 @@
23 no_login=no_login)
24 return view
25
26- def test_commenter_can_see_comments(self):
27- # The author of the comment can see the hidden comment.
28- context = self.makeHiddenMessage()
29- view = self.getView(context=context, user=self.commenter)
30- self.assertIn(self.html_comment_text, view.contents)
31-
32
33 class TestHideQuestionMessageControls(
34 BrowserTestCase, TestHideMessageControlMixin):
35
36=== modified file 'lib/lp/bugs/browser/bugtask.py'
37--- lib/lp/bugs/browser/bugtask.py 2015-08-11 00:54:41 +0000
38+++ lib/lp/bugs/browser/bugtask.py 2015-09-14 16:38:44 +0000
39@@ -295,7 +295,8 @@
40 role = PersonRoles(user)
41 strip_invisible = not (role.in_admin or role.in_registry_experts)
42 if strip_invisible:
43- visible_comments = [c for c in visible_comments if c.visible]
44+ visible_comments = [c for c in visible_comments
45+ if c.visible or c.owner == user]
46
47 return visible_comments
48
49
50=== modified file 'lib/lp/bugs/browser/tests/test_bugcomment.py'
51--- lib/lp/bugs/browser/tests/test_bugcomment.py 2012-12-26 01:32:19 +0000
52+++ lib/lp/bugs/browser/tests/test_bugcomment.py 2015-09-14 16:38:44 +0000
53@@ -211,12 +211,12 @@
54
55 layer = DatabaseFunctionalLayer
56
57- def makeHiddenMessage(self):
58+ def makeHiddenMessage(self, comment_owner=None):
59 """Required by the mixin."""
60 with celebrity_logged_in('admin'):
61 bug = self.factory.makeBug()
62 comment = self.factory.makeBugComment(
63- bug=bug, body=self.comment_text)
64+ bug=bug, body=self.comment_text, owner=comment_owner)
65 comment.visible = False
66 return bug
67
68
69=== modified file 'lib/lp/bugs/stories/bugs/xx-bug-hidden-comments.txt'
70--- lib/lp/bugs/stories/bugs/xx-bug-hidden-comments.txt 2011-03-10 20:32:56 +0000
71+++ lib/lp/bugs/stories/bugs/xx-bug-hidden-comments.txt 2015-09-14 16:38:44 +0000
72@@ -37,10 +37,11 @@
73 For ordinary users, the newly created message no longer appears
74 in the list once visible has been set False.
75
76- >>> user_browser.open(
77+ >>> test_browser = setupBrowser(auth="Basic test@canonical.com:test")
78+ >>> test_browser.open(
79 ... 'http://bugs.launchpad.dev'
80 ... '/jokosher/+bug/11')
81- >>> main_content = find_main_content(user_browser.contents)
82+ >>> main_content = find_main_content(test_browser.contents)
83 >>> last_comment = main_content('div', 'boardCommentBody')[-1]
84 >>> last_comment_text = extract_text(last_comment.div)
85 >>> print last_comment_text
86@@ -50,11 +51,11 @@
87 Ordinary users also cannot reach the message via direct link.
88
89 >>> comments = find_tags_by_class(
90- ... user_browser.contents, 'boardComment')
91+ ... test_browser.contents, 'boardComment')
92 >>> for comment in comments:
93 ... number_node = comment.find(None, 'bug-comment-index')
94 ... latest_index = extract_text(number_node)
95- >>> user_browser.open(
96+ >>> test_browser.open(
97 ... 'http://bugs.launchpad.dev'
98 ... '/jokosher/+bug/11/comments/%d' % (int(latest_index[1:]) + 1))
99 Traceback (most recent call last):
100@@ -94,3 +95,37 @@
101 >>> last_comment_text = extract_text(last_comment.div)
102 >>> print last_comment.parent['class']
103 boardComment adminHiddenComment
104+
105+Also for the owner of comment the message is still visible in the bug page.
106+
107+ >>> user_browser.open(
108+ ... 'http://bugs.launchpad.dev'
109+ ... '/jokosher/+bug/11')
110+ >>> main_content = find_main_content(user_browser.contents)
111+ >>> last_comment = main_content('div', 'boardCommentBody')[-1]
112+ >>> last_comment_text = extract_text(last_comment.div)
113+ >>> print last_comment_text
114+ This comment will not be visible when the test completes.
115+
116+Owner of the comment will see the hidden message highlighted with an
117+'adminHiddenComment' style.
118+
119+ >>> print last_comment.parent['class']
120+ boardComment adminHiddenComment
121+
122+Owner of the comment can also reach the message via direct link, and it is
123+highlighted with the 'adminHiddenComment style there too.
124+
125+ >>> user_browser.open(
126+ ... 'http://bugs.launchpad.dev'
127+ ... '/jokosher/+bug/11/comments/%d' % (int(latest_index[1:]) + 1))
128+ >>> contents = extract_text(user_browser.contents)
129+ >>> print contents
130+ Comment #7 : Bug #11 ...
131+ This comment will not be visible when the test completes.
132+ ...
133+ >>> main_content = find_main_content(user_browser.contents)
134+ >>> last_comment = main_content('div', 'boardCommentBody')[-1]
135+ >>> last_comment_text = extract_text(last_comment.div)
136+ >>> print last_comment.parent['class']
137+ boardComment adminHiddenComment
138
139=== modified file 'lib/lp/coop/answersbugs/visibility.py'
140--- lib/lp/coop/answersbugs/visibility.py 2012-12-11 04:08:19 +0000
141+++ lib/lp/coop/answersbugs/visibility.py 2015-09-14 16:38:44 +0000
142@@ -58,6 +58,12 @@
143 view = self.getView(context=context)
144 self.assertNotIn(self.html_comment_text, view.contents)
145
146+ def test_comment_owner_can_see_hidden_comment(self):
147+ owner = self.factory.makePerson()
148+ context = self.makeHiddenMessage(comment_owner=owner)
149+ view = self.getView(context=context, user=owner)
150+ self.assertIn(self.html_comment_text, view.contents)
151+
152
153 class TestHideMessageControlMixin:
154