1.1 --- a/ApproveChangesSupport.py Wed Oct 12 00:56:42 2011 +0200
1.2 +++ b/ApproveChangesSupport.py Thu Oct 13 21:29:22 2011 +0200
1.3 @@ -17,9 +17,6 @@
1.4
1.5 from MoinMoin import user
1.6 from MoinMoin.wikiutil import escape
1.7 -import re
1.8 -
1.9 -acl_pattern = re.compile(ur"^#acl .*$", re.UNICODE | re.MULTILINE)
1.10
1.11 __version__ = "0.1"
1.12
1.13 @@ -87,41 +84,34 @@
1.14 anyone other than reviewers from seeing it in the queue.
1.15 """
1.16
1.17 - # Find existing ACLs.
1.18 -
1.19 - match = acl_pattern.search(body)
1.20 - if match:
1.21 - start, end = match.span()
1.22 -
1.23 - # Comment out existing ACLs.
1.24 -
1.25 - parts = []
1.26 - parts.append(body[:start])
1.27 - parts.append("#")
1.28 - parts.append(body[start:])
1.29 - else:
1.30 - parts = [body]
1.31 -
1.32 - # Add the ACL.
1.33 -
1.34 - parts.insert(0, "#acl %s:read,write,delete,revert,admin All:\n" %
1.35 - get_page_reviewers_group(request))
1.36 - return "".join(parts)
1.37 + return "#acl %s:read,write,delete,revert,admin All:\n" % (
1.38 + get_page_reviewers_group(request)) + body
1.39
1.40 def remove_access_control(request, body):
1.41
1.42 "Using the 'request', remove any added ACL to the page 'body'."
1.43
1.44 - lines = body.split("\n")
1.45 + new_body = []
1.46 + header = 1
1.47 +
1.48 + for line in body.split("\n"):
1.49 + if header:
1.50 +
1.51 + # Skip the first ACL, preserving others potentially added in the
1.52 + # review process.
1.53
1.54 - try:
1.55 - directive = lines[0].split()[0]
1.56 - if directive == "#acl":
1.57 - return "\n".join(lines[1:])
1.58 - except ValueError:
1.59 - pass
1.60 + if line.startswith("#acl "):
1.61 + header = 0
1.62 + continue
1.63 +
1.64 + # Detect the end of the header.
1.65
1.66 - return body
1.67 + if not line.startswith("#"):
1.68 + header = 0
1.69 +
1.70 + new_body.append(line)
1.71 +
1.72 + return "\n".join(new_body)
1.73
1.74 # Utility classes and associated functions.
1.75 # NOTE: These are a subset of EventAggregatorSupport.