Commits

Thomas Waldmann committed cc23787

use search_users() or User() instead of specialized lookup functions

Comments (0)

Files changed (9)

MoinMoin/_tests/test_user.py

         theuser = user.User(name=name)
         assert theuser.email is None
 
-    def test_for_email_attribut_by_uid(self):
-        """
-        checks access to the email attribute by getting the user object from the uid
-        """
-        name = u"__TestUser2__"
-        password = u"ekERErwerwerh"
-        email = u"__TestUser2__@moinhost"
-        self.createUser(name, password, email=email)
-        uid = user.getUserId(name)
-        theuser = user.User(uid)
-        assert theuser.email == email
-
     # Bookmarks -------------------------------------------------------
 
     def test_bookmark(self):

MoinMoin/apps/admin/views.py

     """
     Set values in user profile
     """
-    uid = user.getUserId(user_name)
-    u = user.User(uid)
+    u = user.User(auth_username=user_name)
     if request.method == 'GET':
         return _(u"User profile of %(username)s: %(email)r", username=user_name,
                  email=(u.email, u.disabled))
                 ok = False
         if ok:
             setattr(u, key, val)
-            theuser.save()
+            u.save()
             flash('%s.%s: %s -> %s' % (user_name, key, unicode(oldval), unicode(val), ), "info")
         else:
             flash('modifying %s.%s failed' % (user_name, key, ), "error")

MoinMoin/apps/frontend/views.py

             u = None
             username = form['username'].value
             if username:
-                u = user.User(user.getUserId(username))
+                u = user.User(auth_username=username)
             email = form['email'].value
             if form['email'].valid and email:
-                u = user.get_by_email_address(email)
+                users = user.search_users(email=email)
+                u = users and user.User(users[0][UUID])
             if u and u.valid:
                 is_ok, msg = u.mailAccountData()
                 if not is_ok:
     elif request.method == 'POST':
         form = PasswordRecoveryForm.from_flat(request.form)
         if form.validate():
-            u = user.User(user.getUserId(form['username'].value))
+            u = user.User(auth_username=form['username'].value)
             if u and u.valid and u.apply_recovery_token(form['token'].value, form['password1'].value):
                 flash(_("Your password has been changed, you can log in now."), "info")
             else:
                 flash(_("Your password has been changed."), "info")
             else:
                 if part == 'personal':
-                    if form['openid'].value != flaskg.user.openid and user.get_by_openid(form['openid'].value):
+                    if form['openid'].value != flaskg.user.openid and user.search_users(openid=form['openid'].value):
                         # duplicate openid
                         flash(_("This openid is already in use."), "error")
                         success = False
-                    if form['name'].value != flaskg.user.name and user.getUserId(form['name'].value):
+                    if form['name'].value != flaskg.user.name and user.search_users(name_exact=form['name'].value):
                         # duplicate name
                         flash(_("This username is already in use."), "error")
                         success = False
                 if part == 'notification':
                     if (form['email'].value != flaskg.user.email and
-                        user.get_by_email_address(form['email'].value) and app.cfg.user_email_unique):
+                        user.search_users(email=form['email'].value) and app.cfg.user_email_unique):
                         # duplicate email
                         flash(_('This email is already in use'), 'error')
                         success = False

MoinMoin/auth/openidrp.py

                 # we have successfully authenticated our openid
                 # we get the user with this openid associated to him
                 identity = oid_info.identity_url
-                user_obj = user.get_by_openid(identity)
+                users = user.search_users(openid=identity)
+                user_obj = users and user.User(users[0][UUID])
 
                 # if the user actually exists
                 if user_obj:

MoinMoin/script/account/create.py

         if msg:
             print msg
         else:
-            uid = user.getUserId(name)
-            u = user.User(uid)
+            u = user.User(auth_username=name)
             print " %-20s %-25s %-35s - created." % (u.id, u.name, u.email),
 

MoinMoin/script/account/disable.py

         if uid:
             u = user.User(uid)
         elif name:
