changeset 3726:cf391507fe8e

merged main
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 20 Jun 2008 13:07:14 +0200
parents 874c4070bd7d (current diff) f42b05d07650 (diff)
children fd63e84632df
files
diffstat 8 files changed, 214 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/PageEditor.py	Fri Jun 20 13:06:38 2008 +0200
+++ b/MoinMoin/PageEditor.py	Fri Jun 20 13:07:14 2008 +0200
@@ -620,8 +620,6 @@
         try:
             os.rename(oldpath, newpath)
             self.error = None
-            if not comment:
-                comment = u"## page was renamed from %s" % self.page_name
             # Save page text with a comment about the old name
             savetext = u"## page was renamed from %s\n%s" % (self.page_name, savetext)
             newpage.saveText(savetext, 0, comment=comment, extra=self.page_name, action='SAVE/RENAME', notify=False)
--- a/MoinMoin/auth/openidrp.py	Fri Jun 20 13:06:38 2008 +0200
+++ b/MoinMoin/auth/openidrp.py	Fri Jun 20 13:07:14 2008 +0200
@@ -93,6 +93,11 @@
                               value=_('Choose this name')))
         table.append(html.TR().append(td1).append(td2))
 
+    def _get_account_name_inval_user(self, request, form):
+        _ = request.getText
+        msg = _('This is not a valid username, choose a different one.')
+        return self._get_account_name(request, form, msg=msg)
+
     def _associate_account(self, request, form, accountname, msg=None):
         _ = request.getText
 
@@ -170,8 +175,7 @@
         if not newname:
             return MultistageFormLogin(self._get_account_name)
         if not user.isValidName(request, newname):
-            return MultistageFormLogin(self._get_account_name,
-                    _('This is not a valid username, choose a different one.'))
+            return MultistageFormLogin(self._get_account_name_inval_user)
         uid = None
         if newname:
             uid = user.getUserId(request, newname)
--- a/MoinMoin/request/__init__.py	Fri Jun 20 13:06:38 2008 +0200
+++ b/MoinMoin/request/__init__.py	Fri Jun 20 13:07:14 2008 +0200
@@ -331,6 +331,10 @@
         except StandardError:
             pass
 
+        if surge_detected and validuser and self.user.auth_method in self.cfg.auth_methods_trusted:
+            logging.info("Trusted user %s would have triggered surge protection if not trusted." % self.user.name)
+            return False  # do not subject trusted users to surge protection
+
         return surge_detected
 
     def getDicts(self):
--- a/MoinMoin/script/__init__.py	Fri Jun 20 13:06:38 2008 +0200
+++ b/MoinMoin/script/__init__.py	Fri Jun 20 13:07:14 2008 +0200
@@ -196,6 +196,7 @@
 moin ... account check ...
 moin ... account create ...
 moin ... account disable ...
+moin ... account resetpw ...
 
 moin ... cli show ...
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/script/account/resetpw.py	Fri Jun 20 13:07:14 2008 +0200
@@ -0,0 +1,68 @@
+# -*- coding: iso-8859-1 -*-
+"""
+MoinMoin - disable a user account
+
+@copyright: 2006 MoinMoin:ThomasWaldmann,
+            2008 MoinMoin:JohannesBerg
+@license: GNU GPL, see COPYING for details.
+"""
+
+from MoinMoin.script import MoinScript
+
+class PluginScript(MoinScript):
+    """\
+Purpose:
+========
+This tool allows you to change a user password via a command line interface.
+
+Detailed Instructions:
+======================
+General syntax: moin [options] account resetpw [newpw-options] newpassword
+
+[options] usually should be:
+    --config-dir=/path/to/my/cfg/ --wiki-url=wiki.example.org/
+
+[newpw-options] see below:
+    1. If using usernames, verify that multiple usernames with the same
+       user ID do not exist.
+
+    2. To change JohnSmith's password:
+       moin ... account resetpw --name JohnSmith new-password
+
+    3. To change the password for the UID '1198872910.78.56322':
+       moin ... account resetpw --uid 1198872910.78.56322 new-password
+"""
+
+    def __init__(self, argv, def_values):
+        MoinScript.__init__(self, argv, def_values)
+        self.parser.add_option(
+            "--uid", metavar="UID", dest="uid",
+            help="Reset password for the user with user id UID."
+        )
+        self.parser.add_option(
+            "--name", metavar="NAME", dest="uname",
+            help="Reset password for the user with user name NAME."
+        )
+
+    def mainloop(self):
+        # we don't expect non-option arguments
+        if len(self.args) != 1:
+            self.parser.error("no new password given")
+        newpass = self.args[0]
+
+        flags_given = self.options.uid or self.options.uname
+        if not flags_given:
+            self.parser.print_help()
+            import sys
+            sys.exit(1)
+
+        self.init_request()
+        request = self.request
+
+        from MoinMoin import user
+        if self.options.uid:
+            u = user.User(request, self.options.uid)
+        elif self.options.uname:
+            u = user.User(request, None, self.options.uname)
+        u.enc_password = user.encodePassword(newpass)
+        u.save()
--- a/MoinMoin/theme/__init__.py	Fri Jun 20 13:06:38 2008 +0200
+++ b/MoinMoin/theme/__init__.py	Fri Jun 20 13:07:14 2008 +0200
@@ -870,6 +870,7 @@
             self.guiEditorScript(d),
             self.html_stylesheets(d),
             self.rsslink(d),
+            self.universal_edit_button(d),
             ]
         return '\n'.join(html)
 
@@ -878,6 +879,21 @@
         src = '%s/common/js/%s.js' % (self.request.cfg.url_prefix_static, name)
         return '<script type="text/javascript" src="%s"></script>' % src
 
+    def universal_edit_button(self, d, **keywords):
+        """ Generate HTML for an edit link in the header."""
+        page = d['page']
+        if 'edit' in self.request.cfg.actions_excluded:
+            return ""
+        if not (page.isWritable() and
+                self.request.user.may.write(page.page_name)):
+            return ""
+        _ = self.request.getText
+        querystr = {'action': 'edit'}
+        text = _(u'Edit')
+        url = page.url(self.request, querystr=querystr, escape=0)
+        return (u'<link rel="alternate" type="application/wiki" '
+                u'title="%s" href="%s" />' % (text, url))
+
     def credits(self, d, **keywords):
         """ Create credits html from credits list """
         if isinstance(self.cfg.page_credits, (list, tuple)):
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/userprefs/oidserv.py	Fri Jun 20 13:07:14 2008 +0200
@@ -0,0 +1,115 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - OpenID preferences
+
+    @copyright: 2007     MoinMoin:JohannesBerg
+    @license: GNU GPL, see COPYING for details.
+"""
+
+from MoinMoin import wikiutil, user
+from MoinMoin.widget import html
+from MoinMoin.userprefs import UserPrefBase
+import base64
+
+
+class Settings(UserPrefBase):
+    def __init__(self, request):
+        """ Initialize OpenID settings form. """
+        UserPrefBase.__init__(self, request)
+        self.request = request
+        self._ = request.getText
+        self.cfg = request.cfg
+        _ = self._
+        self.title = _("OpenID server")
+
+    def allowed(self):
+        if not self.request.cfg.openid_server_enabled:
+            return False
+
+        grp = self.request.cfg.openid_server_restricted_users_group
+        if grp:
+            self.request.dicts.addgroup(self.request, grp)
+            if not self.request.dicts.has_member(grp, self.request.user.name):
+                return False
+
+        return True
+
+    def _handle_remove(self):
+        _ = self.request.getText
+        if not hasattr(self.request.user, 'openid_trusted_roots'):
+            return
+        roots = self.request.user.openid_trusted_roots[:]
+        for root in self.request.user.openid_trusted_roots:
+            name = "rm-%s" % root
+            if name in self.request.form:
+                roots.remove(root)
+        self.request.user.openid_trusted_roots = roots
+        self.request.user.save()
+        return 'info', _("The selected websites have been removed.")
+
+    def handle_form(self):
+        _ = self._
+        form = self.request.form
+
+        if form.has_key('cancel'):
+            return
+
+        if self.request.request_method != 'POST':
+            return
+
+        if form.has_key('remove'):
+            return self._handle_remove()
+
+    def _make_form(self):
+        sn = self.request.getScriptname()
+        pi = self.request.getPathinfo()
+        action = u"%s%s" % (sn, pi)
+        _form = html.FORM(action=action)
+        _form.append(html.INPUT(type="hidden", name="action", value="userprefs"))
+        _form.append(html.INPUT(type="hidden", name="handler", value="oidserv"))
+        return _form
+
+    def _make_row(self, label, cell, **kw):
+        """ Create a row in the form table.
+        """
+        self._table.append(html.TR().extend([
+            html.TD(**kw).extend([html.B().append(label), '   ']),
+            html.TD().extend(cell),
+        ]))
+
+    def _trust_root_list(self):
+        _ = self.request.getText
+        form = self._make_form()
+        for root in self.request.user.openid_trusted_roots:
+            display = base64.decodestring(root)
+            name = 'rm-%s' % root
+            form.append(html.INPUT(type="checkbox", name=name, id=name))
+            form.append(html.LABEL(for_=name).append(html.Text(display)))
+            form.append(html.BR())
+        self._make_row(_("Trusted websites"), [form], valign='top')
+        label = _("Remove selected")
+        form.append(html.BR())
+        form.append(html.INPUT(type="submit", name="remove", value=label))
+
+    def create_form(self):
+        """ Create the complete HTML form code. """
+        _ = self._
+
+        ret = html.P()
+        # Use the user interface language and direction
+        lang_attr = self.request.theme.ui_lang_attr()
+        ret.append(html.Raw('<div %s>' % lang_attr))
+        self._table = html.TABLE(border="0")
+        ret.append(self._table)
+        ret.append(html.Raw("</div>"))
+
+        request = self.request
+
+        if hasattr(request.user, 'openid_trusted_roots') and request.user.openid_trusted_roots:
+            self._trust_root_list()
+
+        form = self._make_form()
+        label = _("Cancel")
+        form.append(html.INPUT(type="submit", name='cancel', value=label))
+        self._make_row('', [form])
+        return unicode(ret)
--- a/docs/CHANGES	Fri Jun 20 13:06:38 2008 +0200
+++ b/docs/CHANGES	Fri Jun 20 13:07:14 2008 +0200
@@ -64,6 +64,10 @@
       Xapian (it uses utf-8 since 1.0.0, so we can use it)).
     * Use better ACLs and comments on system/help pages,
       remove MoinPagesEditorGroup (not needed any more).
+    * If a user is authenticated by a trusted authentication (see also
+      cfg.auth_methods_trusted) then he won't trigger surge protection.
+      But moin will log a INFO level log msg with the user's name so you can
+      find the culprit in case he/she is overusing ressources.
     * docs: added UPDATE instructions