43
43
from lp.bugs.browser.structuralsubscription import (
44
44
expose_structural_subscription_data_to_js,
46
from lp.bugs.enum import BugNotificationLevel
46
from lp.bugs.enum import BugNotificationLevel, HIDDEN_BUG_NOTIFICATION_LEVELS
47
47
from lp.bugs.interfaces.bugsubscription import IBugSubscription
48
48
from lp.bugs.model.personsubscriptioninfo import PersonSubscriptions
49
49
from lp.bugs.model.structuralsubscription import (
122
122
level, level.title,
123
123
self._bug_notification_level_descriptions[level])
124
# We reorder the items so that COMMENTS comes first.
125
for level in sorted(BugNotificationLevel.items, reverse=True)]
124
# We reorder the items so that COMMENTS comes first. We also
125
# drop the NOTHING option since it just makes the UI
127
for level in sorted(BugNotificationLevel.items, reverse=True)
128
if level not in HIDDEN_BUG_NOTIFICATION_LEVELS]
126
129
bug_notification_vocabulary = SimpleVocabulary(
127
130
bug_notification_level_terms)
129
if self.current_user_subscription is not None:
132
if (self.current_user_subscription is not None and
133
self.current_user_subscription.bug_notification_level not in
134
HIDDEN_BUG_NOTIFICATION_LEVELS):
130
135
default_value = (
131
136
self.current_user_subscription.bug_notification_level)
228
233
def _update_subscription_term(self):
229
label = "update my current subscription"
234
if self.user_is_muted:
235
label = "unmute bug mail from this bug and subscribe me to it"
237
label = "update my current subscription"
230
238
return SimpleTerm(
231
239
'update-subscription', 'update-subscription', label)
239
247
return SimpleTerm(self.user, self.user.name, label)
242
def _unmute_user_term(self):
243
if self.user_is_subscribed_directly:
245
'update-subscription', 'update-subscription',
246
"unmute bug mail from this bug and restore my subscription")
248
return SimpleTerm(self.user, self.user.name,
249
"unmute bug mail from this bug")
252
250
def _subscription_field(self):
253
251
subscription_terms = []
254
252
self_subscribed = False
255
is_really_muted = self._use_advanced_features and self.user_is_muted
257
subscription_terms.insert(0, self._unmute_user_term)
258
253
for person in self._subscribers_for_current_user:
259
254
if person.id == self.user.id:
261
# We've already added the unmute option.
264
if (self._use_advanced_features and
265
self.user_is_subscribed_directly):
255
if (self._use_advanced_features and
256
(self.user_is_subscribed_directly or
257
self.user_is_muted)):
266
258
subscription_terms.append(
267
259
self._update_subscription_term)
268
subscription_terms.insert(
269
0, self._unsubscribe_current_user_term)
270
self_subscribed = True
260
subscription_terms.insert(
261
0, self._unsubscribe_current_user_term)
262
self_subscribed = True
272
264
subscription_terms.append(
276
268
canonical_url(person),
277
269
cgi.escape(person.displayname))))
278
270
if not self_subscribed:
279
if not is_really_muted:
280
subscription_terms.insert(0,
282
self.user, self.user.name,
283
'subscribe me to this bug'))
284
elif not self.user_is_subscribed_directly:
285
subscription_terms.insert(0,
287
'update-subscription', 'update-subscription',
288
'unmute bug mail from this bug and subscribe me to '
271
subscription_terms.insert(0,
273
self.user, self.user.name, 'subscribe me to this bug'))
291
275
# Add punctuation to the list of terms.
292
276
if len(subscription_terms) > 1:
298
282
subscription_vocabulary = SimpleVocabulary(subscription_terms)
299
283
if (self._use_advanced_features and
300
(self.user_is_subscribed_directly or self.user_is_muted)):
284
self.user_is_subscribed_directly):
301
285
default_subscription_value = self._update_subscription_term.value
303
287
default_subscription_value = (
327
311
if self._use_advanced_features:
328
312
self.widgets['bug_notification_level'].widget_class = (
329
313
'bug-notification-level-field')
330
if (len(self.form_fields['subscription'].field.vocabulary)==1):
314
if self._subscriber_count_for_current_user == 0:
331
315
# We hide the subscription widget if the user isn't
332
316
# subscribed, since we know who the subscriber is and we
333
317
# don't need to present them with a single radio button.
338
322
# subscribe theirself or unsubscribe their team.
339
323
self.widgets['subscription'].visible = True
341
if self.user_is_subscribed_to_dupes_only:
325
if (self.user_is_subscribed and
326
self.user_is_subscribed_to_dupes_only):
342
327
# If the user is subscribed via a duplicate but is not
343
328
# directly subscribed, we hide the
344
329
# bug_notification_level field, since it's not used.
352
337
def user_is_subscribed_directly(self):
353
338
"""Is the user subscribed directly to this bug?"""
354
return self.context.bug.isSubscribed(self.user)
340
self.context.bug.isSubscribed(self.user) and not
357
344
def user_is_subscribed_to_dupes(self):
358
345
"""Is the user subscribed to dupes of this bug?"""
359
return self.context.bug.isSubscribedToDupes(self.user)
347
self.context.bug.isSubscribedToDupes(self.user) and not
362
351
def user_is_subscribed(self):
400
389
if (subscription_person == self._update_subscription_term.value and
401
390
(self.user_is_subscribed or self.user_is_muted)):
402
if self.user_is_muted:
404
if self.user_is_subscribed:
405
self._handleUpdateSubscription(level=bug_notification_level)
407
self._handleSubscribe(level=bug_notification_level)
391
self._handleUpdateSubscription(level=bug_notification_level)
408
392
elif self.user_is_muted and subscription_person == self.user:
393
self._handleUnsubscribeCurrentUser()
410
394
elif (not self.user_is_subscribed and
411
395
(subscription_person == self.user)):
412
396
self._handleSubscribe(bug_notification_level)
418
402
"""Handle a subscribe request."""
419
403
self.context.bug.subscribe(self.user, self.user, level=level)
420
404
self.request.response.addNotification(
421
"You have subscribed to this bug report.")
405
"You have been subscribed to this bug.")
423
407
def _handleUnsubscribe(self, user):
424
408
"""Handle an unsubscribe request."""
428
412
self._handleUnsubscribeOtherUser(user)
430
def _handleUnmute(self):
431
"""Handle an unmute request."""
432
self.context.bug.unmute(self.user, self.user)
434
414
def _handleUnsubscribeCurrentUser(self):
435
415
"""Handle the special cases for unsubscribing the current user.
476
456
subscription = self.current_user_subscription
477
457
subscription.bug_notification_level = level
478
458
self.request.response.addNotification(
479
"Your bug report subscription has been updated.")
459
"Your subscription to this bug has been updated.")
481
461
def _getUnsubscribeNotification(self, user, unsubed_dupes):
482
462
"""Construct and return the unsubscribe-from-bug feedback message.
559
539
for subscription in direct_subscriptions:
560
540
if not check_permission('launchpad.View', subscription.person):
542
if (subscription.bug_notification_level ==
543
BugNotificationLevel.NOTHING):
562
545
if subscription.person == self.user:
563
546
can_unsubscribe = [subscription] + can_unsubscribe
564
547
elif subscription.canBeUnsubscribedByUser(self.user):
624
return "Mute bug mail for bug %s" % self.context.bug.id
630
return canonical_url(self.context)
632
cancel_url = next_url
634
def initialize(self):
635
super(BugMuteSelfView, self).initialize()
636
# If the user is already muted, redirect them to the +subscribe
637
# page, since there's no point doing its work twice.
641
638
if self.context.bug.isMuted(self.user):
642
return "Unmute bug mail for bug %s" % self.context.bug.id
644
return "Mute bug mail for bug %s" % self.context.bug.id
650
return canonical_url(self.context)
652
cancel_url = next_url
654
def initialize(self):
655
self.is_muted = self.context.bug.isMuted(self.user)
656
super(BugMuteSelfView, self).initialize()
658
@action('Mute bug mail',
660
condition=lambda form, action: not form.is_muted)
639
self.request.response.redirect(
640
canonical_url(self.context, view_name="+subscribe"))
642
@action('Mute bug mail', name='mute')
661
643
def mute_action(self, action, data):
662
644
self.context.bug.mute(self.user, self.user)
663
645
self.request.response.addInfoNotification(
664
646
"Mail for bug #%s has been muted." % self.context.bug.id)
666
@action('Unmute bug mail',
668
condition=lambda form, action: form.is_muted)
669
def unmute_action(self, action, data):
670
self.context.bug.unmute(self.user, self.user)
671
self.request.response.addInfoNotification(
672
"Mail for bug #%s has been unmuted." % self.context.bug.id)