Attachment 'AclBasedText.py'
Download 1 from MoinMoin import wikiutil
2 from MoinMoin.parser.text_moin_wiki import Parser as wiki
3 from MoinMoin.Page import Page
4 import time
5 from datetime import datetime,timedelta
6 import re, StringIO
7
8 _reSeq=re.compile(ur"\s*=\s*")
9
10 ## @param permission Permission user should have
11 ## @param has_perm_text Text, in case permission granted
12 ## @param hasnt_perm_text Text, in case user logged in and permission not granted
13 ## @param anonymous_text Text, in case user not logged in and permission not granted
14 def execute(macro, args):
15 request, page = macro.request, macro.formatter.page
16 options = {
17 'permission' : u'write',
18 'has_perm_text' : u'You\'re granted to do this',
19 'hasnt_perm_text' : u'You\'re not granted to do this',
20 'anonymous_text' : u'Please log in'
21 }
22
23 ret = []
24
25 pars=[s.strip() for s in args.split(',')]
26 options.update(dict([_reSeq.split(s) for s in filter(_reSeq.search, pars)]))
27 permission = options['permission']
28
29 has_parm = False
30 #try:
31 has_perm = getattr(request.user.may, str(permission))(page.page_name)
32 #except:
33 # ret += dir(request.user.may)
34 # ret.append('\n\nAclBasedText: Errornous permission: %s\n\n' % permission)
35 # wikiizer = wiki(u'\n'.join(ret), request)
36 # wikiizer.format(macro.formatter)
37 # return ''
38
39 if has_perm:
40 ret.append(options['has_perm_text'])
41 else:
42 if request.user.valid:
43 ret.append(options['hasnt_perm_text'])
44 else:
45 ret.append(options['anonymous_text'])
46
47 wikiizer = wiki(u'\n'.join(ret), request)
48 wikiizer.format(macro.formatter)
49
50 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.