# HG changeset patch # User Paul Boddie # Date 1383680033 -3600 # Node ID 18c269d09d84347c980ebdc07a0ad2262d9ca43e # Parent 352c175427005a3f4efaa81f16015975e071bbc9 Added initial support for user-specific approval queues. diff -r 352c17542700 -r 18c269d09d84 ApproveChangesSupport.py --- a/ApproveChangesSupport.py Tue Sep 03 00:33:30 2013 +0200 +++ b/ApproveChangesSupport.py Tue Nov 05 20:33:53 2013 +0100 @@ -24,11 +24,19 @@ from MoinMoin.wikiutil import escape import re -__version__ = "0.1.1" +__version__ = "0.2" space_pattern = re.compile("(\s+)") group_member_pattern = re.compile(ur'^ \* +(?:\[\[)?(?P.+?)(?:\]\])? *$', re.MULTILINE | re.UNICODE) +def have_user_specific_queue(request): + return getattr(request.cfg, "queued_changes_per_user", False) + +def get_user_specific_queue(request): + return have_user_specific_queue(request) and \ + request.user.valid and ("%s/" % request.user.name) or \ + "" + def get_queued_changes_page(request): return getattr(request.cfg, "queued_changes_page", "ApprovalQueue") @@ -64,11 +72,14 @@ parts = pagename.split("/") return len(parts) > 1 and parts[-1] == get_queued_changes_page(request) -def get_target_page_name(pagename): +def get_target_page_name(page): + + "Return the target page name for the given queued changes 'page'." - "Return the target page name for the given queued changes 'pagename'." - - return "/".join(pagename.split("/")[:-1]) + directive = "unapproved-user-queue" + body, directives = remove_directives(page.get_raw_body(), [directive]) + extra_parts = directives.has_key(directive) and 2 or 1 + return "/".join(page.page_name.split("/")[:-extra_parts]) def get_user_for_saving(request): @@ -127,6 +138,18 @@ else: return "" +def get_user_queue_directive(request): + + """ + Using the 'request', return a user directive for use in a page body in order + to record who saved the changes originally. + """ + + if request.user.valid and have_user_specific_queue(request): + return "#unapproved-user-queue" + else: + return "" + def add_directives(body, directives): "Add to the page 'body' the given 'directives'." diff -r 352c17542700 -r 18c269d09d84 PKG-INFO --- a/PKG-INFO Tue Sep 03 00:33:30 2013 +0200 +++ b/PKG-INFO Tue Nov 05 20:33:53 2013 +0100 @@ -1,12 +1,12 @@ Metadata-Version: 1.1 Name: ApproveChanges -Version: 0.1.1 +Version: 0.2 Author: Paul Boddie Author-email: paul at boddie org uk Maintainer: Paul Boddie Maintainer-email: paul at boddie org uk Home-page: http://moinmo.in/ActionMarket/ApproveChanges -Download-url: http://moinmo.in/ActionMarket/ApproveChanges?action=AttachFile&do=view&target=ApproveChanges-0.1.1.tar.bz2 +Download-url: http://moinmo.in/ActionMarket/ApproveChanges?action=AttachFile&do=view&target=ApproveChanges-0.2.tar.bz2 Summary: Queue untrusted page changes for approval License: GPL (version 2 or later) Description: The ApproveChanges action for MoinMoin, along with the queue_for_review event diff -r 352c17542700 -r 18c269d09d84 README.txt --- a/README.txt Tue Sep 03 00:33:30 2013 +0200 +++ b/README.txt Tue Nov 05 20:33:53 2013 +0100 @@ -161,6 +161,11 @@ Copyright and licence information can be found in the docs directory - see docs/COPYING.txt and docs/LICENCE.txt for more information. +New in ApproveChanges 0.2 (Changes since ApproveChanges 0.1.1) +-------------------------------------------------------------- + + * Added user-specific approval queues. + New in ApproveChanges 0.1.1 (Changes since ApproveChanges 0.1) -------------------------------------------------------------- diff -r 352c17542700 -r 18c269d09d84 actions/ApproveChanges.py --- a/actions/ApproveChanges.py Tue Sep 03 00:33:30 2013 +0200 +++ b/actions/ApproveChanges.py Tue Nov 05 20:33:53 2013 +0100 @@ -7,7 +7,7 @@ in a subpage, this action just moves the queued page content into the existing page when approving the changes. - @copyright: 2011 Paul Boddie + @copyright: 2011, 2013 Paul Boddie @license: GNU GPL (v2 or later), see COPYING.txt for details. """ @@ -25,6 +25,8 @@ "An action which approves a queued page version." + queued_content_directives = ["acl", "parent-revision", "unapproved-user", "unapproved-user-queue"] + def __init__(self, pagename, request): ActionBase.__init__(self, pagename, request) _ = self._ @@ -61,11 +63,11 @@ # Get information about the queued changes. body = self.get_body(rev) - _body, directives = remove_directives(body, ["acl", "parent-revision", "unapproved-user"]) + _body, directives = remove_directives(body, self.queued_content_directives) # Get the target page's parent revision for the queued changes. - target_page_name = get_target_page_name(self.pagename) + target_page_name = get_target_page_name(self.page) target_page = PageEditor(request, target_page_name) current_rev = target_page.current_rev() @@ -146,11 +148,11 @@ # Remove any introduced directives. - body, directives = remove_directives(body, ["acl", "parent-revision", "unapproved-user"]) + body, directives = remove_directives(body, self.queued_content_directives) # Get the target page's parent revision for the queued changes. - target_page_name = get_target_page_name(self.pagename) + target_page_name = get_target_page_name(self.page) target_page = PageEditor(request, target_page_name) current_rev = target_page.current_rev() @@ -200,7 +202,9 @@ # Prepare a comment. - comment = _("Changes to page approved from queue revision %d.") % rev + comment = username and \ + _("Changes to page by %s approved from queue revision %d.") % (username, rev) or \ + _("Changes to page approved from queue revision %d.") % rev # Save the target page, but only if there is no conflict. diff -r 352c17542700 -r 18c269d09d84 events/queue_for_review.py --- a/events/queue_for_review.py Tue Sep 03 00:33:30 2013 +0200 +++ b/events/queue_for_review.py Tue Nov 05 20:33:53 2013 +0100 @@ -5,7 +5,7 @@ Queue changed pages edited by unprivileged users for review by the ApproveChanges action. - @copyright: 2011 Paul Boddie + @copyright: 2011, 2013 Paul Boddie @license: GNU GPL, see COPYING for details. """ @@ -18,6 +18,7 @@ _ = request.getText queued_changes_page = get_queued_changes_page(request) + user_specific_queue = get_user_specific_queue(request) pagename = event.page_editor.page_name body = event.new_text @@ -43,7 +44,7 @@ # Save the page in the queue. - new_page = PageEditor(request, "%s/%s" % (pagename, queued_changes_page)) + new_page = PageEditor(request, "%s/%s%s" % (pagename, user_specific_queue, queued_changes_page)) # Add an ACL to prevent normal users from seeing the page anywhere. # Add a parent revision to the page. @@ -51,7 +52,8 @@ directives = [ get_access_control_directive(request), get_parent_revision_directive(request, pagename), - get_user_directive(request) + get_user_directive(request), + get_user_queue_directive(request) ] body = add_directives(body, directives) diff -r 352c17542700 -r 18c269d09d84 setup.py --- a/setup.py Tue Sep 03 00:33:30 2013 +0200 +++ b/setup.py Tue Nov 05 20:33:53 2013 +0100 @@ -8,6 +8,6 @@ author = "Paul Boddie", author_email = "paul@boddie.org.uk", url = "http://moinmo.in/ActionMarket/ApproveChanges", - version = "0.1.1", + version = "0.2", py_modules = ["ApproveChangesSupport"] )