changeset 423:c16423b7ff18

switch user functionality for superuser imported from: moin--main--1.5--patch-427
author Thomas Waldmann <tw@waldmann-edv.de>
date Sat, 04 Feb 2006 14:07:51 +0000
parents 1fe19d424346
children 5507d1c91fea
files ChangeLog MoinMoin/userform.py docs/CHANGES
diffstat 3 files changed, 60 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Feb 04 13:24:45 2006 +0000
+++ b/ChangeLog	Sat Feb 04 14:07:51 2006 +0000
@@ -2,6 +2,20 @@
 # arch-tag: automatic-ChangeLog--arch@arch.thinkmo.de--2003-archives/moin--main--1.5
 #
 
+2006-02-04 15:07:51 GMT	Thomas Waldmann <tw@waldmann-edv.de>	patch-427
+
+    Summary:
+      switch user functionality for superuser
+    Revision:
+      moin--main--1.5--patch-427
+
+    switch user functionality for superuser
+    
+
+    modified files:
+     ChangeLog MoinMoin/userform.py docs/CHANGES
+
+
 2006-02-04 14:24:45 GMT	Thomas Waldmann <tw@waldmann-edv.de>	patch-426
 
     Summary:
--- a/MoinMoin/userform.py	Sat Feb 04 13:24:45 2006 +0000
+++ b/MoinMoin/userform.py	Sat Feb 04 14:07:51 2006 +0000
@@ -157,6 +157,21 @@
             if _debug:
                 result = result + util.dumpFormData(form)
             return result
+            
+        if form.has_key('select_user'): # Select user profile (su user)
+            if (wikiutil.checkTicket(self.request.form['ticket'][0]) and
+                self.request.user.name in self.request.cfg.superuser and
+                self.request.request_method == 'POST'):
+                su_user = form.get('selected_user', [''])[0]
+                uid = user.getUserId(self.request, su_user)
+                theuser = user.User(self.request, uid)
+                theuser.disabled = None
+                theuser.save()
+                self.request.user = theuser
+                self.request.setCookie()
+                return  _("Use UserPreferences to change settings of the selected user account")
+            else:
+                return _("Use UserPreferences to change your settings or create an account.")
 
         if form.has_key('save'): # Save user profile
             if self.request.request_method != 'POST':
@@ -386,6 +401,19 @@
                 
         return util.web.makeSelection('language', options, cur_lang)
   
+    def _user_select(self):
+        options = []
+        users = user.getUserList(self.request)
+        for uid in users:
+            name = user.User(self.request, id=uid).name
+            if name: # why do we have empty names?
+                options.append((name, name))
+        options.sort()
+
+        size = min(5, len(options))  
+        current_user = self.request.user.name
+        return util.web.makeSelection('selected_user', options, current_user, size=size)
+            
     def _theme_select(self):
         """ Create theme selection. """
         cur_theme = self.request.user.valid and self.request.user.theme_name or self.cfg.theme_default
@@ -444,6 +472,19 @@
         _ = self._
         self.make_form()
 
+        if self.request.user.name in self.request.cfg.superuser:
+            ticket = wikiutil.createTicket()
+            self.make_row(_('Select User'), [self._user_select()])
+            self._form.append(html.INPUT(type="hidden", name="ticket", value="%s" % ticket))
+            buttons = [("select_user", _('Select User'))]
+            button_cell = []
+            for name, label in buttons:
+                 button_cell.extend([
+                     html.INPUT(type="submit", name=name, value=label),
+                     ' ',
+                 ])
+            self.make_row('', button_cell)
+            
         if self.request.user.valid and not create_only:
             buttons = [('save', _('Save'))]
             uf_remove = self.cfg.user_form_remove
--- a/docs/CHANGES	Sat Feb 04 13:24:45 2006 +0000
+++ b/docs/CHANGES	Sat Feb 04 14:07:51 2006 +0000
@@ -1,7 +1,7 @@
 MoinMoin Version History
 ========================
 
-Version 1.5.2rc1:
+Version 1.5.2.current:
 
   New features:
     * Added FullSearchCached macro which is statically cached.
@@ -18,6 +18,10 @@
     * removed old unfinished form and export code.
     * if there is a user with empty password, we just generate a random one
       when he requests it getting sent by mail. Thanks to Reimar Bauer.
+    * the superuser now can switch to another user using UserPreferences -
+      nice to help your users when they forgot their password or need other
+      help. You need to logout/relogin to use your own userid afterwards.
+      Thanks to Reimar Bauer.
 
   Fixes:
    * fixed table attribute parsing