changeset 2145:f153b3155240

Send notifications about creation of users to Superusers with JID set.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Sun, 17 Jun 2007 02:44:13 +0200
parents 05557f1ce219
children 85854afc1aa2 b01a6ef1be4c
files MoinMoin/events/__init__.py MoinMoin/events/jabbernotify.py MoinMoin/userform.py jabberbot/xmppbot.py
diffstat 4 files changed, 44 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/events/__init__.py	Sun Jun 17 02:43:34 2007 +0200
+++ b/MoinMoin/events/__init__.py	Sun Jun 17 02:44:13 2007 +0200
@@ -93,6 +93,13 @@
         Event.__init__(self, request)
         self.jid = jid
         
+class UserCreatedEvent(Event):
+    """ Sent when a new user has been created """
+    
+    def __init__(self, request, user):
+        Event.__init__(self, request)
+        self.user = user
+        
 def _register_handlers(cfg):
     """Create a list of available event handlers.
     
--- a/MoinMoin/events/jabbernotify.py	Sun Jun 17 02:43:34 2007 +0200
+++ b/MoinMoin/events/jabbernotify.py	Sun Jun 17 02:44:13 2007 +0200
@@ -41,6 +41,8 @@
         return handle_file_attached(event)
     elif isinstance(event, ev.PageDeletedEvent):
         return handle_page_deleted(event)
+    elif isinstance(event, ev.UserCreatedEvent):
+        return handle_user_created(event)
     
 
 def handle_jid_changed(event):
@@ -50,7 +52,7 @@
     _ = request.getText
     
     try:
-        if isinstance(event, JabberIDSetEvent):
+        if isinstance(event, ev.JabberIDSetEvent):
             server.addJIDToRoster(request.cfg.secret, event.jid)
         else:
             server.removeJIDFromRoster(request.cfg.secret, event.jid)        
@@ -91,6 +93,29 @@
     
     subscribers = page.getSubscribers(request, return_users=1)
     page_change("page_deleted", request, page, subscribers)
+
+
+def handle_user_created(event):
+    """Handles an event sent when a new user is being created"""
+    
+    user_ids = getUserList(event.request)
+    jids = []
+    msg = u"""Dear Superuser, a new user has just been created. Details follow:
+    User name: %s
+    Email address: %s
+    """
+
+    email = event.user.email or u"NOT SET"
+    
+    for id in user_ids:
+        usr = User(event.request, id=id)
+        
+        # Currently send this only to super users
+        # TODO: make it possible to disable this notification
+        if usr.isSuperUser() and usr.jid:
+            jids.append(usr.jid)
+            
+    send_notification(event.request, jids, msg % (event.user.name, email))
     
 
 def page_change(type, request, page, subscribers, **kwargs):
--- a/MoinMoin/userform.py	Sun Jun 17 02:43:34 2007 +0200
+++ b/MoinMoin/userform.py	Sun Jun 17 02:44:13 2007 +0200
@@ -9,7 +9,7 @@
 
 import time
 from MoinMoin import user, util, wikiutil
-from MoinMoin.events import send_event, JabberIDSetEvent, JabberIDUnsetEvent
+import MoinMoin.events as events
 from MoinMoin.widget import html
 
 _debug = 0
@@ -134,6 +134,10 @@
 
         # save data
         theuser.save()
+        
+        user_created = events.UserCreatedEvent(self.request, theuser)
+        events.send_event(user_created)
+        
         if form.has_key('create_and_mail'):
             theuser.mailAccountData()
 
@@ -245,10 +249,10 @@
                     return _("This jabber id already belongs to somebody else.")
             
             if jid_changed:
-                set_event = JabberIDSetEvent(self.request, theuser.jid)
-                unset_event = JabberIDUnsetEvent(self.request, previous_jid)
-                send_event(set_event)
-                send_event(unset_event)
+                set_event = events.JabberIDSetEvent(self.request, theuser.jid)
+                unset_event = events.JabberIDUnsetEvent(self.request, previous_jid)
+                events.send_event(unset_event)
+                events.send_event(set_event)
 
         if not 'aliasname' in theuser.auth_attribs:
             # aliasname
--- a/jabberbot/xmppbot.py	Sun Jun 17 02:43:34 2007 +0200
+++ b/jabberbot/xmppbot.py	Sun Jun 17 02:44:13 2007 +0200
@@ -240,8 +240,9 @@
         """Sends a message
         
         @param jid: JID to send the message to
-        @param text: message's body
+        @param text: message's body: 
         @param type: message type, as defined in RFC
+        @type jid: pyxmpp.jid.JID
         
         """
         message = Message(to_jid=jid, body=text, stanza_type=msg_type)