changeset 2146:85854afc1aa2

Merge with my devel branch.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Sun, 17 Jun 2007 02:45:15 +0200
parents 2941aad83666 (current diff) f153b3155240 (diff)
children 8181ec5cd86c
files
diffstat 5 files changed, 47 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/events/__init__.py	Sat Jun 16 23:15:08 2007 +0200
+++ b/MoinMoin/events/__init__.py	Sun Jun 17 02:45:15 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/emailnotify.py	Sat Jun 16 23:15:08 2007 +0200
+++ b/MoinMoin/events/emailnotify.py	Sun Jun 17 02:45:15 2007 +0200
@@ -13,7 +13,7 @@
 from MoinMoin.Page import Page
 from MoinMoin.mail import sendmail
 from MoinMoin.events import *
-from MoinMoin.events.notification_common import page_changed_notification
+from MoinMoin.events.messages import page_change_message
 
 
 def sendNotification(request, page, comment, emails, email_lang, revisions, trivial):
@@ -28,7 +28,8 @@
     @return: sendmail result
     """
     _ = request.getText
-    mailBody = page_changed_notification(request, page, comment, email_lang, revisions, trivial)
+    mailBody = page_change_message("page_changed", request, page, email_lang, 
+                                   comment=comment, revisions=revisions)
 
     return sendmail.sendmail(request, emails,
         _('[%(sitename)s] %(trivial)sUpdate of "%(pagename)s" by %(username)s', formatted=False) % {
--- a/MoinMoin/events/jabbernotify.py	Sat Jun 16 23:15:08 2007 +0200
+++ b/MoinMoin/events/jabbernotify.py	Sun Jun 17 02:45:15 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	Sat Jun 16 23:15:08 2007 +0200
+++ b/MoinMoin/userform.py	Sun Jun 17 02:45:15 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	Sat Jun 16 23:15:08 2007 +0200
+++ b/jabberbot/xmppbot.py	Sun Jun 17 02:45:15 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)