Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
MoinMoin.userprefs.suid.Settings Class Reference
Inheritance diagram for MoinMoin.userprefs.suid.Settings:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.userprefs.suid.Settings:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def allowed
def handle_form
def create_form
def handle_form
def make_form
def make_row

Public Attributes

 request
 cfg
 title
 name

Private Member Functions

def _user_select

Private Attributes

 _
 _only

Detailed Description

Definition at line 16 of file suid.py.


Constructor & Destructor Documentation

def MoinMoin.userprefs.suid.Settings.__init__ (   self,
  request 
)
Initialize setuid settings form. 

Reimplemented from MoinMoin.userprefs.UserPrefBase.

Definition at line 18 of file suid.py.

00018 
00019     def __init__(self, request):
00020         """ Initialize setuid settings form. """
00021         UserPrefBase.__init__(self, request)
00022         self.request = request
00023         self._ = request.getText
00024         self.cfg = request.cfg
00025         _ = self._
00026         self.title = _("Switch user")
00027         self.name = 'suid'


Member Function Documentation

Definition at line 57 of file suid.py.

00057 
00058     def _user_select(self):
00059         options = []
00060         users = user.getUserList(self.request)
00061         current_uid = self.request.user.id
00062         for uid in users:
00063             if uid != current_uid:
00064                 name = user.User(self.request, id=uid).name
00065                 options.append((uid, name))
00066         options.sort(lambda x, y: cmp(x[1].lower(), y[1].lower()))
00067 
00068         if not options:
00069             _ = self._
00070             self._only = True
00071             return _("You are the only user.")
00072 
00073         self._only = False
00074         size = min(10, len(options))
00075         return util.web.makeSelection('selected_user', options, current_uid, size=size)

Here is the caller graph for this function:

    Not all preferences are applicable to all users,
    this method is called to determine whether the
    title should be listed or not and whether
    submissions are accepted.

Reimplemented from MoinMoin.userprefs.UserPrefBase.

Definition at line 28 of file suid.py.

00028 
00029     def allowed(self):
00030         return (self.request.user.auth_method in self.request.cfg.auth_can_logout and
00031                UserPrefBase.allowed(self) and self.request.user.isSuperUser())

Create the complete HTML form code. 

Reimplemented from MoinMoin.userprefs.UserPrefBase.

Definition at line 76 of file suid.py.

00076 
00077     def create_form(self):
00078         """ Create the complete HTML form code. """
00079         _ = self._
00080         form = self.make_form(html.Text(_('As a superuser, you can temporarily '
00081                                           'assume the identity of another user.')))
00082 
00083         ticket = wikiutil.createTicket(self.request)
00084         self.make_row(_('Select User'), [self._user_select()], valign="top")
00085         form.append(html.INPUT(type="hidden", name="ticket", value="%s" % ticket))
00086         if not self._only:
00087             buttons = [html.INPUT(type="submit", name="select_user",
00088                                   value=_('Select User')),
00089                        ' ', ]
00090         else:
00091             buttons = []
00092         buttons.append(html.INPUT(type="submit", name="cancel",
00093                                   value=_('Cancel')))
00094         self.make_row('', buttons)
00095         return unicode(form)

Here is the call graph for this function:

Definition at line 32 of file suid.py.

00032 
00033     def handle_form(self):
00034         _ = self._
00035         form = self.request.form
00036 
00037         if 'cancel' in form:
00038             return
00039 
00040         if (wikiutil.checkTicket(self.request, self.request.form['ticket'])
00041             and self.request.method == 'POST'):
00042             uid = form.get('selected_user', '')
00043             if not uid:
00044                 return 'error', _("No user selected")
00045             theuser = user.User(self.request, uid, auth_method='setuid')
00046             if not theuser or not theuser.exists():
00047                 return 'error', _("No user selected")
00048             # set valid to True so superusers can even switch
00049             # to disable accounts
00050             theuser.valid = True
00051             self.request._setuid_real_user = self.request.user
00052             # now continue as the other user
00053             self.request.user = theuser
00054             return  _("You can now change the settings of the selected user account; log out to get back to your account.")
00055         else:
00056             return None

def MoinMoin.userprefs.UserPrefBase.handle_form (   self,
  request 
) [inherited]
    When any of the created forms is submitted and the
    hidden fields are set correctly (see create_form)
    this method will be invoked to handle the user's
    input. Note that GET requests are also handed to
    this method, so if you require POST check that.

Definition at line 50 of file __init__.py.

00050 
00051     def handle_form(self, request):
00052         '''
00053             When any of the created forms is submitted and the
00054             hidden fields are set correctly (see create_form)
00055             this method will be invoked to handle the user's
00056             input. Note that GET requests are also handed to
00057             this method, so if you require POST check that.
00058         '''
00059         raise NotImplementedError

def MoinMoin.userprefs.UserPrefBase.make_form (   self,
  explanation = None 
) [inherited]
    To have a consistent UI, use this method for most
    preferences forms and then call make_row(). See
    existing plugins, e.g. changepass.py.

Definition at line 69 of file __init__.py.

00069 
00070     def make_form(self, explanation=None):
00071         '''
00072             To have a consistent UI, use this method for most
00073             preferences forms and then call make_row(). See
00074             existing plugins, e.g. changepass.py.
00075         '''
00076         action = self.request.page.url(self.request)
00077         _form = html.FORM(action=action)
00078         _form.append(html.INPUT(type="hidden", name="action", value="userprefs"))
00079         _form.append(html.INPUT(type="hidden", name="handler", value=self.name))
00080 
00081         self._table = html.TABLE(border="0")
00082 
00083         # Use the user interface language and direction
00084         lang_attr = self.request.theme.ui_lang_attr()
00085         _form.append(html.Raw('<div class="userpref"%s>' % lang_attr))
00086         para = html.P()
00087         _form.append(para)
00088         if explanation:
00089             para.append(explanation)
00090 
00091         para.append(self._table)
00092         _form.append(html.Raw("</div>"))
00093 
00094         return _form

Here is the caller graph for this function:

def MoinMoin.userprefs.UserPrefBase.make_row (   self,
  label,
  cell,
  kw 
) [inherited]
   Create a row in the form table.

Definition at line 95 of file __init__.py.

00095 
00096     def make_row(self, label, cell, **kw):
00097         '''
00098            Create a row in the form table.
00099         '''
00100         self._table.append(html.TR().extend([
00101             html.TD(**kw).extend([html.B().append(label), '   ']),
00102             html.TD().extend(cell),
00103         ]))

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from MoinMoin.userprefs.UserPrefBase.

Definition at line 22 of file suid.py.

Definition at line 69 of file suid.py.

Definition at line 23 of file suid.py.

Reimplemented from MoinMoin.userprefs.UserPrefBase.

Definition at line 26 of file suid.py.

Reimplemented from MoinMoin.userprefs.UserPrefBase.

Definition at line 21 of file suid.py.

Reimplemented from MoinMoin.userprefs.UserPrefBase.

Definition at line 25 of file suid.py.


The documentation for this class was generated from the following file: