view MoinMoin/userform/ @ 5625:78f1be3c8777

MoinMoin.widget.browser: introduced feature for sorting tables ( DataBrowserWidget.setData: got two new optional keywords. (Defaults: sort_columns=None, reverse=False) MoinMoin.action.AttachFile.do_admin_browser: feature added to sort by first and second column (Page and Filename) MoinMoin.userform.admin.do_user_browser: feature added to sort by the first column (Username)
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Wed, 10 Mar 2010 16:14:56 +0100
parents b0dfed9a569f
children f4e0854b1604
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
    MoinMoin - User account administration

    @copyright: 2001-2004 Juergen Hermann <>,
                2003-2007 MoinMoin:ThomasWaldmann,
                2007-2008 MoinMoin:ReimarBauer,
                2009 MoinMoin:DmitrijsMilajevs
    @license: GNU GPL, see COPYING for details.

from MoinMoin import user, wikiutil
from MoinMoin.util.dataset import TupleDataset, Column
from MoinMoin.Page import Page
from MoinMoin.widget import html
from MoinMoin.datastruct.backends.wiki_groups import WikiGroup

def do_user_browser(request):
    """ Browser for SystemAdmin macro. """
    _ = request.getText
    groups = request.groups

    data = TupleDataset()
    data.columns = [
        Column('name', label=_('Username')),
        Column('groups', label=_('Member of Groups')),
        Column('email', label=_('Email')),
        Column('jabber', label=_('Jabber')),
        Column('action', label=_('Action')),

    # Iterate over users
    for uid in user.getUserList(request):
        account = user.User(request, uid)

        account_groups = set(groups.groups_with_member(
        wiki_groups = set([group for group in account_groups if isinstance(groups[group], WikiGroup)])
        other_groups = list(account_groups - wiki_groups)

        # First show groups that are defined in wikipages linking to it
        # after show groups from other backends.
        grouppage_links = ', '.join([Page(request, group_name).link_to(request) for group_name in wiki_groups] +

        userhomepage = Page(request,
        if userhomepage.exists():
            namelink = userhomepage.link_to(request)
            namelink = wikiutil.escape(

        # creates the POST data for account disable/enable
        val = "1"
        text=_('Disable user')
        if account.disabled:
            text=_('Enable user')
            val = "0"
            namelink += " (%s)" % _("disabled")

        url =
        ret = html.FORM(action=url)
        ret.append(html.INPUT(type='hidden', name='action', value='userprofile'))
        ticket = wikiutil.createTicket(request, action='userprofile')
        ret.append(html.INPUT(type="hidden", name="ticket", value="%s" % ticket))
        ret.append(html.INPUT(type='hidden', name='name',
        ret.append(html.INPUT(type='hidden', name='key', value="disabled"))
        ret.append(html.INPUT(type='hidden', name='val', value=val))
        ret.append(html.INPUT(type='submit', name='userprofile', value=text))
        enable_disable_link = unicode(unicode(ret))

        # creates the POST data for recoverpass
        url =
        ret = html.FORM(action=url)
        ret.append(html.INPUT(type='hidden', name='action', value='recoverpass'))
        ret.append(html.INPUT(type='hidden', name='email',
        ret.append(html.INPUT(type='hidden', name='account_sendmail', value="1"))
        ret.append(html.INPUT(type='hidden', name='sysadm', value="users"))
        ret.append(html.INPUT(type='submit', name='recoverpass', value=_('Mail account data')))
        recoverpass_link =  unicode(unicode(ret))

            email_link = (request.formatter.url(1, 'mailto:' +, css='mailto') +
                          request.formatter.text( +
            email_link = ''

        if account.jid:
            jabber_link = (request.formatter.url(1, 'xmpp:' + account.jid, css='mailto') +
                           request.formatter.text(account.jid) +
            jabber_link = ''

            recoverpass_link + enable_disable_link

    if data:
        from MoinMoin.widget.browser import DataBrowserWidget

        browser = DataBrowserWidget(request)
        browser.setData(data, sort_columns=[0])
        return browser.render()

    # No data
    return ''