← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~gmb/launchpad/non-js-muting-bug-734732 into lp:launchpad

 

Graham Binns has proposed merging lp:~gmb/launchpad/non-js-muting-bug-734732 into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #734732 in Launchpad itself: "Muting a bug should have a non JS fallback"
  https://bugs.launchpad.net/launchpad/+bug/734732

For more details, see:
https://code.launchpad.net/~gmb/launchpad/non-js-muting-bug-734732/+merge/53981

This branch adds a BugTask:+mute view, so that stick-in-the muds who use
console-based browsers (RMS, I'm looking at you here) and people who use
browsers that don't play nice with YUI 3 (IE, now I'm looking at you)
can still use the mute / unmute functionality.

The +mute view presents a single button that allows the user to mute or
unmute bug mail for a bug. If the +mute page is visited by a user who
already holds a mute on the bug, they'll be redirected to the +subscribe
page, which handles the unmuting (and resubscribing if desired) story.
-- 
https://code.launchpad.net/~gmb/launchpad/non-js-muting-bug-734732/+merge/53981
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~gmb/launchpad/non-js-muting-bug-734732 into lp:launchpad.
=== modified file 'lib/lp/bugs/browser/bug.py'
--- lib/lp/bugs/browser/bug.py	2011-03-10 12:42:35 +0000
+++ lib/lp/bugs/browser/bug.py	2011-03-18 12:47:34 +0000
@@ -281,10 +281,8 @@
         else:
             text = "Mute bug mail"
 
