Back to index

moin  1.9.0~rc2
admin.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - User account administration
00004 
00005     @copyright: 2001-2004 Juergen Hermann <jh@web.de>,
00006                 2003-2007 MoinMoin:ThomasWaldmann,
00007                 2007-2008 MoinMoin:ReimarBauer,
00008                 2009 MoinMoin:DmitrijsMilajevs
00009     @license: GNU GPL, see COPYING for details.
00010 """
00011 
00012 
00013 from MoinMoin import user, wikiutil
00014 from MoinMoin.util.dataset import TupleDataset, Column
00015 from MoinMoin.Page import Page
00016 from MoinMoin.widget import html
00017 from MoinMoin.datastruct.backends.wiki_groups import WikiGroup
00018 
00019 
00020 def do_user_browser(request):
00021     """ Browser for SystemAdmin macro. """
00022     _ = request.getText
00023     groups = request.groups
00024 
00025     data = TupleDataset()
00026     data.columns = [
00027         Column('name', label=_('Username')),
00028         Column('groups', label=_('Member of Groups')),
00029         Column('email', label=_('Email')),
00030         Column('jabber', label=_('Jabber')),
00031         Column('action', label=_('Action')),
00032     ]
00033 
00034     # Iterate over users
00035     for uid in user.getUserList(request):
00036         account = user.User(request, uid)
00037 
00038         account_groups = set(groups.groups_with_member(account.name))
00039         wiki_groups = set([group for group in account_groups if isinstance(groups[group], WikiGroup)])
00040         other_groups = list(account_groups - wiki_groups)
00041 
00042         # First show groups that are defined in wikipages linking to it
00043         # after show groups from other backends.
00044         grouppage_links = ', '.join([Page(request, group_name).link_to(request) for group_name in wiki_groups] +
00045                                     other_groups)
00046 
00047         userhomepage = Page(request, account.name)
00048         if userhomepage.exists():
00049             namelink = userhomepage.link_to(request)
00050         else:
00051             namelink = wikiutil.escape(account.name)
00052 
00053         # creates the POST data for account disable/enable
00054         val = "1"
00055         text=_('Disable user')
00056         if account.disabled:
00057             text=_('Enable user')
00058             val = "0"
00059             namelink += " (%s)" % _("disabled")
00060 
00061         url = request.page.url(request)
00062         ret = html.FORM(action=url)
00063         ret.append(html.INPUT(type='hidden', name='action', value='userprofile'))
00064         ret.append(html.INPUT(type='hidden', name='name', value=account.name))
00065         ret.append(html.INPUT(type='hidden', name='key', value="disabled"))
00066         ret.append(html.INPUT(type='hidden', name='val', value=val))
00067         ret.append(html.INPUT(type='submit', name='userprofile', value=text))
00068         enable_disable_link = unicode(unicode(ret))
00069 
00070         # creates the POST data for recoverpass
00071         url = request.page.url(request)
00072         ret = html.FORM(action=url)
00073         ret.append(html.INPUT(type='hidden', name='action', value='recoverpass'))
00074         ret.append(html.INPUT(type='hidden', name='email', value=account.email))
00075         ret.append(html.INPUT(type='hidden', name='account_sendmail', value="1"))
00076         ret.append(html.INPUT(type='hidden', name='sysadm', value="users"))
00077         ret.append(html.INPUT(type='submit', name='recoverpass', value=_('Mail account data')))
00078         recoverpass_link =  unicode(unicode(ret))
00079 
00080         if account.email:
00081             email_link = (request.formatter.url(1, 'mailto:' + account.email, css='mailto') +
00082                           request.formatter.text(account.email) +
00083                           request.formatter.url(0))
00084         else:
00085             email_link = ''
00086 
00087         if account.jid:
00088             jabber_link = (request.formatter.url(1, 'xmpp:' + account.jid, css='mailto') +
00089                            request.formatter.text(account.jid) +
00090                            request.formatter.url(0))
00091         else:
00092             jabber_link = ''
00093 
00094         data.addRow((
00095             request.formatter.rawHTML(namelink),
00096             request.formatter.rawHTML(grouppage_links),
00097             email_link,
00098             jabber_link,
00099             recoverpass_link + enable_disable_link
00100         ))
00101 
00102     if data:
00103         from MoinMoin.widget.browser import DataBrowserWidget
00104 
00105         browser = DataBrowserWidget(request)
00106         browser.setData(data)
00107         return browser.render()
00108 
00109     # No data
00110     return ''
00111