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
2.1 --- a/actions/ApproveChanges.py Thu Oct 13 21:29:22 2011 +0200
2.2 +++ b/actions/ApproveChanges.py Thu Oct 13 22:48:25 2011 +0200
2.3 @@ -85,7 +85,6 @@
2.4 target_page_name = get_target_page_name(self.pagename)
2.5 target_page = PageEditor(request, target_page_name)
2.6
2.7 - # Save the target page, removing any protective ACL.
2.8 # First, the displayed revision must be retrieved.
2.9
2.10 form = get_form(request)
2.11 @@ -100,7 +99,10 @@
2.12
2.13 page = Page(request, self.page.page_name, rev=rev)
2.14 body = page.get_raw_body()
2.15 - body = remove_access_control(request, body)
2.16 +
2.17 + # Save the target page, removing any introduced directives.
2.18 +
2.19 + body = remove_directives(body, ["acl", "parent-revision"])
2.20
2.21 try:
2.22 target_page.saveText(body, 0, comment=_("Changes to page approved from queue revision %d.") % rev)
3.1 --- a/events/queue_for_review.py Thu Oct 13 21:29:22 2011 +0200
3.2 +++ b/events/queue_for_review.py Thu Oct 13 22:48:25 2011 +0200
3.3 @@ -41,14 +41,18 @@
3.4 elif not is_approved(request):
3.5
3.6 # Save the page in the queue.
3.7 - # NOTE: Record the parent revision.
3.8 - # NOTE: (to-do/record-parent-for-proper-merges.txt)
3.9
3.10 new_page = PageEditor(request, "%s/%s" % (pagename, queued_changes_page))
3.11
3.12 # Add an ACL to prevent normal users from seeing the page anywhere.
3.13 + # Add a parent revision to the page.
3.14
3.15 - body = add_access_control(request, body)
3.16 + directives = [
3.17 + get_access_control_directive(request),
3.18 + get_parent_revision_directive(request, pagename)
3.19 + ]
3.20 +
3.21 + body = add_directives(body, directives)
3.22
3.23 username = request.user.name
3.24 comment = (username or _("anonymous")) + " : " + _("Queued page edit")