changeset 2426:5d1c31b0c6b5

make jabber/email notification types configurable orthogonally
author Johannes Berg <johannes AT sipsolutions DOT net>
date Fri, 20 Jul 2007 00:57:57 +0200
parents c1592d799c53
children dd138b728c1f 58260d360f5c
files MoinMoin/_tests/test_events.py MoinMoin/config/multiconfig.py MoinMoin/events/emailnotify.py MoinMoin/events/jabbernotify.py MoinMoin/events/notification.py MoinMoin/user.py
diffstat 6 files changed, 28 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_events.py	Fri Jul 20 00:40:54 2007 +0200
+++ b/MoinMoin/_tests/test_events.py	Fri Jul 20 00:57:57 2007 +0200
@@ -51,40 +51,36 @@
     user = User(request)
     event = events.Event(request)
 
-    print "User is subscribed to this event and wants to get notified by jabber."
+    print "User is subscribed to this event on jabber."
     print "This means, that he should stay on the list."
-    user.notify_by_jabber = True
     user.jid = "user@example.com"
-    user.subscribed_events = [events.Event.__name__]
+    user.jabber_subscribed_events = [events.Event.__name__]
     subscribers = {"en": [user]}
     notification.filter_subscriber_list(event, subscribers, True)
     assert subscribers["en"]
 
-    print "User is subscribed to this event, but doesn't want to get notified by jabber."
+    print "User is not subscribed to this event on jabber."
     print "The list should be empty."
-    user.notify_by_jabber = False
     user.jid = "user@example.com"
-    user.subscribed_events = [events.Event.__name__]
+    user.jabber_subscribed_events = []
     subscribers = {"en": [user]}
     notification.filter_subscriber_list(event, subscribers, True)
     assert not subscribers["en"]
 
-    print "User is not subscribed to this event, but wants to get notfied by jabber."
-    print "The list should be empty."
-    user.notify_by_jabber = True
-    user.jid = "user@example.com"
-    user.subscribed_events = []
+    print "User is subscribed to this event on email."
+    print "This means, that he should stay on the list."
+    user.email = "user@example.com"
+    user.email_subscribed_events = [events.Event.__name__]
     subscribers = {"en": [user]}
-    notification.filter_subscriber_list(event, subscribers, True)
-    assert not subscribers["en"]
+    notification.filter_subscriber_list(event, subscribers, False)
+    assert subscribers["en"]
 
-    print "User is neither subscribed to this event, nor wants jabber notifications."
+    print "User is not subscribed to this event on email."
     print "The list should be empty."
-    user.notify_by_jabber = False
-    user.subscribed_events = []
-    user.jid = "user@example.com"
+    user.email = "user@example.com"
+    user.email_subscribed_events = []
     subscribers = {"en": [user]}
-    notification.filter_subscriber_list(event, subscribers, True)
+    notification.filter_subscriber_list(event, subscribers, False)
     assert not subscribers["en"]
 
 coverage_modules = ["MoinMoin.events"]
--- a/MoinMoin/config/multiconfig.py	Fri Jul 20 00:40:54 2007 +0200
+++ b/MoinMoin/config/multiconfig.py	Fri Jul 20 00:57:57 2007 +0200
@@ -697,15 +697,6 @@
             from xmlrpclib import Server
             self.notification_server = Server(self.notification_bot_uri, )
 
-            # Add checkbox fields that allow user to select means of notification
-            self.user_checkbox_fields.extend([
-                  ('notify_by_email', lambda _: _('Notify me about changes via email')),
-                  ('notify_by_jabber', lambda _: _('Notify me about changes via jabber')),
-                  ])
-
-            new_defaults = {'notify_by_email': 1, 'notify_by_jabber': 0}
-            self.user_checkbox_defaults.update(new_defaults)
-
         # Cache variables for the properties below
         self._iwid = self._iwid_full = self._meta_dict = None
 
--- a/MoinMoin/events/emailnotify.py	Fri Jul 20 00:40:54 2007 +0200
+++ b/MoinMoin/events/emailnotify.py	Fri Jul 20 00:57:57 2007 +0200
@@ -79,8 +79,10 @@
 
         # send email to all subscribers
         for lang in subscribers:
