changeset 2159:a8941968efa1

Merge with my devel branch.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Mon, 18 Jun 2007 03:31:47 +0200
parents 8e772d72ec6e (current diff) 22a7080b4ac5 (diff)
children 7c8ee12f8c1d af1eb45c937e
files
diffstat 3 files changed, 40 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/events/jabbernotify.py	Mon Jun 18 02:14:57 2007 +0200
+++ b/MoinMoin/events/jabbernotify.py	Mon Jun 18 03:31:47 2007 +0200
@@ -8,6 +8,8 @@
     @license: GNU GPL, see COPYING for details.
 """
 
+import xmlrpclib
+
 from MoinMoin.user import User, getUserList
 from MoinMoin.Page import Page
 
@@ -55,14 +57,36 @@
         return (0, _("Notifications not sent"))
 
 
+def _filter_subscriber_list(event, subscribers):
+    """Filter a list of page subscribers to honor event subscriptions
+    
+    @param subscribers: list of subscribers (dict of lists, language is the key)
+    @type subscribers: dict
+    
+    """
+    event_name = event.__class__.__name__
+    
+    # Filter the list by removing users who don't want to receive
+    # notifications about this type of event
+    for lang in subscribers.keys():
+        userlist = []
+        
+        for usr in subscribers[lang]:
+            if event_name in usr.subscribed_events:
+                userlist.append(usr)
+                
+        subscribers[lang] = userlist
+
 def handle_file_attached(event):
     """Handles event sent when a file is attached to a page"""
     
     request = event.request
     server = request.cfg.xmlrpc_server
-    page = Page(request, event.pagename) 
+    page = Page(request, event.pagename)
     
     subscribers = page.getSubscribers(request, return_users=1)
+    _filter_subscriber_list(event, subscribers)
+    
     page_change("attachment_added", request, page, subscribers, attach_name=event.attachment_name, attach_size=event.size)
 
         
@@ -73,7 +97,9 @@
     server = request.cfg.xmlrpc_server
     page = event.page
     
-    subscribers = page.getSubscribers(request, return_users=1, trivial=event.trivial)
+    subscribers = page.getSubscribers(request, return_users=1, trivial=event.trivial)    
+    _filter_subscriber_list(event, subscribers)
+
     page_change("page_changed", request, page, subscribers, revisions=page.getRevList(), comment=event.comment)
     
 
@@ -85,6 +111,8 @@
     page = event.page
     
     subscribers = page.getSubscribers(request, return_users=1)
+    _filter_subscriber_list(event, subscribers)
+    
     page_change("page_deleted", request, page, subscribers)
 
 
@@ -93,6 +121,7 @@
     
     user_ids = getUserList(event.request)
     jids = []
+    event_name = event.__class__.__name__
     msg = u"""Dear Superuser, a new user has just been created. Details follow:
     User name: %s
     Email address: %s
@@ -105,7 +134,7 @@
         
         # Currently send this only to super users
         # TODO: make it possible to disable this notification
-        if usr.isSuperUser() and usr.jid:
+        if usr.isSuperUser() and usr.jid and event_name in usr.subscribed_events:
             jids.append(usr.jid)
             
     send_notification(event.request, jids, msg % (event.user.name, email))
@@ -119,7 +148,7 @@
         # send notifications to all subscribers
         results = [_('Status of sending notifications:')]
         for lang in subscribers:
-            jids = [u.jid for u in subscribers[lang]]
+            jids = [u.jid for u in subscribers[lang] if u.jid]
             names = [u.name for u in subscribers[lang]]
             msg = page_change_message(type, request, page, lang, **kwargs)
             jabberok, status = send_notification(request, jids, msg)
@@ -147,6 +176,7 @@
     server = request.cfg.xmlrpc_server
     
     for jid in jids:
+                
         # FIXME: stops sending notifications on first error
         try:
             server.send_notification(request.cfg.secret, jid, message)
--- a/MoinMoin/userform.py	Mon Jun 18 02:14:57 2007 +0200
+++ b/MoinMoin/userform.py	Mon Jun 18 03:31:47 2007 +0200
@@ -237,7 +237,7 @@
                     
         if not 'jid' in theuser.auth_attribs:
             # try to get the jid
-            jid = wikiutil.clean_input(form.get('jid', [theuser.jid])[0]).strip()
+            jid = wikiutil.clean_input(form.get('jid', "")).strip()
             
             jid_changed = theuser.jid != jid
             previous_jid = theuser.jid           
--- a/jabberbot/xmppbot.py	Mon Jun 18 02:14:57 2007 +0200
+++ b/jabberbot/xmppbot.py	Mon Jun 18 03:31:47 2007 +0200
@@ -173,6 +173,11 @@
         @param ignore_dnd: if command results in user interaction, should DnD be ignored?
         
         """
+        
+        if not command.jid:
+            self.log("Received a command with empty jid, looks like a bug!")
+            return
+        
         # Handle normal notifications
         if isinstance(command, cmd.NotificationCommand):
             jid = JID(node_or_jid=command.jid)