-            uid = user.getUserId(name)
-            u = user.User(uid)
+            u = user.User(auth_username=name)
 
         if not u.exists():
             print 'This user "%s" does not exists!' % u.name

MoinMoin/script/account/resetpw.py

         if uid:
             u = user.User(uid)
         elif name:
-            uid = user.getUserId(name)
-            u = user.User(uid)
+            u = user.User(auth_username=name)
 
         if not u.exists():
             print 'This user "%s" does not exists!' % u.name

MoinMoin/security/__init__.py

             that means that there is a valid user account present.
             works for subscription emails.
         """
-        if user.getUserId(name): # is a user with this name known?
+        if user.search_users(name_exact=name): # is a user with this name known?
             return rightsdict.get(dowhat)
         return None
 
 space between words. Group page name is not allowed.""", name=theuser.name)
 
     # Name required to be unique. Check if name belong to another user.
-    if getUserId(theuser.name):
+    if search_users(name_exact=theuser.name):
         return _("This user name already belongs to somebody else.")
 
     pw_checker = app.cfg.password_checker
 
     # 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(theuser.email):
+        if search_users(email=theuser.email):
             return _("This email already belongs to somebody else.")
 
     # Openid should be unique
     theuser.openid = openid
-    if theuser.openid and get_by_openid(theuser.openid):
-            return _('This OpenID already belongs to somebody else.')
+    if theuser.openid and search_users(openid=theuser.openid):
+        return _('This OpenID already belongs to somebody else.')
 
     # save data
     theuser.save()
     docs = backend.documents(all_revs=False, **q)
     return list(docs)
 
-def get_by_email(email):
-    """ Searches for an user with a particular e-mail address and returns it. """
-    docs = search_users(email=email)
-    if docs:
-        return User(docs[0][UUID])
-
-def get_by_openid(openid):
-    """
-    Searches for a user using an openid identifier.
-
-    :param openid: the openid to filter with
-    :type openid: unicode
-    :returns: the user whose openid is this one
-    :rtype: user object or None
-    """
-    docs = search_users(openid=openid)
-    if docs:
-        return User(docs[0][UUID])
-
-def getName(uuid):
-    """ Get the name for a specific uuid.
-
-    :param uuid: the user uuid to look up
-    :rtype: string
-    :returns: the corresponding user name or None
-    """
-    docs = search_users(uuid=uuid)
-    if docs:
-        return docs[0][NAME]
-
-def getUserId(name):
-    """ Get the user ID for a specific user NAME.
-
-    :param name: the user name to look up
-    :rtype: unicode
-    :returns: the corresponding user ID or None
-    """
-    docs = search_users(name_exact=name)
-    if docs:
-        return docs[0][UUID]
 
 def get_editor(userid, addr, hostname):
     """ Return a tuple of type id and string or Page object
         # we got an already authenticated username:
         check_password = None
         if not self.uuid and self.auth_username:
-            self.uuid = getUserId(self.auth_username)
+            users = search_users(name_exact=self.auth_username)
+            if users:
+                self.uuid = users[0][UUID]
             if not password is None:
                 check_password = password
         if self.uuid:
             self.load_from_id(check_password)
         elif self.name and self.name != 'anonymous':
-            self.uuid = getUserId(self.name)
+            users = search_users(name_exact=self.name)
+            if users:
+                self.uuid = users[0][UUID]
             if self.uuid:
                 # no password given should fail
                 self.load_from_id(password or u'')
                          password in the user account file.
         """
         try:
-            name = getName(self.uuid) # XXX we need the name because backend API is still based on names
-            if name is None:
+            users = search_users(uuid=self.uuid) # XXX we need the name because backend API is still based on names
+            if not users:
                 raise NoSuchItemError("No user name for that uuid.")
+            name = users[0][NAME]
             item = self._user_backend.get_item(name)
             self._user = item.get_revision(-1)
         except (NoSuchItemError, NoSuchRevisionError):