← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~gmb/launchpad/team-subscription-opt-out into lp:launchpad/db-devel

 

Graham Binns has proposed merging lp:~gmb/launchpad/team-subscription-opt-out into lp:launchpad/db-devel.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~gmb/launchpad/team-subscription-opt-out/+merge/55779

This branch adds a BugSubscriptionFilterMute table to the database and
its associated interface and model to the tree.

The idea behind BugSubscriptionFilterMute is that people should be able
to mute team subscriptions if they want to. The story being that:

 As a member of ~launchpad
 I want to be able to mute emails that I would receive because
 ~launchpad is structurally subscribed to a project
 So that I don't have to read bug mail in which I'm not interested.
-- 
https://code.launchpad.net/~gmb/launchpad/team-subscription-opt-out/+merge/55779
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~gmb/launchpad/team-subscription-opt-out into lp:launchpad/db-devel.
=== modified file 'database/schema/comments.sql'
--- database/schema/comments.sql	2011-03-29 10:17:46 +0000
+++ database/schema/comments.sql	2011-03-31 15:52:35 +0000
@@ -231,6 +231,12 @@
 COMMENT ON COLUMN BugSubscriptionFilterTag.tag IS 'A bug tag.';
 COMMENT ON COLUMN BugSubscriptionFilterTag.include IS 'If True, send only messages for bugs having this tag, else send only messages for bugs which do not have this tag.';
 
+-- BugSubscriptionFilterMute
+COMMENT ON TABLE BugSubscriptionFilterMute IS 'Mutes for subscription filters.';
+COMMENT ON COLUMN BugSubscriptionFilterMute.person IS 'The person that muted their subscription to this filter.';
+COMMENT ON COLUMN BugSubscriptionFilterMute.filter IS 'The subscription filter of this record';
+COMMENT ON COLUMN BugSubscriptionFilterMute.date_created IS 'The date at which this mute was created.';
+
 -- BugTag
 COMMENT ON TABLE BugTag IS 'Attaches simple text tags to a bug.';
 COMMENT ON COLUMN BugTag.bug IS 'The bug the tags is attached to.';

=== added file 'database/schema/patch-2208-99-0.sql'
--- database/schema/patch-2208-99-0.sql	1970-01-01 00:00:00 +0000
+++ database/schema/patch-2208-99-0.sql	2011-03-31 15:52:35 +0000
@@ -0,0 +1,22 @@
+-- Copyright 2011 Canonical Ltd.  This software is licensed under the
+-- GNU Affero General Public License version 3 (see the file LICENSE).
+
+SET client_min_messages=ERROR;
+
+-- A table to store subscription mutes in.
+
+CREATE TABLE BugSubscriptionFilterMute (
+    id serial PRIMARY KEY,
+    person integer REFERENCES Person(id) NOT NULL,
+    filter integer REFERENCES BugSubscriptionFilter(id) 
+        ON DELETE CASCADE NOT NULL,
+    date_created timestamp without time zone
+        DEFAULT timezone('UTC'::text, now())
+);
+
+CREATE INDEX bugsubscriptionfiltermute__bug_subscription_filter
+    ON BugSubscriptionFilterMute(filter);
+CREATE INDEX bugsubscriptionfiltermute__person
+    ON BugSubscriptionFilterMute(person);
+
+INSERT INTO LaunchpadDatabaseRevision VALUES (2208, 99, 0);

=== modified file 'lib/lp/bugs/configure.zcml'
--- lib/lp/bugs/configure.zcml	2011-03-29 05:38:15 +0000
+++ lib/lp/bugs/configure.zcml	2011-03-31 15:52:35 +0000
@@ -642,6 +642,17 @@
           set_schema=".interfaces.bugsubscriptionfilter.IBugSubscriptionFilterAttributes" />
     </class>
 
+    <!-- BugSubscriptionFilterMute -->
+    <class
+        class=".model.bugsubscriptionfilter.BugSubscriptionFilterMute">
+      <allow
+          interface=".interfaces.bugsubscriptionfilter.IBugSubscriptionFilterMute"/>
+      <require
+          permission="launchpad.Edit"
+          set_schema=".interfaces.bugsubscriptionfilter.IBugSubscriptionFilterMute" />
+    </class>
+
+
     <!-- BugSubscriptionInfo -->
 
     <class class=".model.bug.BugSubscriptionInfo">