-            emails = [u.email for u in subscribers[lang] if u.notify_by_email]
-            names = [u.name for u in subscribers[lang] if u.notify_by_email]
+            users = [u for u in subscribers[lang]
+                     if PageChangedEvent.__name__ in u.email_subscribed_events]
+            emails = [u.email for u in users]
+            names = [u.name for u in users]
             data = prep_page_changed_mail(request, page, comment, lang, revisions, trivial)
 
             if send_notification(request, mail_from, emails, data):
@@ -107,11 +109,9 @@
 
     for id in user_ids:
         usr = User(event.request, id=id)
-        if not usr.notify_by_email:
-            continue
 
         # Currently send this only to super users
-        if usr.isSuperUser() and event_name in usr.subscribed_events and usr.notify_by_email:
+        if usr.isSuperUser() and event_name in usr.email_subscribed_events:
             emails.append(usr.email)
 
     send_notification(event.request, from_address, emails, data)
@@ -135,7 +135,7 @@
         emails = []
 
         for usr in subscribers[lang]:
-            if usr.notify_by_email and event_name in usr.subscribed_events:
+            if usr.email and event_name in usr.email_subscribed_events:
                 emails.append(usr.email)
             else:
                 continue
--- a/MoinMoin/events/jabbernotify.py	Fri Jul 20 00:40:54 2007 +0200
+++ b/MoinMoin/events/jabbernotify.py	Fri Jul 20 00:57:57 2007 +0200
@@ -80,7 +80,7 @@
         data = notification.attachment_added(request, event.pagename, event.name, event.size)
 
         for usr in subscribers[lang]:
-            if usr.notify_by_jabber and usr.jid and event_name in usr.subscribed_events:
+            if usr.jid and event_name in usr.jabber_subscribed_events:
                 jids.append(usr.jid)
             else:
                 continue
@@ -139,11 +139,9 @@
 
     for id in user_ids:
         usr = User(event.request, id=id)
-        if not usr.notify_by_jabber:
-            continue
 
         # Currently send this only to super users
-        if usr.isSuperUser() and usr.jid and event_name in usr.subscribed_events:
+        if usr.isSuperUser() and usr.jid and event_name in usr.jabber_subscribed_events:
             jids.append(usr.jid)
 
     send_notification(event.request, jids, msg % (event.user.name, email), data['subject'])
--- a/MoinMoin/events/notification.py	Fri Jul 20 00:40:54 2007 +0200
+++ b/MoinMoin/events/notification.py	Fri Jul 20 00:57:57 2007 +0200
@@ -176,11 +176,12 @@
     return {'body': body, 'subject': subject}
 
 
+# XXX: clean up this method to take a notification type instead of bool for_jabber
 def filter_subscriber_list(event, subscribers, for_jabber):
     """Filter a list of page subscribers to honor event subscriptions
 
     @param subscribers: list of subscribers (dict of lists, language is the key)
-    @param for_jabber: require jid and notify_by_jabber
+    @param for_jabber: require jid
     @type subscribers: dict
 
     """
@@ -193,11 +194,11 @@
 
         if for_jabber:
             for usr in subscribers[lang]:
-                if usr.jid and usr.notify_by_jabber and event_name in usr.subscribed_events:
+                if usr.jid and event_name in usr.jabber_subscribed_events:
                     userlist.append(usr)
         else:
             for usr in subscribers[lang]:
-                if usr.notify_by_email and event_name in usr.subscribed_events:
+                if usr.email and event_name in usr.email_subscribed_events:
                     userlist.append(usr)
 
         subscribers[lang] = userlist
--- a/MoinMoin/user.py	Fri Jul 20 00:40:54 2007 +0200
+++ b/MoinMoin/user.py	Fri Jul 20 00:57:57 2007 +0200
@@ -299,8 +299,6 @@
         self.auth_method = kw.get('auth_method', 'internal')
         self.auth_attribs = kw.get('auth_attribs', ())
         self.bookmarks = {} # interwikiname: bookmark
-        self.notify_by_email = True
-        self.notify_by_jabber = False
 
         # create some vars automatically
         self.__dict__.update(self._cfg.user_form_defaults)
@@ -331,7 +329,8 @@
         self.datetime_fmt = ""
         self.quicklinks = self._cfg.quicklinks_default
         self.subscribed_pages = self._cfg.subscribed_pages_default
-        self.subscribed_events = self._cfg.subscribed_events_default
+        self.email_subscribed_events = self._cfg.subscribed_events_default
+        self.jabber_subscribed_events = []
         self.theme_name = self._cfg.theme_default
         self.editor_default = self._cfg.editor_default
         self.editor_ui = self._cfg.editor_ui