Merge lp:~gary/launchpad/bug-772763-edit-subscription into lp:launchpad/db-devel

Proposed by Gary Poster
Status: Merged
Approved by: Brad Crittenden
Approved revision: no longer in the source branch.
Merged at revision: 10585
Proposed branch: lp:~gary/launchpad/bug-772763-edit-subscription
Merge into: lp:launchpad/db-devel
Diff against target: 211 lines (+41/-61)
2 files modified
lib/lp/bugs/browser/bugsubscription.py (+29/-27)
lib/lp/bugs/browser/tests/test_bugsubscription_views.py (+12/-34)
To merge this branch: bzr merge lp:~gary/launchpad/bug-772763-edit-subscription
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Review via email: mp+61782@code.launchpad.net

Commit message

[incr] [r=bac][bug=772763] make the +subscribe page, shown as a form overlay when you subscribe or edit a subscription, have options that are pertinent to the new unmute functionality

Description of the change

This branch, primarily from Danilo, builds on the other mute work we have done recently to make unmuting restore previous direct bug subscriptions.

The only goal of this branch is to make the +subscribe page, shown as a form overlay when you subscribe or edit a subscription, have options that are pertinent to the new functionality. These changes are made, and tests are adjusted accordingly.

We no longer offer the option to unmute and edit your subscription simultaneously (and in fact unmuting will typically be done with a simple API-backed click in the UI rather than this form) so I removed the test for that case.

The UI is a bit odd after this branch in two ways. First, it relies on the JS branch that I mentioned before to be completely resolved. Second, in some cases it will show a single (pre-selected) radio button option. I would worry more about this if we were not about to readdress the entire UI for bug 772754, and if this were not a db-devel branch.

Thank you!

Gary

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

Gary this branch looks good save for the line we discussed on IRC that is oddly formatted:

