# HG changeset patch # User Paul Boddie # Date 1318538905 -7200 # Node ID 7e37c1bc2ae15cfd82279656a686ef94533e7823 # Parent 94730941d6ff1b780fded52e5fee519e4ce44f06 Replaced the page editing around the ACL directive with more general directive editing so that a parent revision directive can also be used. diff -r 94730941d6ff -r 7e37c1bc2ae1 ApproveChangesSupport.py --- a/ApproveChangesSupport.py Thu Oct 13 21:29:22 2011 +0200 +++ b/ApproveChangesSupport.py Thu Oct 13 22:48:25 2011 +0200 @@ -16,8 +16,14 @@ """ from MoinMoin import user +from MoinMoin.Page import Page from MoinMoin.wikiutil import escape +try: + set +except NameError: + from sets import Set as set + __version__ = "0.1" def get_queued_changes_page(request): @@ -77,37 +83,60 @@ return user.User(request, uid) -def add_access_control(request, body): +def get_parent_revision_directive(request, pagename): """ - Using the 'request', add an ACL to the page 'body' in order to prevent - anyone other than reviewers from seeing it in the queue. + Using the 'request', return a parent page revision directive for the page + having the given 'pagename'. """ - return "#acl %s:read,write,delete,revert,admin All:\n" % ( - get_page_reviewers_group(request)) + body + page = Page(request, pagename) + return "#parent-revision %s" % page.current_rev() + +def get_access_control_directive(request): + + """ + Using the 'request', return an ACL directive for use in a page body in order + to prevent anyone other than reviewers from seeing it in the queue. + """ + + return "#acl %s:read,write,delete,revert,admin All:" % ( + get_page_reviewers_group(request)) -def remove_access_control(request, body): +def add_directives(body, directives): + + "Add to the page 'body' the given 'directives'." + + return "\n".join(directives + [body]) - "Using the 'request', remove any added ACL to the page 'body'." +def remove_directives(body, names): + + """ + Remove from the page 'body' the first of each directive using the given + 'names'. + """ new_body = [] header = 1 + found = set() for line in body.split("\n"): if header: - # Skip the first ACL, preserving others potentially added in the - # review process. - - if line.startswith("#acl "): - header = 0 - continue - # Detect the end of the header. if not line.startswith("#"): header = 0 + else: + parts = line[1:].split() + + # Identify any directive. + + directive = parts[0] + + if directive in names and directive not in found: + found.add(directive) + continue new_body.append(line) diff -r 94730941d6ff -r 7e37c1bc2ae1 actions/ApproveChanges.py --- a/actions/ApproveChanges.py Thu Oct 13 21:29:22 2011 +0200 +++ b/actions/ApproveChanges.py Thu Oct 13 22:48:25 2011 +0200 @@ -85,7 +85,6 @@ target_page_name = get_target_page_name(self.pagename) target_page = PageEditor(request, target_page_name) - # Save the target page, removing any protective ACL. # First, the displayed revision must be retrieved. form = get_form(request) @@ -100,7 +99,10 @@ page = Page(request, self.page.page_name, rev=rev) body = page.get_raw_body() - body = remove_access_control(request, body) + + # Save the target page, removing any introduced directives. + + body = remove_directives(body, ["acl", "parent-revision"]) try: target_page.saveText(body, 0, comment=_("Changes to page approved from queue revision %d.") % rev) diff -r 94730941d6ff -r 7e37c1bc2ae1 events/queue_for_review.py --- a/events/queue_for_review.py Thu Oct 13 21:29:22 2011 +0200 +++ b/events/queue_for_review.py Thu Oct 13 22:48:25 2011 +0200 @@ -41,14 +41,18 @@ elif not is_approved(request): # Save the page in the queue. - # NOTE: Record the parent revision. - # NOTE: (to-do/record-parent-for-proper-merges.txt) new_page = PageEditor(request, "%s/%s" % (pagename, queued_changes_page)) # Add an ACL to prevent normal users from seeing the page anywhere. + # Add a parent revision to the page. - body = add_access_control(request, body) + directives = [ + get_access_control_directive(request), + get_parent_revision_directive(request, pagename) + ] + + body = add_directives(body, directives) username = request.user.name comment = (username or _("anonymous")) + " : " + _("Queued page edit")