43
43
from lp.bugs.browser.structuralsubscription import (
44
44
expose_structural_subscription_data_to_js,
46
from lp.bugs.enum import BugNotificationLevel, HIDDEN_BUG_NOTIFICATION_LEVELS
46
from lp.bugs.enum import BugNotificationLevel
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. 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]
124
# We reorder the items so that COMMENTS comes first.
125
for level in sorted(BugNotificationLevel.items, reverse=True)]
129
126
bug_notification_vocabulary = SimpleVocabulary(
130
127
bug_notification_level_terms)
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):
129
if self.current_user_subscription is not None:
135
130
default_value = (
136
131
self.current_user_subscription.bug_notification_level)
233
228
def _update_subscription_term(self):
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"
229
label = "update my current subscription"
238
230
return SimpleTerm(
239
231
'update-subscription', 'update-subscription', label)
247
239
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")
250
252
def _subscription_field(self):
251
253
subscription_terms = []
252
254
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)
253
258
for person in self._subscribers_for_current_user:
254
259
if person.id == self.user.id:
255
if (self._use_advanced_features and
256
(self.user_is_subscribed_directly or
257
self.user_is_muted)):
261
# We've already added the unmute option.
264
if (self._use_advanced_features and
265
self.user_is_subscribed_directly):
258
266
subscription_terms.append(
259
267
self._update_subscription_term)
260
subscription_terms.insert(
261
0, self._unsubscribe_current_user_term)
262
self_subscribed = True
268
subscription_terms.insert(
269
0, self._unsubscribe_current_user_term)
270
self_subscribed = True
264
272
subscription_terms.append(
267
275
'unsubscribe <a href="%s">%s</a> from this bug' % (
268
276
canonical_url(person),
269
277
cgi.escape(person.displayname))))
270
if not self_subscribed:
278
if not self_subscribed and not is_really_muted:
271
279
subscription_terms.insert(0,
273
281
self.user, self.user.name, 'subscribe me to this bug'))
322
330
# subscribe theirself or unsubscribe their team.
323
331
self.widgets['subscription'].visible = True
325
if (self.user_is_subscribed and
326
self.user_is_subscribed_to_dupes_only):
333
if (self.user_is_subscribed_to_dupes_only or
334
(self._use_advanced_features and self.user_is_muted and
335
not self.user_is_subscribed)):
327
336
# If the user is subscribed via a duplicate but is not
328
337
# directly subscribed, we hide the
329
338
# bug_notification_level field, since it's not used.
337
346
def user_is_subscribed_directly(self):
338
347
"""Is the user subscribed directly to this bug?"""
340
self.context.bug.isSubscribed(self.user) and not
348
return self.context.bug.isSubscribed(self.user)
344
351
def user_is_subscribed_to_dupes(self):
345
352
"""Is the user subscribed to dupes of this bug?"""
347
self.context.bug.isSubscribedToDupes(self.user) and not
353
return self.context.bug.isSubscribedToDupes(self.user)
351
356
def user_is_subscribed(self):
389
394
if (subscription_person == self._update_subscription_term.value and
390
395
(self.user_is_subscribed or self.user_is_muted)):
391
self._handleUpdateSubscription(level=bug_notification_level)
396
if self.user_is_muted:
398
if self.user_is_subscribed:
399
self._handleUpdateSubscription(level=bug_notification_level)
401
self._handleSubscribe(level=bug_notification_level)
392
402
elif self.user_is_muted and subscription_person == self.user:
393
self._handleUnsubscribeCurrentUser()
394
404
elif (not self.user_is_subscribed and
395
405
(subscription_person == self.user)):
396
406
self._handleSubscribe(bug_notification_level)
412
422
self._handleUnsubscribeOtherUser(user)
424
def _handleUnmute(self):
425
"""Handle an unmute request."""
426
self.context.bug.unmute(self.user, self.user)
414
428
def _handleUnsubscribeCurrentUser(self):
415
429
"""Handle the special cases for unsubscribing the current user.
539
553
for subscription in direct_subscriptions:
540
554
if not check_permission('launchpad.View', subscription.person):
542
if (subscription.bug_notification_level ==
543
BugNotificationLevel.NOTHING):
545
556
if subscription.person == self.user:
546
557
can_unsubscribe = [subscription] + can_unsubscribe
547
558
elif subscription.canBeUnsubscribedByUser(self.user):
624
return "Mute bug mail for bug %s" % self.context.bug.id
635
if self.context.bug.isMuted(self.user):
636
return "Unmute bug mail for bug %s" % self.context.bug.id
638
return "Mute bug mail for bug %s" % self.context.bug.id
626
640
page_title = label
632
646
cancel_url = next_url
634
648
def initialize(self):
649
self.is_muted = self.context.bug.isMuted(self.user)
635
650
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.
638
if self.context.bug.isMuted(self.user):
639
self.request.response.redirect(
640
canonical_url(self.context, view_name="+subscribe"))
642
@action('Mute bug mail', name='mute')
652
@action('Mute bug mail',
654
condition=lambda form, action: not form.is_muted)
643
655
def mute_action(self, action, data):
644
656
self.context.bug.mute(self.user, self.user)
645
657
self.request.response.addInfoNotification(
646
658
"Mail for bug #%s has been muted." % self.context.bug.id)
660
@action('Unmute bug mail',
662
condition=lambda form, action: form.is_muted)
663
def unmute_action(self, action, data):
664
self.context.bug.unmute(self.user, self.user)
665
self.request.response.addInfoNotification(
666
"Mail for bug #%s has been unmuted." % self.context.bug.id)