-        # We link to '#' here because we don't yet have a view to handle
-        # this link.
         return Link(
-            '#', text, icon='remove', summary=(
+            '+mute', text, icon='remove', summary=(
                 "Mute this bug so that you will never receive emails "
                 "about it."))
 

=== modified file 'lib/lp/bugs/browser/bugsubscription.py'
--- lib/lp/bugs/browser/bugsubscription.py	2011-03-16 13:26:30 +0000
+++ lib/lp/bugs/browser/bugsubscription.py	2011-03-18 12:47:34 +0000
@@ -6,6 +6,7 @@
 __metaclass__ = type
 __all__ = [
     'AdvancedSubscriptionMixin',
+    'BugMuteSelfView',
     'BugPortletDuplicateSubcribersContents',
     'BugPortletSubcribersContents',
     'BugSubscriptionAddView',
@@ -584,3 +585,36 @@
     @property
     def structural_subscriptions(self):
         return self.context.bug.getStructuralSubscriptionsForPerson(self.user)
+
+
+class BugMuteSelfView(LaunchpadFormView):
+    """A view to mute a user's bug mail for a given bug."""
+
+    schema = IBugSubscription
+    field_names = []
+
+    @property
+    def label(self):
+        return "Mute bug mail for bug %s" % self.context.bug.id
+
+    page_title = label
+
+    @property
+    def next_url(self):
+        return canonical_url(self.context)
+
+    cancel_url = next_url
+
+    def initialize(self):
+        super(BugMuteSelfView, self).initialize()
+        # If the user is already muted, redirect them to the +subscribe
+        # page, since there's no point doing its work twice.
+        if self.context.bug.isMuted(self.user):
+            self.request.response.redirect(
+                canonical_url(self.context, view_name="+subscribe"))
+
+    @action('Mute bug mail', name='mute')
+    def mute_action(self, action, data):
+        self.context.bug.mute(self.user, self.user)
+        self.request.response.addInfoNotification(
+            "Bug mail for bug #%s has been muted." % self.context.bug.id)

=== modified file 'lib/lp/bugs/browser/configure.zcml'
--- lib/lp/bugs/browser/configure.zcml	2011-03-15 02:17:01 +0000
+++ lib/lp/bugs/browser/configure.zcml	2011-03-18 12:47:34 +0000
@@ -713,6 +713,12 @@
             permission="launchpad.AnyPerson"
             template="../templates/bug-subscription.pt"/>
         <browser:page
+            for="lp.bugs.interfaces.bugtask.IBugTask"
+            name="+mute"
+            class="lp.bugs.browser.bugsubscription.BugMuteSelfView"
+            permission="launchpad.AnyPerson"
+            template="../templates/bug-mute.pt"/>
+        <browser:page
             name="+linkcve"
             for="lp.bugs.interfaces.bugtask.IBugTask"
             class="lp.bugs.browser.cve.CveLinkView"

=== modified file 'lib/lp/bugs/browser/tests/test_bugsubscription_views.py'
--- lib/lp/bugs/browser/tests/test_bugsubscription_views.py	2011-03-16 13:26:30 +0000
+++ lib/lp/bugs/browser/tests/test_bugsubscription_views.py	2011-03-18 12:47:34 +0000
@@ -6,6 +6,7 @@
 __metaclass__ = type
 
 from canonical.launchpad.ftests import LaunchpadFormHarness
+from canonical.launchpad.webapp import canonical_url
 from canonical.testing.layers import LaunchpadFunctionalLayer
 
 from lp.bugs.browser.bugsubscription import (
@@ -444,3 +445,38 @@
                 decorator.subscription for decorator in
                 view.sorted_direct_subscriptions]
             self.assertFalse(subscription in sorted_subscriptions)
+
+
+class BugMuteSelfViewTestCase(TestCaseWithFactory):
+    """Tests for the BugMuteSelfView."""
+
+    layer = LaunchpadFunctionalLayer
+
+    def setUp(self):
+        super(BugMuteSelfViewTestCase, self).setUp()
+        self.bug = self.factory.makeBug()
+        self.person = self.factory.makePerson()
+
+    def test_bug_mute_self_view_mutes_bug(self):
+        # The BugMuteSelfView mutes bug mail for the current user when
+        # its form is submitted.
+        with person_logged_in(self.person):
+            mute_view = create_initialized_view(
+                self.bug.default_bugtask, name="+mute",
+                form={'field.actions.mute': 'Mute bug mail'})
+            self.assertTrue(self.bug.isMuted(self.person))
+
+    def test_bug_mute_self_view_redirects_muted_users(self):
+        # The BugMuteSelfView redirects muted users to the +subscribe
+        # page, where they can remove their muted subscription or change
+        # their BugNotificationLevel.
+        with person_logged_in(self.person):
+            self.bug.mute(self.person, self.person)
+            mute_view = create_initialized_view(
+                self.bug.default_bugtask, name="+mute")
+            response = mute_view.request.response
+            self.assertEqual(302, response.getStatus())
+            self.assertEqual(
+                canonical_url(self.bug.default_bugtask,
+                    view_name="+subscribe"),
+                response.getHeader('Location'))

=== added file 'lib/lp/bugs/templates/bug-mute.pt'
--- lib/lp/bugs/templates/bug-mute.pt	1970-01-01 00:00:00 +0000
+++ lib/lp/bugs/templates/bug-mute.pt	2011-03-18 12:47:34 +0000
@@ -0,0 +1,32 @@
+<html
+  xmlns="http://www.w3.org/1999/xhtml";
+  xmlns:tal="http://xml.zope.org/namespaces/tal";
+  xmlns:metal="http://xml.zope.org/namespaces/metal";
+  xmlns:i18n="http://xml.zope.org/namespaces/i18n";
+  xml:lang="en"
+  lang="en"
+  dir="ltr"
+  metal:use-macro="view/macro:page/main_only"
+  i18n:domain="malone"
+>
+
+<body>
+  <div metal:fill-slot="main">
+
+    <div id="maincontent">
+      <div id="nonportlets" class="readable">
+        <p>
+          If you mute a bug you will receive no email about the the bug
+          at all until you unmute it again.
+        </p>
+
+        <div metal:use-macro="context/@@launchpad_form/form">
+        </div>
+
+      </div>
+    </div>
+
+  </div>
+
+</body>
+</html>