if not self_subscribed and not(is_really_muted):

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/bugsubscription.py'
2--- lib/lp/bugs/browser/bugsubscription.py 2011-05-18 08:17:35 +0000
3+++ lib/lp/bugs/browser/bugsubscription.py 2011-05-20 17:53:00 +0000
4@@ -211,14 +211,6 @@
5 persons_for_user[person.id] = person
6 person_count += 1
7
8- # The view code previously expected a 'mute' to be a subscription
9- # as well. Since it is not anymore, we add the user to the
10- # subscribers list as needed.
11- if self.user_is_muted:
12- if self.user.id not in persons_for_user:
13- persons_for_user[self.user.id] = self.user
14- person_count += 1
15-
16 self._subscriber_count_for_current_user = person_count
17 return persons_for_user.values()
18
19@@ -234,10 +226,7 @@
20
21 @cachedproperty
22 def _update_subscription_term(self):
23- if self.user_is_muted:
24- label = "unmute bug mail from this bug and subscribe me to it"
25- else:
26- label = "update my current subscription"
27+ label = "update my current subscription"
28 return SimpleTerm(
29 'update-subscription', 'update-subscription', label)
30
31@@ -250,19 +239,35 @@
32 return SimpleTerm(self.user, self.user.name, label)
33
34 @cachedproperty
35+ def _unmute_user_term(self):
36+ if self.user_is_subscribed_directly:
37+ return SimpleTerm(
38+ 'update-subscription', 'update-subscription',
39+ "unmute bug mail from this bug and restore my subscription")
40+ else:
41+ return SimpleTerm(self.user, self.user.name,
42+ "unmute bug mail from this bug")
43+
44+ @cachedproperty
45 def _subscription_field(self):
46 subscription_terms = []
47 self_subscribed = False
48+ is_really_muted = self._use_advanced_features and self.user_is_muted
49+ if is_really_muted:
50+ subscription_terms.insert(0, self._unmute_user_term)
51 for person in self._subscribers_for_current_user:
52 if person.id == self.user.id:
53- if (self._use_advanced_features and
54- (self.user_is_subscribed_directly or
55- self.user_is_muted)):
56+ if is_really_muted:
57+ # We've already added the unmute option.
58+ continue
59+ else:
60+ if (self._use_advanced_features and
61+ self.user_is_subscribed_directly):
62 subscription_terms.append(
63 self._update_subscription_term)
64- subscription_terms.insert(
65- 0, self._unsubscribe_current_user_term)
66- self_subscribed = True
67+ subscription_terms.insert(
68+ 0, self._unsubscribe_current_user_term)
69+ self_subscribed = True
70 else:
71 subscription_terms.append(
72 SimpleTerm(
73@@ -270,7 +275,7 @@
74 'unsubscribe <a href="%s">%s</a> from this bug' % (
75 canonical_url(person),
76 cgi.escape(person.displayname))))
77- if not self_subscribed:
78+ if not self_subscribed and not is_really_muted:
79 subscription_terms.insert(0,
80 SimpleTerm(
81 self.user, self.user.name, 'subscribe me to this bug'))
82@@ -325,8 +330,9 @@
83 # subscribe theirself or unsubscribe their team.
84 self.widgets['subscription'].visible = True
85
86- if (self.user_is_subscribed and
87- self.user_is_subscribed_to_dupes_only):
88+ if (self.user_is_subscribed_to_dupes_only or
89+ (self._use_advanced_features and self.user_is_muted and
90+ not self.user_is_subscribed)):
91 # If the user is subscribed via a duplicate but is not
92 # directly subscribed, we hide the
93 # bug_notification_level field, since it's not used.
94@@ -339,16 +345,12 @@
95 @cachedproperty
96 def user_is_subscribed_directly(self):
97 """Is the user subscribed directly to this bug?"""
98- return (
99- self.context.bug.isSubscribed(self.user) and not
100- self.user_is_muted)
101+ return self.context.bug.isSubscribed(self.user)
102
103 @cachedproperty
104 def user_is_subscribed_to_dupes(self):
105 """Is the user subscribed to dupes of this bug?"""
106- return (
107- self.context.bug.isSubscribedToDupes(self.user) and not
108- self.user_is_muted)
109+ return self.context.bug.isSubscribedToDupes(self.user)
110
111 @property
112 def user_is_subscribed(self):
113
114=== modified file 'lib/lp/bugs/browser/tests/test_bugsubscription_views.py'
115--- lib/lp/bugs/browser/tests/test_bugsubscription_views.py 2011-05-17 11:44:33 +0000
116+++ lib/lp/bugs/browser/tests/test_bugsubscription_views.py 2011-05-20 17:53:00 +0000
117@@ -5,8 +5,6 @@
118
119 __metaclass__ = type
120
121-import transaction
122-
123 from canonical.launchpad.ftests import LaunchpadFormHarness
124 from canonical.launchpad.webapp import canonical_url
125 from canonical.testing.layers import LaunchpadFunctionalLayer
126@@ -231,15 +229,14 @@
127 harness.view.widgets['bug_notification_level'].visible)
128
129 def test_muted_subs_have_unmute_option(self):
130- # If a user has a muted subscription, the
131- # BugSubscriptionSubscribeSelfView's subscription field will
132- # show an "Unmute" option.
133+ # If a user has a muted subscription, but no previous
134+ # direct bug subscription, the BugSubscriptionSubscribeSelfView's
135+ # subscription field will show an "Unmute" option.
136 with person_logged_in(self.person):
137 self.bug.mute(self.person, self.person)
138
139 with FeatureFixture({self.feature_flag: ON}):
140 with person_logged_in(self.person):
141- self.bug.mute(self.person, self.person)
142 subscribe_view = create_initialized_view(
143 self.bug.default_bugtask, name='+subscribe')
144 subscription_widget = (
145@@ -247,15 +244,17 @@
146 # The Unmute option is actually treated the same way as
147 # the unsubscribe option.
148 self.assertEqual(
149- "unmute bug mail from this bug, or",
150+ "unmute bug mail from this bug",
151 subscription_widget.vocabulary.getTerm(self.person).title)
152
153- def test_muted_subs_have_unmute_and_update_option(self):
154+ def test_muted_subs_have_unmute_and_restore_option(self):
155 # If a user has a muted subscription, the
156 # BugSubscriptionSubscribeSelfView's subscription field will
157- # show an option to unmute the subscription and update it to a
158- # new BugNotificationLevel.
159+ # show an option to unmute the subscription and restore it to a
160+ # previous or new BugNotificationLevel.
161 with person_logged_in(self.person):
162+ self.bug.subscribe(self.person, self.person,
163+ level=BugNotificationLevel.COMMENTS)
164 self.bug.mute(self.person, self.person)
165
166 with FeatureFixture({self.feature_flag: ON}):
167@@ -267,12 +266,13 @@
168 update_term = subscription_widget.vocabulary.getTermByToken(
169 'update-subscription')
170 self.assertEqual(
171- "unmute bug mail from this bug and subscribe me to it.",
172+ "unmute bug mail from this bug and restore my "
173+ "subscription",
174 update_term.title)
175
176 def test_unmute_unmutes(self):
177 # Using the "Unmute bug mail" option when the user has a muted
178- # subscription will remove the muted subscription.
179+ # subscription will unmute.
180 with person_logged_in(self.person):
181 self.bug.mute(self.person, self.person)
182
183@@ -290,28 +290,6 @@
184 self.assertFalse(self.bug.isMuted(self.person))
185 self.assertFalse(self.bug.isSubscribed(self.person))
186
187- def test_update_when_muted_updates(self):
188- # Using the "Unmute and subscribe me" option when the user has a
189- # muted subscription will update the existing subscription to a
190- # new BugNotificationLevel.
191- with person_logged_in(self.person):
192- self.bug.mute(self.person, self.person)
193-
194- with FeatureFixture({self.feature_flag: ON}):
195- with person_logged_in(self.person):
196- level = BugNotificationLevel.COMMENTS
197- form_data = {
198- 'field.subscription': 'update-subscription',
199- 'field.bug_notification_level': level.title,
200- 'field.actions.continue': 'Continue',
201- }
202- create_initialized_view(
203- self.bug.default_bugtask, form=form_data,
204- name='+subscribe')
205- transaction.commit()
206- self.assertFalse(self.bug.isMuted(self.person))
207- self.assertTrue(self.bug.isSubscribed(self.person))
208-
209 def test_bug_notification_level_field_has_widget_class(self):
210 # The bug_notification_level widget has a widget_class property
211 # that can be used to manipulate it with JavaScript.

Subscribers

People subscribed via source and target branches

to status/vote changes: