# HG changeset patch # User Paul Boddie # Date 1318534162 -7200 # Node ID 94730941d6ff1b780fded52e5fee519e4ce44f06 # Parent af7549a4eb7fe681d02e842a7634677de1bc545e Removed the commenting out of ACLs when queuing changes and improved the removal of ACLs when approving changes so that reviewers can add header lines including ACLs and only the first ACL will be removed. diff -r af7549a4eb7f -r 94730941d6ff ApproveChangesSupport.py --- a/ApproveChangesSupport.py Wed Oct 12 00:56:42 2011 +0200 +++ b/ApproveChangesSupport.py Thu Oct 13 21:29:22 2011 +0200 @@ -17,9 +17,6 @@ from MoinMoin import user from MoinMoin.wikiutil import escape -import re - -acl_pattern = re.compile(ur"^#acl .*$", re.UNICODE | re.MULTILINE) __version__ = "0.1" @@ -87,41 +84,34 @@ anyone other than reviewers from seeing it in the queue. """ - # Find existing ACLs. - - match = acl_pattern.search(body) - if match: - start, end = match.span() - - # Comment out existing ACLs. - - parts = [] - parts.append(body[:start]) - parts.append("#") - parts.append(body[start:]) - else: - parts = [body] - - # Add the ACL. - - parts.insert(0, "#acl %s:read,write,delete,revert,admin All:\n" % - get_page_reviewers_group(request)) - return "".join(parts) + return "#acl %s:read,write,delete,revert,admin All:\n" % ( + get_page_reviewers_group(request)) + body def remove_access_control(request, body): "Using the 'request', remove any added ACL to the page 'body'." - lines = body.split("\n") + new_body = [] + header = 1 + + for line in body.split("\n"): + if header: + + # Skip the first ACL, preserving others potentially added in the + # review process. - try: - directive = lines[0].split()[0] - if directive == "#acl": - return "\n".join(lines[1:]) - except ValueError: - pass + if line.startswith("#acl "): + header = 0 + continue + + # Detect the end of the header. - return body + if not line.startswith("#"): + header = 0 + + new_body.append(line) + + return "\n".join(new_body) # Utility classes and associated functions. # NOTE: These are a subset of EventAggregatorSupport.