102
104
from lp.bugs.interfaces.bugwatch import IBugWatchSet
103
105
from lp.bugs.interfaces.cve import ICveSet
104
106
from lp.bugs.mail.bugnotificationbuilder import format_rfc2822_date
107
from lp.bugs.model.personsubscriptioninfo import PersonSubscriptions
105
108
from lp.services import features
106
109
from lp.services.fields import DuplicateBug
107
110
from lp.services.propertycache import cachedproperty
285
288
user = getUtility(ILaunchBag).user
286
289
if self.context.bug.isMuted(user):
287
290
text = "Unmute bug mail"
290
293
text = "Mute bug mail"
294
link, text, icon='remove', summary=(
297
'+mute', text, icon=icon, summary=(
295
298
"Mute this bug so that you will not receive emails "
505
508
return 'subscribed-false %s' % dup_class
508
def current_user_subscription_class(self):
511
if bug.personIsSubscribedToDuplicate(self.user):
512
dup_class = 'dup-subscribed-true'
514
dup_class = 'dup-subscribed-false'
516
if (bug.personIsDirectSubscriber(self.user) and not
517
bug.isMuted(self.user)):
518
return 'subscribed-true %s' % dup_class
520
return 'subscribed-false %s' % dup_class
523
def current_user_mute_class(self):
525
subscription_class = self.current_user_subscription_class
526
if self.user_should_see_mute_link:
527
visibility_class = ''
529
visibility_class = 'hidden'
530
if bug.isMuted(self.user):
531
return 'muted-true %s %s' % (subscription_class, visibility_class)
533
return 'muted-false %s %s' % (
534
subscription_class, visibility_class)
537
511
def user_should_see_mute_link(self):
538
512
"""Return True if the user should see the Mute link."""
539
if features.getFeatureFlag('malone.advanced-subscriptions.enabled'):
540
user_is_subscribed = (
541
self.context.isMuted(self.user) or
542
self.context.isSubscribed(self.user) or
543
self.context.isSubscribedToDupes(self.user) or
544
self.context.personIsAlsoNotifiedSubscriber(self.user))
545
return user_is_subscribed
513
user_is_subscribed = (
514
self.context.isMuted(self.user) or
515
self.context.isSubscribed(self.user) or
516
self.context.isSubscribedToDupes(self.user) or
517
self.context.personIsAlsoNotifiedSubscriber(self.user))
518
return user_is_subscribed
550
521
def _bug_attachments(self):
643
614
return ProxiedLibraryFileAlias(
644
615
attachment.libraryfile, attachment).http_url
617
class BugSubscriptionPortletView(BugView):
619
# We want these strings to be available for the template and for the
621
notifications_text = {
622
'not_only_other_subscription': _('You are'),
623
'only_other_subscription': _(
624
'You have subscriptions that may cause you to receive '
625
'notifications, but you are'),
626
'direct_all': _('subscribed to all notifications for this bug.'),
627
'direct_metadata': _(
628
'subscribed to all notifications except comments for this bug.'),
629
'direct_lifecycle': _(
630
'subscribed to notifications when this bug is closed or '
633
"not directly subscribed to this bug's notifications."),
635
'Your personal email notifications from this bug are muted.'),
638
def initialize(self):
639
"""Initialize the view to handle the request."""
640
BugView.initialize(self)
642
# We are using "direct" to represent both direct and personal
644
self.direct_notifications = False
645
self.direct_all_notifications = False
646
self.direct_metadata_notifications = False
647
self.direct_lifecycle_notifications = False
648
self.other_subscription_notifications = False
649
self.only_other_subscription_notifications = False
650
self.any_subscription_notifications = False
654
cache = IJSONRequestCache(self.request).objects
655
cache['notifications_text'] = self.notifications_text
656
self.muted = bug.isMuted(user)
657
psi = PersonSubscriptions(user, bug)
658
if psi.direct.personal:
659
self.direct_notifications = True
660
direct = psi.direct.personal[0]
661
cache['subscription'] = direct.subscription
662
level = direct.subscription.bug_notification_level
663
if level == BugNotificationLevel.COMMENTS:
664
self.direct_all_notifications = True
665
elif level == BugNotificationLevel.METADATA:
666
self.direct_metadata_notifications = True
668
assert level == BugNotificationLevel.LIFECYCLE
669
self.direct_lifecycle_notifications = True
670
self.other_subscription_notifications = (
671
psi.from_duplicate.count or
672
psi.as_owner.count or
673
psi.as_assignee.count or
674
psi.direct.as_team_member or
675
psi.direct.as_team_admin)
676
cache['other_subscription_notifications'] = (
677
self.other_subscription_notifications
678
self.only_other_subscription_notifications = (
679
self.other_subscription_notifications and
680
not self.direct_notifications)
681
self.any_subscription_notifications = psi.count > 0
647
684
class BugWithoutContextView:
648
685
"""View that redirects to the new bug page.