changeset 2090:9fec7760489e

Add a get_by_jabber_id function to search for users given their jabber id.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Sun, 03 Jun 2007 20:30:08 +0200
parents 4ec961fd40d9
children 7af58454aafa
files MoinMoin/user.py
diffstat 1 files changed, 15 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/user.py	Sun Jun 03 19:51:23 2007 +0200
+++ b/MoinMoin/user.py	Sun Jun 03 20:30:08 2007 +0200
@@ -41,12 +41,22 @@
     userlist = [f for f in files if user_re.match(f)]
     return userlist
 
+def get_by_filter(request, filter):
+    """ Searches for an user with a given filter """
+    for uind in getUserList(request):
+        theuser = User(request, uid)
+        if filter(theuser):
+            return theuser
+
 def get_by_email_address(request, email_address):
-    """ Searches for a user with a particular e-mail address and returns it. """
-    for uid in getUserList(request):
-        theuser = User(request, uid)
-        if theuser.valid and theuser.email.lower() == email_address.lower():
-            return theuser
+    """ Searches for an user with a particular e-mail address and returns it. """
+    filter = lambda user: user.valid and user.email.lower() == email_address.lower()
+    return get_by_filter(request, filter)
+        
+def get_by_jabber_id(request, jabber_id):
+    """ Searches for an user with a perticular jabber id and returns it. """
+    filter = lambda user: user.valid and user.jid.lower() == jabber_id.lower()
+    return get_by_filter(request, filter)
 
 def _getUserIdByKey(request, key, search):
     """ Get the user ID for a specified key/value pair.