annotate MoinMoin/userprefs/suid.py @ 5144:12d27670e274

merged moin/1.8
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 14 Sep 2009 02:47:11 +0200
parents 6c8aa68b803c df2301035a3c
children cded5f776bc1
rev   line source
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
2 """
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
3 MoinMoin - switch user form
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
4
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
5 @copyright: 2001-2004 Juergen Hermann <jh@web.de>,
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
6 2003-2007 MoinMoin:ThomasWaldmann
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
7 2007 MoinMoin:JohannesBerg
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
8 @license: GNU GPL, see COPYING for details.
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
9 """
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
10
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
11 from MoinMoin import user, util, wikiutil
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
12 from MoinMoin.widget import html
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
13 from MoinMoin.userprefs import UserPrefBase
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
14
2449
fa3aca6aacd4 make pep8 checker happy
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2444
diff changeset
15
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
16 class Settings(UserPrefBase):
2449
fa3aca6aacd4 make pep8 checker happy
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2444
diff changeset
17
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
18 def __init__(self, request):
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
19 """ Initialize setuid settings form. """
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
20 UserPrefBase.__init__(self, request)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
21 self.request = request
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
22 self._ = request.getText
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
23 self.cfg = request.cfg
2423
76bf8b6b3061 use formatted=False for userprefs titles
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2369
diff changeset
24 _ = self._
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2449
diff changeset
25 self.title = _("Switch user")
2368
5fc0717a060f refactor userprefs for more consistent UI
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2363
diff changeset
26 self.name = 'suid'
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
27
2368
5fc0717a060f refactor userprefs for more consistent UI
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2363
diff changeset
28 def allowed(self):
4901
6c8aa68b803c userprefs.suid: requires an auth_method which can logout (corrected changeset 4893:c1ed36a3fd5e)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4893
diff changeset
29 return (self.request.user.auth_method in self.request.cfg.auth_can_logout and
4893
c1ed36a3fd5e userprefs.suid: allowed only if request.cfg.auth_have_login is given
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4638
diff changeset
30 UserPrefBase.allowed(self) and self.request.user.isSuperUser())
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
31
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
32 def handle_form(self):
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
33 _ = self._
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
34 form = self.request.form
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
35
2449
fa3aca6aacd4 make pep8 checker happy
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2444
diff changeset
36 if 'cancel' in form:
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
37 return
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
38
4237
162002d5b148 Replaced some references to request.form with MultiDict-compatible semantics
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4186
diff changeset
39 if (wikiutil.checkTicket(self.request, self.request.form['ticket'])
4186
126559845d4b Use Werkzeug-property names instead of old MoinMoin attribute names
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3513
diff changeset
40 and self.request.method == 'POST'):
4428
ded09bdc3902 pre-1.9: request.form has qs args and post data, 1.9: .form only post data, .args only qs args, .values both
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4237
diff changeset
41 uid = form.get('selected_user', '')
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
42 if not uid:
3513
7bfd4232cfb7 builtin userprefs plugins: return appropriate message class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3122
diff changeset
43 return 'error', _("No user selected")
2434
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
44 theuser = user.User(self.request, uid, auth_method='setuid')
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
45 if not theuser or not theuser.exists():
3513
7bfd4232cfb7 builtin userprefs plugins: return appropriate message class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3122
diff changeset
46 return 'error', _("No user selected")
2434
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
47 # set valid to True so superusers can even switch
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
48 # to disable accounts
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
49 theuser.valid = True
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
50 self.request._setuid_real_user = self.request.user
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
51 # now continue as the other user
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
52 self.request.user = theuser
2363
a73c99c076c2 clean up suid prefs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2294
diff changeset
53 return _("You can now change the settings of the selected user account; log out to get back to your account.")
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
54 else:
2363
a73c99c076c2 clean up suid prefs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2294
diff changeset
55 return None
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
56
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
57 def _user_select(self):
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
58 options = []
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
59 users = user.getUserList(self.request)
4638
7bc4d1571f8f suid: simplify and fix, bigger selection box
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4530
diff changeset
60 current_uid = self.request.user.id
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
61 for uid in users:
4638
7bc4d1571f8f suid: simplify and fix, bigger selection box
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4530
diff changeset
62 if uid != current_uid:
2434
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
63 name = user.User(self.request, id=uid).name
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
64 options.append((uid, name))
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
65 options.sort(lambda x, y: cmp(x[1].lower(), y[1].lower()))
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
66
2434
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
67 if not options:
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
68 _ = self._
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
69 self._only = True
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
70 return _("You are the only user.")
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
71
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
72 self._only = False
4638
7bc4d1571f8f suid: simplify and fix, bigger selection box
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4530
diff changeset
73 size = min(10, len(options))
7bc4d1571f8f suid: simplify and fix, bigger selection box
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4530
diff changeset
74 return util.web.makeSelection('selected_user', options, current_uid, size=size)
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
75
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
76 def create_form(self):
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
77 """ Create the complete HTML form code. """
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
78 _ = self._
2368
5fc0717a060f refactor userprefs for more consistent UI
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2363
diff changeset
79 form = self.make_form(html.Text(_('As a superuser, you can temporarily '
5fc0717a060f refactor userprefs for more consistent UI
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2363
diff changeset
80 'assume the identity of another user.')))
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
81
2368
5fc0717a060f refactor userprefs for more consistent UI
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2363
diff changeset
82 ticket = wikiutil.createTicket(self.request)
5123
df2301035a3c suid: translate 'Select User'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3513
diff changeset
83 self.make_row(_('Select User'), [self._user_select()], valign="top")
2368
5fc0717a060f refactor userprefs for more consistent UI
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2363
diff changeset
84 form.append(html.INPUT(type="hidden", name="ticket", value="%s" % ticket))
2434
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
85 if not self._only:
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
86 buttons = [html.INPUT(type="submit", name="select_user",
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
87 value=_('Select User')),
2444
12854ba50c0d password_checker test: add the usual set import magic for py 2.3, small whitespace fix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2434
diff changeset
88 ' ', ]
2434
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
89 else:
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
90 buttons = []
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
91 buttons.append(html.INPUT(type="submit", name="cancel",
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
92 value=_('Cancel')))
b4aa8a40f754 clean up suid a bit
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2423
diff changeset
93 self.make_row('', buttons)
2368
5fc0717a060f refactor userprefs for more consistent UI
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2363
diff changeset
94 return unicode(form)