=== modified file 'lib/lp/bugs/interfaces/bugsubscriptionfilter.py'
--- lib/lp/bugs/interfaces/bugsubscriptionfilter.py	2011-03-23 15:55:44 +0000
+++ lib/lp/bugs/interfaces/bugsubscriptionfilter.py	2011-03-31 15:52:35 +0000
@@ -6,6 +6,7 @@
 __metaclass__ = type
 __all__ = [
     "IBugSubscriptionFilter",
+    "IBugSubscriptionFilterMute",
     ]
 
 
@@ -19,6 +20,7 @@
 from zope.schema import (
     Bool,
     Choice,
+    Datetime,
     FrozenSet,
     Int,
     Text,
@@ -33,7 +35,10 @@
 from lp.bugs.interfaces.structuralsubscription import (
     IStructuralSubscription,
     )
-from lp.services.fields import SearchTag
+from lp.services.fields import (
+    PersonChoice,
+    SearchTag,
+    )
 
 
 class IBugSubscriptionFilterAttributes(Interface):
@@ -109,3 +114,18 @@
     IBugSubscriptionFilterAttributes, IBugSubscriptionFilterMethods):
     """A bug subscription filter."""
     export_as_webservice_entry()
+
+
+class IBugSubscriptionFilterMute(Interface):
+    """A mute on an IBugSubscriptionFilter."""
+
+    id = Int(required=True, readonly=True)
+    person = PersonChoice(
+        title=_('Person'), required=True, vocabulary='ValidPersonOrTeam',
+        readonly=True, description=_("The person subscribed."))
+    filter = Reference(
+        IBugSubscriptionFilter, title=_("Subscription filter"),
+        description=_("The subscription filter to be muted."))
+    date_created = Datetime(
+        title=_("The date on which the mute was created."), required=False,
+        readonly=True)

=== modified file 'lib/lp/bugs/model/bugsubscriptionfilter.py'
--- lib/lp/bugs/model/bugsubscriptionfilter.py	2011-03-29 10:52:55 +0000
+++ lib/lp/bugs/model/bugsubscriptionfilter.py	2011-03-31 15:52:35 +0000
@@ -4,12 +4,18 @@
 # pylint: disable-msg=E0611,W0212
 
 __metaclass__ = type
-__all__ = ['BugSubscriptionFilter']
+__all__ = [
+    'BugSubscriptionFilter',
+    'BugSubscriptionFilterMute',
+    ]
+
+import pytz
 
 from itertools import chain
 
 from storm.locals import (
     Bool,
+    DateTime,
     Int,
     Reference,
     SQL,
@@ -18,13 +24,17 @@
     )
 from zope.interface import implements
 
+from canonical.database.constants import UTC_NOW
 from canonical.database.enumcol import DBEnum
 from canonical.database.sqlbase import sqlvalues
 from canonical.launchpad import searchbuilder
 from canonical.launchpad.interfaces.lpstorm import IStore
 from lazr.restful.error import expose
 from lp.bugs.enum import BugNotificationLevel
-from lp.bugs.interfaces.bugsubscriptionfilter import IBugSubscriptionFilter
+from lp.bugs.interfaces.bugsubscriptionfilter import (
+    IBugSubscriptionFilter,
+    IBugSubscriptionFilterMute,
+    )
 from lp.bugs.interfaces.bugtask import (
     BugTaskImportance,
     BugTaskStatus,
@@ -36,6 +46,7 @@
     BugSubscriptionFilterStatus,
     )
 from lp.bugs.model.bugsubscriptionfiltertag import BugSubscriptionFilterTag
+from lp.registry.interfaces.person import validate_person
 from lp.services.database.stormbase import StormBase
 
 
@@ -253,3 +264,23 @@
             # There are no other filters.  We can delete the parent
             # subscription.
             self.structural_subscription.delete()
+
+
+class BugSubscriptionFilterMute(StormBase):
+    """A filter to specialize a *structural* subscription."""
+
+    implements(IBugSubscriptionFilterMute)
+
+    __storm_table__ = "BugSubscriptionFilter"
+
+    id = Int(primary=True)
+
+    person_id = Int("person", allow_none=False, validator=validate_person)
+    person = Reference(person_id, "Person.id")
+
+    filter_id = Int("filter", allow_none=False)
+    filter = Reference(filter_id, "StructuralSubscription.id")
+
+    date_created = DateTime(
+        "date_created", allow_none=False, default=UTC_NOW,
+        tzinfo=pytz.UTC)