1.1 --- a/ApproveChangesSupport.py Thu Oct 13 21:29:22 2011 +0200
1.2 +++ b/ApproveChangesSupport.py Thu Oct 13 22:48:25 2011 +0200
1.3 @@ -16,8 +16,14 @@
1.4 """
1.5
1.6 from MoinMoin import user
1.7 +from MoinMoin.Page import Page
1.8 from MoinMoin.wikiutil import escape
1.9
1.10 +try:
1.11 + set
1.12 +except NameError:
1.13 + from sets import Set as set
1.14 +
1.15 __version__ = "0.1"
1.16
1.17 def get_queued_changes_page(request):
1.18 @@ -77,37 +83,60 @@
1.19
1.20 return user.User(request, uid)
1.21
1.22 -def add_access_control(request, body):
1.23 +def get_parent_revision_directive(request, pagename):
1.24
1.25 """
1.26 - Using the 'request', add an ACL to the page 'body' in order to prevent
1.27 - anyone other than reviewers from seeing it in the queue.
1.28 + Using the 'request', return a parent page revision directive for the page
1.29 + having the given 'pagename'.
1.30 """
1.31
1.32 - return "#acl %s:read,write,delete,revert,admin All:\n" % (
1.33 - get_page_reviewers_group(request)) + body
1.34 + page = Page(request, pagename)
1.35 + return "#parent-revision %s" % page.current_rev()
1.36 +
1.37 +def get_access_control_directive(request):
1.38 +
1.39 + """
1.40 + Using the 'request', return an ACL directive for use in a page body in order
1.41 + to prevent anyone other than reviewers from seeing it in the queue.
1.42 + """
1.43 +
1.44 + return "#acl %s:read,write,delete,revert,admin All:" % (
1.45 + get_page_reviewers_group(request))
1.46
1.47 -def remove_access_control(request, body):
1.48 +def add_directives(body, directives):
1.49 +
1.50 + "Add to the page 'body' the given 'directives'."
1.51 +
1.52 + return "\n".join(directives + [body])
1.53
1.54 - "Using the 'request', remove any added ACL to the page 'body'."
1.55 +def remove_directives(body, names):
1.56 +
1.57 + """
1.58 + Remove from the page 'body' the first of each directive using the given
1.59 + 'names'.
1.60 + """
1.61
1.62 new_body = []
1.63 header = 1
1.64 + found = set()
1.65
1.66 for line in body.split("\n"):
1.67 if header:
1.68
1.69 - # Skip the first ACL, preserving others potentially added in the
1.70 - # review process.
1.71 -
1.72 - if line.startswith("#acl "):
1.73 - header = 0
1.74 - continue
1.75 -
1.76 # Detect the end of the header.
1.77
1.78 if not line.startswith("#"):
1.79 header = 0
1.80 + else:
1.81 + parts = line[1:].split()
1.82 +
1.83 + # Identify any directive.
1.84 +
1.85 + directive = parts[0]
1.86 +
1.87 + if directive in names and directive not in found:
1.88 + found.add(directive)
1.89 + continue
1.90
1.91 new_body.append(line)
1.92