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
=== modified file 'lib/lp/code/browser/branch.py'
--- lib/lp/code/browser/branch.py 2010-06-11 05:05:43 +0000
+++ lib/lp/code/browser/branch.py 2010-06-14 02:46:26 +0000
@@ -34,7 +34,6 @@
34import cgi34import cgi
35from collections import defaultdict35from collections import defaultdict
36from datetime import datetime, timedelta36from datetime import datetime, timedelta
37from operator import attrgetter
3837
39import pytz38import pytz
40import simplejson39import simplejson
@@ -378,7 +377,8 @@
378 for bug, task in self.branch.getLinkedBugsAndTasks():377 for bug, task in self.branch.getLinkedBugsAndTasks():
379 bugs[bug].append(task)378 bugs[bug].append(task)
380 return [DecoratedBug(bug, self.branch, tasks)379 return [DecoratedBug(bug, self.branch, tasks)
381 for bug, tasks in bugs.iteritems()]380 for bug, tasks in bugs.iteritems()
381 if check_permission('launchpad.View', bug)]
382382
383 @property383 @property
384 def displayname(self):384 def displayname(self):
385385
=== modified file 'lib/lp/code/browser/tests/test_branch.py'
--- lib/lp/code/browser/tests/test_branch.py 2010-06-11 03:21:09 +0000
+++ lib/lp/code/browser/tests/test_branch.py 2010-06-14 02:46:26 +0000
@@ -280,6 +280,21 @@
280 self.assertEqual(len(BugTaskStatus), len(view.linked_bugs))280 self.assertEqual(len(BugTaskStatus), len(view.linked_bugs))
281 self.assertFalse(view.context.is_series_branch)281 self.assertFalse(view.context.is_series_branch)
282282
283 def test_linked_bugs_privacy(self):
284 # If a linked bug is private, it is not in the linked bugs if the user
285 # can't see it.
286 branch = self.factory.makeAnyBranch()
287 reporter = self.factory.makePerson()
288 bug = self.factory.makeBug(private=True, owner=reporter)
289 with person_logged_in(reporter):
290 branch.linkBug(bug, reporter)
291 view = create_initialized_view(branch, '+index')
292 # Comparing bug ids as the linked bugs are decorated bugs.
293 self.assertEqual([bug.id], [bug.id for bug in view.linked_bugs])
294 with person_logged_in(branch.owner):
295 view = create_initialized_view(branch, '+index')
296 self.assertEqual([], view.linked_bugs)
297
283 def test_linked_bugs_series_branch(self):298 def test_linked_bugs_series_branch(self):
284 # The linked bugs for a series branch shows only unresolved bugs.299 # The linked bugs for a series branch shows only unresolved bugs.
285 product = self.factory.makeProduct()300 product = self.factory.makeProduct()