changeset 2984:52f9d511f155

SystemAdmin user browser: SuperUser now can enable/disable user accounts, new userprofile action (partly a port from 1.6)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 06 Jan 2008 04:45:56 +0100
parents 7b0aadb97d01
children af66750c66e4
files MoinMoin/action/userprofile.py MoinMoin/userform/admin.py
diffstat 2 files changed, 64 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/action/userprofile.py	Sun Jan 06 04:45:56 2008 +0100
@@ -0,0 +1,33 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - set values in user profile
+
+    @copyright: 2008 MoinMoin:ThomasWaldmann
+    @license: GNU GPL, see COPYING for details.
+"""
+from MoinMoin.Page import Page
+from MoinMoin import user
+ 
+def execute(pagename, request):
+    """ set values in user profile """
+    _ = request.getText
+    cfg = request.cfg
+    form = request.form
+
+    if not request.user.isSuperUser():
+        request.theme.add_msg(_("Only superuser is allowed to use this action."), "error")
+    else:
+       user_name = form.get('name', [''])[0]
+       key = form.get('key', [''])[0]
+       val = form.get('val', [''])[0]
+       if key in cfg.user_checkbox_fields:
+           val = int(val)
+       uid = user.getUserId(request, user_name)
+       theuser = user.User(request, uid)
+       oldval = getattr(theuser, key)
+       setattr(theuser, key, val)
+       theuser.save()
+       request.theme.add_msg('%s.%s: %s -> %s' % (user_name, key, oldval, val), "info")
+
+    Page(request, pagename).send_page()
+
--- a/MoinMoin/userform/admin.py	Sun Jan 06 02:49:32 2008 +0100
+++ b/MoinMoin/userform/admin.py	Sun Jan 06 04:45:56 2008 +0100
@@ -7,7 +7,7 @@
                 2007 MoinMoin:ReimarBauer
     @license: GNU GPL, see COPYING for details.
 """
-from MoinMoin import user, wikidicts
+from MoinMoin import user, wikidicts, wikiutil
 from MoinMoin.util.dataset import TupleDataset, Column
 from MoinMoin.Page import Page
 
@@ -18,7 +18,6 @@
 
     data = TupleDataset()
     data.columns = [
-        #Column('id', label=('ID'), align='right'),
         Column('name', label=_('Username')),
         Column('acl groups', label=_('ACL Groups')),
         Column('email', label=_('Email')),
@@ -44,29 +43,46 @@
         if userhomepage.exists():
             namelink = userhomepage.link_to(request)
         else:
-            namelink = account.name
+            namelink = wikiutil.escape(account.name)
+
+        if account.disabled:
+            enable_disable_link = request.page.link_to(
+                                    request, text=_('Enable user'),
+                                    querystr={"action":"userprofile",
+                                              "name": account.name,
+                                              "key": "disabled",
+                                              "val": "0",
+                                             },
+                                    rel='nofollow')
+            namelink += " (%s)" % _("disabled")
+        else:
+            enable_disable_link = request.page.link_to(
+                                    request, text=_('Disable user'),
+                                    querystr={"action":"userprofile",
+                                              "name": account.name,
+                                              "key": "disabled",
+                                              "val": "1",
+                                             },
+                                    rel='nofollow')
+
+        mail_link = request.page.link_to(
+                        request, text=_('Mail account data'),
+                        querystr={"action": "recoverpass",
+                                  "email": account.email,
+                                  "account_sendmail": "1",
+                                  "sysadm": "users", },
+                        rel='nofollow')
 
         data.addRow((
-            #request.formatter.code(1) + uid + request.formatter.code(0),
-            # 0
             request.formatter.rawHTML(namelink),
-            # 1
             request.formatter.rawHTML(list_groups),
-            # 2
             (request.formatter.url(1, 'mailto:' + account.email, css='mailto', do_escape=0) +
              request.formatter.text(account.email) +
              request.formatter.url(0)),
-            # 3
             (request.formatter.url(1, 'xmpp:' + account.jid, css='mailto', do_escape=0) +
              request.formatter.text(account.jid) +
              request.formatter.url(0)),
-            # 4
-            (request.page.link_to(request, text=_('Mail account data'),
-                                 querystr={"action": "recoverpass",
-                                           "email": account.email,
-                                           "account_sendmail": "1",
-                                           "sysadm": "users", },
-                                 rel='nofollow'))
+            mail_link + " - " + enable_disable_link
         ))
 
     if data: