Back to index

moin  1.9.0~rc2
Functions | Variables
MoinMoin.events.jabbernotify Namespace Reference

Functions

def handle
def handle_jid_changed
def handle_file_attached
def handle_page_changed
def handle_page_deleted
def handle_page_renamed
def handle_user_created
def page_change
def send_notification

Variables

tuple logging = log.getLogger(__name__)

Function Documentation

An event handler

Definition at line 25 of file jabbernotify.py.

00025 
00026 def handle(event):
00027     """An event handler"""
00028 
00029     cfg = event.request.cfg
00030 
00031     # Check for desired event type and if notification bot is configured
00032     if not cfg.jabber_enabled:
00033         return
00034 
00035     if isinstance(event, (ev.PageChangedEvent, ev.TrivialPageChangedEvent)):
00036         return handle_page_changed(event)
00037     elif isinstance(event, (ev.JabberIDSetEvent, ev.JabberIDUnsetEvent)):
00038         return handle_jid_changed(event)
00039     elif isinstance(event, ev.FileAttachedEvent):
00040         return handle_file_attached(event)
00041     # TODO (needs also corresponding changes in xmppbot + testing)
00042     #elif isinstance(event, ev.FileRemovedEvent):
00043     #    return handle_file_removed(event)
00044     elif isinstance(event, ev.PageDeletedEvent):
00045         return handle_page_deleted(event)
00046     elif isinstance(event, ev.PageRenamedEvent):
00047         return handle_page_renamed(event)
00048     elif isinstance(event, ev.UserCreatedEvent):
00049         return handle_user_created(event)
00050 

Here is the call graph for this function:

Handles event sent when a file is attached to a page

Definition at line 68 of file jabbernotify.py.

00068 
00069 def handle_file_attached(event):
00070     """Handles event sent when a file is attached to a page"""
00071 
00072     names = set()
00073     request = event.request
00074     page = Page(request, event.pagename)
00075     subscribers = page.getSubscribers(request, return_users=1)
00076     notification.filter_subscriber_list(event, subscribers, True)
00077     recipients = []
00078 
00079     for lang in subscribers:
00080         recipients.extend(subscribers[lang])
00081 
00082     attachlink = request.getQualifiedURL(getAttachUrl(event.pagename, event.filename, request))
00083     pagelink = request.getQualifiedURL(page.url(request, {}))
00084 
00085     for lang in subscribers.keys():
00086         _ = lambda text: request.getText(text, lang=lang)
00087         data = notification.attachment_added(request, _, event.pagename, event.filename, event.size)
00088         links = [{'url': attachlink, 'description': _("Attachment link")},
00089                   {'url': pagelink, 'description': _("Page link")}]
00090 
00091         jids = [usr.jid for usr in subscribers[lang]]
00092         data['url_list'] = links
00093         data['action'] = "file_attached"
00094 
00095         if send_notification(request, jids, data):
00096             names.update(recipients)
00097 
00098     return notification.Success(names)
00099 

Here is the call graph for this function:

Here is the caller graph for this function:

Handles events sent when user's JID changes 

Definition at line 51 of file jabbernotify.py.

00051 
00052 def handle_jid_changed(event):
00053     """ Handles events sent when user's JID changes """
00054 
00055     request = event.request
00056     server = request.cfg.notification_server
00057     secret = request.cfg.secrets['jabberbot']
00058     try:
00059         if isinstance(event, ev.JabberIDSetEvent):
00060             server.addJIDToRoster(secret, event.jid)
00061         else:
00062             server.removeJIDFromRoster(secret, event.jid)
00063     except xmlrpclib.Error, err:
00064         logging.error("XML RPC error: %s" % str(err))
00065     except Exception, err:
00066         logging.error("Low-level communication error: %s" % str(err))
00067 

Here is the caller graph for this function:

Handles events related to page changes 

Definition at line 100 of file jabbernotify.py.

00100 
00101 def handle_page_changed(event):
00102     """ Handles events related to page changes """
00103     request = event.request
00104     page = event.page
00105 
00106     subscribers = page.getSubscribers(request, return_users=1)
00107     notification.filter_subscriber_list(event, subscribers, True)
00108     return page_change("page_changed", request, page, subscribers, \
00109                        revisions=page.getRevList(), comment=event.comment)
00110 

Here is the call graph for this function:

Here is the caller graph for this function:

Handles event sent when a page is deleted

Definition at line 111 of file jabbernotify.py.

00111 
00112 def handle_page_deleted(event):
00113     """Handles event sent when a page is deleted"""
00114 
00115     request = event.request
00116     page = event.page
00117 
00118     subscribers = page.getSubscribers(request, return_users=1)
00119     notification.filter_subscriber_list(event, subscribers, True)
00120     return page_change("page_deleted", request, page, subscribers)
00121 

Here is the call graph for this function:

Here is the caller graph for this function:

Handles event sent when a page is renamed

Definition at line 122 of file jabbernotify.py.

00122 
00123 def handle_page_renamed(event):
00124     """Handles event sent when a page is renamed"""
00125 
00126     request = event.request
00127     page = event.page
00128     old_name = event.old_page.page_name
00129 
00130     subscribers = page.getSubscribers(request, return_users=1)
00131 
00132     # Change request's page so that we filter subscribers of the OLD page
00133     request.page = event.old_page
00134     notification.filter_subscriber_list(event, subscribers, True)
00135     request.page = page
00136     return page_change("page_renamed", request, page, subscribers, old_name=old_name)
00137 

Here is the call graph for this function:

Here is the caller graph for this function:

Handles an event sent when a new user is being created

Definition at line 138 of file jabbernotify.py.

00138 
00139 def handle_user_created(event):
00140     """Handles an event sent when a new user is being created"""
00141     request = event.request
00142     sitename = request.cfg.sitename
00143     event_name = event.name
00144     email = event.user.email or u"NOT SET"
00145     username = event.user.name
00146 
00147     user_ids = getUserList(request)
00148     for id in user_ids:
00149         usr = User(request, id=id)
00150         # Currently send this only to super users
00151         if usr.isSuperUser() and usr.jid and event_name in usr.jabber_subscribed_events:
00152             _ = lambda text: request.getText(text, lang=usr.language or 'en')
00153             msg = notification.user_created_message(request, _, sitename, username, email)
00154             data = {'action': "user_created", 'subject': msg['subject'], 'text': msg['text'],
00155                     'url_list': []}
00156             send_notification(request, [usr.jid], data)
00157 

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.events.jabbernotify.page_change (   change_type,
  request,
  page,
  subscribers,
  kwargs 
)
Sends notification about page being changed in some way

Definition at line 158 of file jabbernotify.py.

00158 
00159 def page_change(change_type, request, page, subscribers, **kwargs):
00160     """Sends notification about page being changed in some way"""
00161 
00162     # send notifications to all subscribers
00163     if subscribers:
00164         recipients = set()
00165 
00166         for lang in subscribers:
00167             _ = lambda text: request.getText(text, lang=lang)
00168             jids = [u.jid for u in subscribers[lang] if u.jid]
00169             names = [u.name for u in subscribers[lang] if u.jid]
00170             msg = notification.page_change_message(change_type, request, page, lang, **kwargs)
00171             page_url = request.getQualifiedURL(page.url(request))
00172             url = {'url': page_url, 'description': _("Changed page")}
00173             data = {'action': change_type, 'subject': _('Page changed'),
00174                             'url_list': [url], 'text': msg['text'], 'diff': msg.get('diff', ''),
00175                             'comment': msg.get('comment', ''), 'editor': msg['editor'],
00176                             'old_name': msg.get('old_name', ''), 'page_name': msg.get('page_name', ''),
00177                             'revision': msg.get('revision', '')}
00178 
00179             result = send_notification(request, jids, data)
00180 
00181             if result:
00182                 recipients.update(names)
00183 
00184         if recipients:
00185             return notification.Success(recipients)
00186 

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.events.jabbernotify.send_notification (   request,
  jids,
  notification 
)
Send notifications for a single language.

@param jids: an iterable of Jabber IDs to send the message to
@param message: message text
@param subject: subject of the message, makes little sense for chats
@param url_list: a list of dicts containing URLs and their descriptions
@type url_list: list

Definition at line 187 of file jabbernotify.py.

00187 
00188 def send_notification(request, jids, notification):
00189     """ Send notifications for a single language.
00190 
00191     @param jids: an iterable of Jabber IDs to send the message to
00192     @param message: message text
00193     @param subject: subject of the message, makes little sense for chats
00194     @param url_list: a list of dicts containing URLs and their descriptions
00195     @type url_list: list
00196 
00197     """
00198     server = request.cfg.notification_server
00199 
00200     if type(notification) != dict:
00201         raise ValueError("notification must be of type dict!")
00202 
00203     if type(notification['url_list']) != list:
00204         raise ValueError("url_list must be of type list!")
00205 
00206     try:
00207         server.send_notification(request.cfg.secrets['jabberbot'], jids, notification)
00208         return True
00209     except xmlrpclib.Error, err:
00210         logging.error("XML RPC error: %s" % str(err))
00211     except Exception, err:
00212         logging.error("Low-level communication error: %s" % str(err))
00213 

Here is the caller graph for this function:


Variable Documentation

Definition at line 14 of file jabbernotify.py.