Merge lp:~gmb/launchpad/prevent-bnl-nothing-oopses-bug-721400 into lp:launchpad

Proposed by Graham Binns
Status: Merged
Merged at revision: 12527
Proposed branch: lp:~gmb/launchpad/prevent-bnl-nothing-oopses-bug-721400
Merge into: lp:launchpad
Diff against target: 92 lines (+36/-3)
3 files modified
lib/lp/bugs/browser/bugsubscription.py (+5/-3)
lib/lp/bugs/browser/tests/test_bugsubscription_views.py (+26/-0)
lib/lp/bugs/enum.py (+5/-0)
To merge this branch: bzr merge lp:~gmb/launchpad/prevent-bnl-nothing-oopses-bug-721400
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Review via email: mp+52036@code.launchpad.net

Commit message

[r=allenap][ui=none] [r=allenap][bug=721400] The BugTask:+subscribe page will no longer OOPS if the user already has a subscription with a bug_notification_level of NOTHING.

Description of the change

This branch fixes bug 721400, wherein the BugTask:+subscribe page would
OOPS if the user had an existing subscription with a
bug_notification_level of NOTHING. This value isn't one that's allowed
to be set using the UI, though it is allowed via the API, and the view's
validation code was kicking out the default value.

The fix for the bug was to ensure that we only use the user's existing
bug_notification_level as a default if it's in the set of values that we
allow to appear in the bug_notification_level widget.

I've added a regression test to cover this bug.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/bugs/browser/bugsubscription.py'
--- lib/lp/bugs/browser/bugsubscription.py 2011-02-22 17:17:35 +0000
+++ lib/lp/bugs/browser/bugsubscription.py 2011-03-04 11:03:47 +0000
@@ -39,7 +39,7 @@
39 LaunchpadFormView,39 LaunchpadFormView,
40 )40 )
41from lp.bugs.browser.bug import BugViewMixin41from lp.bugs.browser.bug import BugViewMixin
42from lp.bugs.enum import BugNotificationLevel42from lp.bugs.enum import BugNotificationLevel, HIDDEN_BUG_NOTIFICATION_LEVELS
43from lp.bugs.interfaces.bugsubscription import IBugSubscription43from lp.bugs.interfaces.bugsubscription import IBugSubscription
44from lp.bugs.interfaces.bugtask import IBugTaskSet44from lp.bugs.interfaces.bugtask import IBugTaskSet
45from lp.services import features45from lp.services import features
@@ -118,11 +118,13 @@
118 # drop the NOTHING option since it just makes the UI118 # drop the NOTHING option since it just makes the UI
119 # confusing.119 # confusing.
120 for level in sorted(BugNotificationLevel.items, reverse=True)120 for level in sorted(BugNotificationLevel.items, reverse=True)
121 if level != BugNotificationLevel.NOTHING]121 if level not in HIDDEN_BUG_NOTIFICATION_LEVELS]
122 bug_notification_vocabulary = SimpleVocabulary(122 bug_notification_vocabulary = SimpleVocabulary(
123 bug_notification_level_terms)123 bug_notification_level_terms)
124124
125 if self.current_user_subscription is not None:125 if (self.current_user_subscription is not None and
126 self.current_user_subscription.bug_notification_level not in
127 HIDDEN_BUG_NOTIFICATION_LEVELS):
126 default_value = (128 default_value = (
127 self.current_user_subscription.bug_notification_level)129 self.current_user_subscription.bug_notification_level)
128 else:130 else:
129131
=== modified file 'lib/lp/bugs/browser/tests/test_bugsubscription_views.py'
--- lib/lp/bugs/browser/tests/test_bugsubscription_views.py 2011-02-22 17:17:35 +0000
+++ lib/lp/bugs/browser/tests/test_bugsubscription_views.py 2011-03-04 11:03:47 +0000
@@ -20,6 +20,7 @@
20 set_feature_flag,20 set_feature_flag,
21 TestCaseWithFactory,21 TestCaseWithFactory,
22 )22 )
23from lp.testing.views import create_initialized_view
2324
2425
25class BugSubscriptionAdvancedFeaturesTestCase(TestCaseWithFactory):26class BugSubscriptionAdvancedFeaturesTestCase(TestCaseWithFactory):
@@ -250,6 +251,31 @@
250 self.assertFalse(251 self.assertFalse(
251 harness.view.widgets['bug_notification_level'].visible)252 harness.view.widgets['bug_notification_level'].visible)
252253
254 def test_bug_721400(self):
255 # If a subscription exists with a BugNotificationLevel of
256 # NOTHING the view will still render correctly, even though
257 # NOTHING is not accepted as a valid value for the
258 # bug_notification_level field.
259 # This is a regression test for bug 721400.
260 bug = self.factory.makeBug()
261 person = self.factory.makePerson()
262 with person_logged_in(person):
263 subscription = bug.subscribe(
264 person, person, level=BugNotificationLevel.NOTHING)
265
266 with feature_flags():
267 with person_logged_in(person):
268 subscribe_view = create_initialized_view(
269 bug.default_bugtask, name='+subscribe')
270 self.assertEqual(0, len(subscribe_view.errors))
271 bug_notification_level_widget = (
272 subscribe_view.widgets['bug_notification_level'])
273 default_notification_level_value = (
274 bug_notification_level_widget._getDefault())
275 self.assertEqual(
276 BugNotificationLevel.COMMENTS,
277 default_notification_level_value)
278
253279
254class BugPortletSubcribersIdsTests(TestCaseWithFactory):280class BugPortletSubcribersIdsTests(TestCaseWithFactory):
255281
256282
=== modified file 'lib/lp/bugs/enum.py'
--- lib/lp/bugs/enum.py 2011-02-01 17:52:45 +0000
+++ lib/lp/bugs/enum.py 2011-03-04 11:03:47 +0000
@@ -6,6 +6,7 @@
6__metaclass__ = type6__metaclass__ = type
7__all__ = [7__all__ = [
8 'BugNotificationLevel',8 'BugNotificationLevel',
9 'HIDDEN_BUG_NOTIFICATION_LEVELS',
9 ]10 ]
1011
11from lazr.enum import (12from lazr.enum import (
@@ -47,3 +48,7 @@
47 notifications about new events in the bugs's discussion, like new48 notifications about new events in the bugs's discussion, like new
48 comments.49 comments.
49 """)50 """)
51
52
53# The set of bug notification levels that won't be displayed in the UI.
54HIDDEN_BUG_NOTIFICATION_LEVELS = [BugNotificationLevel.NOTHING]