Merge lp:~thumper/launchpad/linked-bug-visibility into lp:launchpad

Proposed by Tim Penhey
Status: Merged
Approved by: Stuart Bishop
Approved revision: no longer in the source branch.
Merged at revision: 11006
Proposed branch: lp:~thumper/launchpad/linked-bug-visibility
Merge into: lp:launchpad
Diff against target: 47 lines (+17/-2)
2 files modified
lib/lp/code/browser/branch.py (+2/-2)
lib/lp/code/browser/tests/test_branch.py (+15/-0)
To merge this branch: bzr merge lp:~thumper/launchpad/linked-bug-visibility
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+27466@code.launchpad.net

Commit message

Check the bug visibility before trying to access other properties.

Description of the change

In my fix on Friday to not show resolved bugs on the branch page for series branches, I created a bug where the view class is trying to get access to properties of the bug even if the user cannot see the bug due to bug privacy. This causes a 403 to be shown to the user.

tests:
  test_linked_bugs_privacy

QA:
  look at lp:~software-store-developers/software-center/trunk to see if it renders

No pre implementation call. I found this while QAing the other bug.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/browser/branch.py'
2--- lib/lp/code/browser/branch.py 2010-06-11 05:05:43 +0000
3+++ lib/lp/code/browser/branch.py 2010-06-14 02:46:26 +0000
4@@ -34,7 +34,6 @@
5 import cgi
6 from collections import defaultdict
7 from datetime import datetime, timedelta
8-from operator import attrgetter
9
10 import pytz
11 import simplejson
12@@ -378,7 +377,8 @@
13 for bug, task in self.branch.getLinkedBugsAndTasks():
14 bugs[bug].append(task)
15 return [DecoratedBug(bug, self.branch, tasks)
16- for bug, tasks in bugs.iteritems()]
17+ for bug, tasks in bugs.iteritems()
18+ if check_permission('launchpad.View', bug)]
19
20 @property
21 def displayname(self):
22
23=== modified file 'lib/lp/code/browser/tests/test_branch.py'
24--- lib/lp/code/browser/tests/test_branch.py 2010-06-11 03:21:09 +0000
25+++ lib/lp/code/browser/tests/test_branch.py 2010-06-14 02:46:26 +0000
26@@ -280,6 +280,21 @@
27 self.assertEqual(len(BugTaskStatus), len(view.linked_bugs))
28 self.assertFalse(view.context.is_series_branch)
29
30+ def test_linked_bugs_privacy(self):
31+ # If a linked bug is private, it is not in the linked bugs if the user
32+ # can't see it.
33+ branch = self.factory.makeAnyBranch()
34+ reporter = self.factory.makePerson()
35+ bug = self.factory.makeBug(private=True, owner=reporter)
36+ with person_logged_in(reporter):
37+ branch.linkBug(bug, reporter)
38+ view = create_initialized_view(branch, '+index')
39+ # Comparing bug ids as the linked bugs are decorated bugs.
40+ self.assertEqual([bug.id], [bug.id for bug in view.linked_bugs])
41+ with person_logged_in(branch.owner):
42+ view = create_initialized_view(branch, '+index')
43+ self.assertEqual([], view.linked_bugs)
44+
45 def test_linked_bugs_series_branch(self):
46 # The linked bugs for a series branch shows only unresolved bugs.
47 product = self.factory.makeProduct()