Commits

Thomas Waldmann committed 942b53b

use whoosh for user lookup, add EMAIL/OPENID to latest-revs schema

fix some minor test issues with unicode/str data types

Comments (0)

Files changed (6)

MoinMoin/_tests/test_user.py

         # "KeyError: 'enc_password'" error during user authentication.
         user_name = u'moin'
         user_password = u'{SHA}LKM56'
-        user.create_user(user_name, user_password, u'moin@moinmo.in', '')
+        user.create_user(user_name, user_password, u'moin@moinmo.in', u'')
 
         # Try to "login"
         theuser = user.User(name=user_name, password=user_password)

MoinMoin/auth/_tests/test_auth.py

         givenauth_obj.strip_windomain = True
         givenauth_obj.titlecase = True
         givenauth_obj.remove_blanks = True
-        create_user('Test_User', 'test_pass', 'test@moinmoin.org')
+        create_user(u'Test_User', u'test_pass', u'test@moinmoin.org')
         test_user, bool_value = givenauth_obj.request(flaskg.user)
         assert test_user.valid
         assert test_user.name == u'Test_User'
 
 def test_handle_login():
-    # no messages in the biginning
+    # no messages in the beginning
     assert not flaskg._login_messages
     test_user1 = handle_login(flaskg.user, login_username = 'test_user', login_password = 'test_password', stage = 'moin')
     test_login_message = [u'Invalid username or password.']
     givenauth_obj = GivenAuth()
     flaskg.user.auth_method = 'given'
     givenauth_obj.user_name = u'Test_User'
-    create_user('Test_User', 'test_pass', 'test@moinmoin.org')
+    create_user(u'Test_User', u'test_pass', u'test@moinmoin.org')
     test_user, bool_value = givenauth_obj.request(flaskg.user)
     test_user2 = handle_login(test_user, login_username = 'Test_User', login_password = 'test_pass', stage = 'moin')
     assert not flaskg._login_messages

MoinMoin/auth/_tests/test_http.py

 
     def test_request(self):
         # create a new user
-        create_user(u'ValidUser', 'test_pass', 'test_email@moinmoin')
+        create_user(u'ValidUser', u'test_pass', u'test_email@moinmoin')
         httpauthmoin_obj = HTTPAuthMoin()
         test_user, bool_val = httpauthmoin_obj.request(flaskg.user)
         assert test_user.valid

MoinMoin/config/__init__.py

 WIKINAME = "wikiname"
 CONTENT = "content"
 
+# stuff from user profiles / for whoosh index
+EMAIL = "email"
+OPENID = "openid"
+
 # structure for contenttype groups
 CONTENTTYPE_GROUPS = [
     ('markup text items', [

MoinMoin/search/indexing.py

 
 from MoinMoin.config import WIKINAME, NAME, NAME_EXACT, REV_NO, MTIME, CONTENTTYPE, TAGS, \
                             LANGUAGE, USERID, ADDRESS, HOSTNAME, SIZE, ACTION, COMMENT, \
-                            CONTENT, UUID, ITEMLINKS, ITEMTRANSCLUSIONS, ACL
+                            CONTENT, UUID, ITEMLINKS, ITEMTRANSCLUSIONS, ACL, EMAIL, OPENID
 from MoinMoin.search.analyzers import *
 from MoinMoin.error import FatalError
 
         }
         latest_revs_fields.update(**common_fields)
 
+        userprofile_fields = {
+            # EMAIL from user profile metadata
+            EMAIL: ID(unique=True, stored=True),
+            # OPENID from user profile metadata
+            OPENID: ID(unique=True, stored=True),
+        }
+        latest_revs_fields.update(**userprofile_fields)
+
         all_revs_fields = {
             # UUID from metadata
             UUID: ID(stored=True),
 from flask import g as flaskg
 from flask import session, request, url_for
 
+from whoosh.query import Term, And, Or
+
 from MoinMoin import config, wikiutil
-from MoinMoin.config import NAME, UUID, ACTION, CONTENTTYPE
+from MoinMoin.config import WIKINAME, NAME, NAME_EXACT, UUID, ACTION, CONTENTTYPE, EMAIL, OPENID
 from MoinMoin.i18n import _, L_, N_
 from MoinMoin.util.interwiki import getInterwikiHome, getInterwikiName, is_local_wiki
 from MoinMoin.util.crypto import crypt_password, upgrade_password, valid_password, \
 
     # Email should be unique - see also MoinMoin/script/accounts/moin_usercheck.py
     if theuser.email and app.cfg.user_email_unique:
-        if get_by_email_address(theuser.email):
+        if get_by_email(theuser.email):
             return _("This email already belongs to somebody else.")
 
     # Openid should be unique
     return flaskg.unprotected_storage
 
 
+def get_revs_by_filter(**q):
+    """ Searches for a user with a given filter """
+    q.update(wikiname=app.cfg.interwikiname) # XXX for now, search only users of THIS wiki
+                                             # maybe add option to not index wiki users separately,
+                                             # but share them in the index also
+    backend = get_user_backend()
+    docs = backend.documents(all_revs=False, **q)
+    return list(docs)
+
+
 def getUserList():
     """ Get a list of all (numerical) user IDs.
 
     :rtype: list
     :returns: all user IDs
     """
-    userlist = []
-    for item in get_user_backend().iteritems():
-        rev = item.get_revision(-1)
-        userlist.append(rev[UUID])
-    return userlist
+    revs = get_revs_by_filter()
+    return [rev[UUID] for rev in revs]
 
-
-def get_revs_by_filter(key, value):
-    """ Searches for a user with a given filter """
-    backend = get_user_backend()
-    revs_found = []
-    for item in backend.iteritems():
-        rev = item.get_revision(-1)
-        if rev.get(key) == value:
-            revs_found.append(rev)
-    return revs_found
-
-
-def get_by_email_address(email_address):
+def get_by_email(email):
     """ Searches for an user with a particular e-mail address and returns it. """
-    revs = get_revs_by_filter('email', email_address)
+    revs = get_revs_by_filter(email=email)
     if revs:
         return User(revs[0][UUID])
 
     :returns: the user whose openid is this one
     :rtype: user object or None
     """
-    revs = get_revs_by_filter('openid', openid)
+    revs = get_revs_by_filter(openid=openid)
     if revs:
         return User(revs[0][UUID])
 
     :rtype: string
     :returns: the corresponding user name or None
     """
-    revs = get_revs_by_filter(UUID, uuid)
+    revs = get_revs_by_filter(uuid=uuid)
     if revs:
         return revs[0][NAME]
 
-def getUserId(searchName):
+def getUserId(name):
     """ Get the user ID for a specific user NAME.
 
-    :param searchName: the user name to look up
-    :rtype: string
+    :param name: the user name to look up
+    :rtype: unicode
     :returns: the corresponding user ID or None
     """
-    revs = get_revs_by_filter(NAME, searchName)
+    revs = get_revs_by_filter(name_exact=name)
     if revs:
         return revs[0][UUID]