view MoinMoin/userform/ @ 6133:a6283e189869 tip

fixup: remove nonexisting passlib.utils._blowfish this was removed by the passlib 1.7.1 upgrade.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 01 Jun 2017 18:10:19 +0200
parents 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')),

    class UserAccount(object):
        # namedtuple is >= 2.6 :-(
        def __init__(self, **kw):
            for k, v in kw.items():
                setattr(self, k, v)
        def __repr__(self):
            return "<UserAccount %r>" % self.__dict__

    accounts = []
    for uid in user.getUserList(request):
        # be careful and just create a list of what we really need,
        # not sure if we can keep lots of User objects instantiated
        # in parallel (open files? too big?)
        u = user.User(request, uid)
        accounts.append(UserAccount(,, jid=u.jid, disabled=u.disabled))

    def sortkey(account):
        # enabled accounts at top, sorted by name
        return (account.disabled,

    # Iterate over user accounts
    for account in sorted(accounts, key=sortkey):
        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)
        return browser.render()

    # No data
    return ''