Attachment 'ManageUsers.py'

Download

   1 # -*- coding: utf-8 -*-
   2 """
   3     MoinMoin - ManageUsers Macro
   4 
   5     Based on functions taken from:
   6         userform.py
   7         MoinMoin - UserPreferences Form and User Browser
   8         @copyright: 2001-2004 by Jürgen Hermann <jh@web.de>
   9 
  10     To use this macro the following procedure (potentially UNSAFE as it makes a link to user file public)
  11     should be inserted into user.py (somewhere near the def save()):
  12 
  13     def getFilename(self):
  14         return self.__filename()
  15 
  16     When an account is deleted from Wiki, it's necessary to clean the cache.
  17     This macro only cleans user cache in current Wiki,
  18     so if there's a farm, you'll have to clean cache in other Wikies on your own or using another macro.
  19 
  20     @copyright: 2007 Alexander "Loki" Agibalov
  21     @license: GNU GPL, see COPYING for details.
  22 
  23     changes:
  24         12.2007 - conversion to new syntax by Boles³aw Kulbabiñski
  25 """
  26 
  27 import os
  28 import re
  29 from MoinMoin import user, util, wikiutil, caching
  30 from MoinMoin.util.dataset import TupleDataset, Column
  31 from MoinMoin.Page import Page
  32 
  33 def macro_ManageUsers(macro, args):
  34     request = macro.request
  35     _ = macro.request.getText
  36 
  37     # do not show system admin to users not in superuser list
  38     if not request.user.isSuperUser():
  39         return ''
  40 
  41     # check whether we already have a file name in parameters
  42     par = request.form.get('useradm', [None])[0]
  43     if par is not None:
  44         try:
  45             os.remove(par)
  46         except OSError:
  47             return "error deleting main profile file; stopping"
  48         try:
  49             os.remove(par + ".trail")
  50         except OSError:
  51             return "error deleting trail; main profile was deleted"
  52 
  53         caching.CacheEntry(request, 'user', 'name2id').remove()
  54         return "<u>" + par + "</u> has been deleted and the cache <b>IN CURRENT Wiki</b> was cleaned. To clean cache in other Wiki either goto file system or use my CleanUserCache macro."
  55 
  56     # if no file to delete is given then list the users
  57     data = TupleDataset()
  58     data.columns = [
  59         Column('name', label=_('Username')),
  60         Column('email', label=_('Email')),
  61         Column('theme', label=_('Theme')),
  62         Column('action', label=_('Action')),
  63         Column('filename', label=_('Filename')),
  64         Column('delete', label=_('Delete')),
  65     ]
  66 
  67     # Iterate over users
  68     for uid in user.getUserList(request):
  69         account = user.User(request, uid)
  70 
  71         userhomepage = Page(request, account.name)
  72         if userhomepage.exists():
  73             namelink = userhomepage.link_to(request)
  74         else:
  75             namelink = account.name
  76 
  77         data.addRow((
  78             request.formatter.rawHTML(namelink),
  79             (request.formatter.url(1, 'mailto:' + account.email, css='mailto', do_escape=0) +
  80              request.formatter.text(account.email) +
  81              request.formatter.url(0)),
  82              request.formatter.text(account.theme_name),
  83             request.page.link_to(request, text=_('Mail user his account data'),
  84                                  querystr={"action":"userform",
  85                                             "email": account.email,
  86                                             "account_sendmail": "1",
  87                                             "sysadm": "users"}),
  88             request.formatter.text(account.id),
  89             wikiutil.link_tag(request, "%s?useradm=%s" % (macro.formatter.page.page_name, account.getFilename()), "delete"),
  90         ))
  91 
  92     if data:
  93         from MoinMoin.widget.browser import DataBrowserWidget
  94 
  95         browser = DataBrowserWidget(request)
  96         browser.setData(data)
  97         return browser.toHTML()
  98 
  99     # No data
 100     return ''
 101 
 102 def execute(macro, args):
 103     try:
 104         return wikiutil.invoke_extension_function(
 105                    macro.request, macro_ManageUsers,
 106                    args, [macro])
 107     except ValueError, err:
 108         return macro.request.formatter.text(
 109                    "<<ManageUsers: %s>>" % err.args[0])

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2007-12-22 23:47:40, 1.4 KB) [[attachment:AllPagesWithACL.py]]
  • [get | view] (2007-12-22 23:26:11, 2.2 KB) [[attachment:LostSoulsInGroups.py]]
  • [get | view] (2007-12-22 23:47:25, 3.9 KB) [[attachment:ManageUsers.py]]
  • [get | view] (2008-11-01 08:08:30, 3.0 KB) [[attachment:WikiLog.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.