~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/browser/bug.py

  • Committer: Gary Poster
  • Date: 2011-05-27 22:55:25 UTC
  • mto: (7675.1194.3 bug-772754-base)
  • mto: This revision was merged to the branch mainline in revision 13243.
  • Revision ID: gary.poster@canonical.com-20110527225525-2bwkwos90r9yi8sw
incremental, to save state.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
    )
38
38
from lazr.lifecycle.event import ObjectModifiedEvent
39
39
from lazr.lifecycle.snapshot import Snapshot
 
40
from lazr.restful.interfaces import IJSONRequestCache
40
41
import pytz
41
42
from zope import formlib
42
43
from zope.app.form.browser import TextWidget
85
86
from lp.app.widgets.itemswidgets import LaunchpadRadioWidgetWithDescription
86
87
from lp.app.widgets.project import ProjectScopeWidget
87
88
from lp.bugs.browser.widgets.bug import BugTagsWidget
 
89
from lp.bugs.enum import BugNotificationLevel
88
90
from lp.bugs.interfaces.bug import (
89
91
    IBug,
90
92
    IBugSet,
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"
288
 
            link = "+subscribe"
 
291
            icon = 'yes'
289
292
        else:
290
293
            text = "Mute bug mail"
291
 
            link = "+mute"
 
294
            icon = 'no'
292
295
 
293
296
        return Link(
294
 
            link, text, icon='remove', summary=(
 
297
            '+mute', text, icon=icon, summary=(
295
298
                "Mute this bug so that you will not receive emails "
296
299
                "about it."))
297
300
 
504
507
        else:
505
508
            return 'subscribed-false %s' % dup_class
506
509
 
507
 
    @property
508
 
    def current_user_subscription_class(self):
509
 
        bug = self.context
510
 
 
511
 
        if bug.personIsSubscribedToDuplicate(self.user):
512
 
            dup_class = 'dup-subscribed-true'
513
 
        else:
514
 
            dup_class = 'dup-subscribed-false'
515
 
 
516
 
        if (bug.personIsDirectSubscriber(self.user) and not
517
 
            bug.isMuted(self.user)):
518
 
            return 'subscribed-true %s' % dup_class
519
 
        else:
520
 
            return 'subscribed-false %s' % dup_class
521
 
 
522
 
    @property
523
 
    def current_user_mute_class(self):
524
 
        bug = self.context
525
 
        subscription_class = self.current_user_subscription_class
526
 
        if self.user_should_see_mute_link:
527
 
            visibility_class = ''
528
 
        else:
529
 
            visibility_class = 'hidden'
530
 
        if bug.isMuted(self.user):
531
 
            return 'muted-true %s %s' % (subscription_class, visibility_class)
532
 
        else:
533
 
            return 'muted-false %s %s' % (
534
 
                subscription_class, visibility_class)
535
 
 
536
510
    @cachedproperty
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
546
 
        else:
547
 
            return False
 
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
548
519
 
549
520
    @cachedproperty
550
521
    def _bug_attachments(self):
643
614
        return ProxiedLibraryFileAlias(
644
615
            attachment.libraryfile, attachment).http_url
645
616
 
 
617
class BugSubscriptionPortletView(BugView):
 
618
 
 
619
    # We want these strings to be available for the template and for the
 
620
    # JavaScript.
 
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 '
 
631
            'reopened.'),
 
632
        'not_direct': _(
 
633
            "not directly subscribed to this bug's notifications."),
 
634
        'muted': _(
 
635
            'Your personal email notifications from this bug are muted.'),
 
636
        }
 
637
 
 
638
    def initialize(self):
 
639
        """Initialize the view to handle the request."""
 
640
        BugView.initialize(self)
 
641
        user = self.user
 
642
        # We are using "direct" to represent both direct and personal
 
643
        # (not team).
 
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
 
651
        self.muted = False
 
652
        if user is not None:
 
653
            bug = self.context
 
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
 
667
                else:
 
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
 
682
 
646
683
 
647
684
class BugWithoutContextView:
648
685
    """View that redirects to the new bug page.