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