Merge lp:~kfogel/launchpad/546943-really-hide-hidden-bug-comments into lp:launchpad

Proposed by Karl Fogel
Status: Merged
Approved by: Karl Fogel
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~kfogel/launchpad/546943-really-hide-hidden-bug-comments
Merge into: lp:launchpad
Diff against target: 99 lines (+43/-7)
2 files modified
lib/lp/bugs/browser/bugtask.py (+6/-1)
lib/lp/bugs/stories/bugs/xx-bug-hidden-comments.txt (+37/-6)
To merge this branch: bzr merge lp:~kfogel/launchpad/546943-really-hide-hidden-bug-comments
Reviewer Review Type Date Requested Status
Deryck Hodge (community) code Approve
Abel Deuring Pending
Review via email: mp+22647@code.launchpad.net

Description of the change

Make sure that hidden (visible=false) comments cannot be reached via direct link either, except by admin.

To post a comment you must log in.
Revision history for this message
Deryck Hodge (deryck) wrote :

Looks good. Thanks!

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/bugs/browser/bugtask.py'
2--- lib/lp/bugs/browser/bugtask.py 2010-03-29 13:31:23 +0000
3+++ lib/lp/bugs/browser/bugtask.py 2010-04-01 18:39:29 +0000
4@@ -485,7 +485,12 @@
5 # I have chosed to use this simple solution for now.
6 # -- kiko, 2006-07-11
7 try:
8- return comments[index]
9+ comment = comments[index]
10+ if (comment.visible
11+ or check_permission('launchpad.Admin', self.context)):
12+ return comment
13+ else:
14+ return None
15 except IndexError:
16 return None
17
18
19=== modified file 'lib/lp/bugs/stories/bugs/xx-bug-hidden-comments.txt'
20--- lib/lp/bugs/stories/bugs/xx-bug-hidden-comments.txt 2009-08-28 14:31:15 +0000
21+++ lib/lp/bugs/stories/bugs/xx-bug-hidden-comments.txt 2010-04-01 18:39:29 +0000
22@@ -8,13 +8,13 @@
23 ... 'http://bugs.launchpad.dev'
24 ... '/jokosher/+bug/11')
25 >>> user_browser.getControl(name='field.comment').value = (
26- ... 'This comment will not visible when the test completes.')
27+ ... 'This comment will not be visible when the test completes.')
28 >>> user_browser.getControl('Post Comment', index=-1).click()
29 >>> main_content = find_main_content(user_browser.contents)
30 >>> new_comment = main_content('div', 'boardCommentBody')[-1]
31 >>> new_comment_text = extract_text(new_comment.div)
32 >>> print new_comment_text
33- This comment will not visible when the test completes.
34+ This comment will not be visible when the test completes.
35
36 Admin users can set a message's visible attribute to False.
37 In this case, the last message in the list, the one just added,
38@@ -26,7 +26,7 @@
39 >>> bug_11 = getUtility(IBugSet).get(11)
40 >>> message = bug_11.messages[-1]
41 >>> print message.text_contents
42- This comment will not visible when the test completes.
43+ This comment will not be visible when the test completes.
44 >>> bug_message = getUtility(IBugMessageSet).getByBugAndMessage(
45 ... bug_11, message)
46 >>> bug_message.visible = False
47@@ -46,7 +46,21 @@
48 This title, however, is the same as the bug title and so it will
49 be suppressed in the UI.
50
51-For admin users, the message is still visible.
52+Ordinary users also cannot reach the message via direct link.
53+
54+ >>> comments = find_tags_by_class(
55+ ... user_browser.contents, 'boardComment')
56+ >>> for comment in comments:
57+ ... number_node = comment.find(None, 'bug-comment-index')
58+ ... latest_index = extract_text(number_node)
59+ >>> user_browser.open(
60+ ... 'http://bugs.launchpad.dev'
61+ ... '/jokosher/+bug/11/comments/%d' % (int(latest_index[1:]) + 1))
62+ Traceback (most recent call last):
63+ ...
64+ NotFound...
65+
66+For admin users, the message is still visible in the bug page.
67
68 >>> admin_browser.open(
69 ... 'http://bugs.launchpad.dev'
70@@ -55,10 +69,27 @@
71 >>> last_comment = main_content('div', 'boardCommentBody')[-1]
72 >>> last_comment_text = extract_text(last_comment.div)
73 >>> print last_comment_text
74- This comment will not visible when the test completes.
75+ This comment will not be visible when the test completes.
76
77-Also, admin users will see the hidden message grayed out via an
78+Admin users will see the hidden message highlighted with an
79 'adminHiddenComment' style.
80
81 >>> print last_comment.parent['class']
82 boardComment adminHiddenComment
83+
84+Admin users can also reach the message via direct link, and it is
85+highlighted with the 'adminHiddenComment style there too.
86+
87+ >>> admin_browser.open(
88+ ... 'http://bugs.launchpad.dev'
89+ ... '/jokosher/+bug/11/comments/%d' % (int(latest_index[1:]) + 1))
90+ >>> contents = extract_text(admin_browser.contents)
91+ >>> print contents
92+ Comment #7 : Bug #11 ...
93+ This comment will not be visible when the test completes.
94+ ...
95+ >>> main_content = find_main_content(admin_browser.contents)
96+ >>> last_comment = main_content('div', 'boardCommentBody')[-1]
97+ >>> last_comment_text = extract_text(last_comment.div)
98+ >>> print last_comment.parent['class']
99+ boardComment adminHiddenComment