ApproveChanges

Changeset

28:18c269d09d84
2013-11-05 Paul Boddie raw files shortlog changelog graph Added initial support for user-specific approval queues.
ApproveChangesSupport.py (file) PKG-INFO (file) README.txt (file) actions/ApproveChanges.py (file) events/queue_for_review.py (file) setup.py (file)
     1.1 --- a/ApproveChangesSupport.py	Tue Sep 03 00:33:30 2013 +0200
     1.2 +++ b/ApproveChangesSupport.py	Tue Nov 05 20:33:53 2013 +0100
     1.3 @@ -24,11 +24,19 @@
     1.4  from MoinMoin.wikiutil import escape
     1.5  import re
     1.6  
     1.7 -__version__ = "0.1.1"
     1.8 +__version__ = "0.2"
     1.9  
    1.10  space_pattern = re.compile("(\s+)")
    1.11  group_member_pattern = re.compile(ur'^ \* +(?:\[\[)?(?P<member>.+?)(?:\]\])? *$', re.MULTILINE | re.UNICODE)
    1.12  
    1.13 +def have_user_specific_queue(request):
    1.14 +    return getattr(request.cfg, "queued_changes_per_user", False)
    1.15 +
    1.16 +def get_user_specific_queue(request):
    1.17 +    return have_user_specific_queue(request) and \
    1.18 +        request.user.valid and ("%s/" % request.user.name) or \
    1.19 +        ""
    1.20 +
    1.21  def get_queued_changes_page(request):
    1.22      return getattr(request.cfg, "queued_changes_page", "ApprovalQueue")
    1.23  
    1.24 @@ -64,11 +72,14 @@
    1.25      parts = pagename.split("/")
    1.26      return len(parts) > 1 and parts[-1] == get_queued_changes_page(request)
    1.27  
    1.28 -def get_target_page_name(pagename):
    1.29 +def get_target_page_name(page):
    1.30 +
    1.31 +    "Return the target page name for the given queued changes 'page'."
    1.32  
    1.33 -    "Return the target page name for the given queued changes 'pagename'."
    1.34 -
    1.35 -    return "/".join(pagename.split("/")[:-1])
    1.36 +    directive = "unapproved-user-queue"
    1.37 +    body, directives = remove_directives(page.get_raw_body(), [directive])
    1.38 +    extra_parts = directives.has_key(directive) and 2 or 1
    1.39 +    return "/".join(page.page_name.split("/")[:-extra_parts])
    1.40  
    1.41  def get_user_for_saving(request):
    1.42  
    1.43 @@ -127,6 +138,18 @@
    1.44      else:
    1.45          return ""
    1.46  
    1.47 +def get_user_queue_directive(request):
    1.48 +
    1.49 +    """
    1.50 +    Using the 'request', return a user directive for use in a page body in order
    1.51 +    to record who saved the changes originally.
    1.52 +    """
    1.53 +
    1.54 +    if request.user.valid and have_user_specific_queue(request):
    1.55 +        return "#unapproved-user-queue"
    1.56 +    else:
    1.57 +        return ""
    1.58 +
    1.59  def add_directives(body, directives):
    1.60  
    1.61      "Add to the page 'body' the given 'directives'."
     2.1 --- a/PKG-INFO	Tue Sep 03 00:33:30 2013 +0200
     2.2 +++ b/PKG-INFO	Tue Nov 05 20:33:53 2013 +0100
     2.3 @@ -1,12 +1,12 @@
     2.4  Metadata-Version: 1.1
     2.5  Name: ApproveChanges
     2.6 -Version: 0.1.1
     2.7 +Version: 0.2
     2.8  Author: Paul Boddie
     2.9  Author-email: paul at boddie org uk
    2.10  Maintainer: Paul Boddie
    2.11  Maintainer-email: paul at boddie org uk
    2.12  Home-page: http://moinmo.in/ActionMarket/ApproveChanges
    2.13 -Download-url: http://moinmo.in/ActionMarket/ApproveChanges?action=AttachFile&do=view&target=ApproveChanges-0.1.1.tar.bz2
    2.14 +Download-url: http://moinmo.in/ActionMarket/ApproveChanges?action=AttachFile&do=view&target=ApproveChanges-0.2.tar.bz2
    2.15  Summary: Queue untrusted page changes for approval
    2.16  License: GPL (version 2 or later)
    2.17  Description: The ApproveChanges action for MoinMoin, along with the queue_for_review event
     3.1 --- a/README.txt	Tue Sep 03 00:33:30 2013 +0200
     3.2 +++ b/README.txt	Tue Nov 05 20:33:53 2013 +0100
     3.3 @@ -161,6 +161,11 @@
     3.4  Copyright and licence information can be found in the docs directory - see
     3.5  docs/COPYING.txt and docs/LICENCE.txt for more information.
     3.6  
     3.7 +New in ApproveChanges 0.2 (Changes since ApproveChanges 0.1.1)
     3.8 +--------------------------------------------------------------
     3.9 +
    3.10 +  * Added user-specific approval queues.
    3.11 +
    3.12  New in ApproveChanges 0.1.1 (Changes since ApproveChanges 0.1)
    3.13  --------------------------------------------------------------
    3.14  
     4.1 --- a/actions/ApproveChanges.py	Tue Sep 03 00:33:30 2013 +0200
     4.2 +++ b/actions/ApproveChanges.py	Tue Nov 05 20:33:53 2013 +0100
     4.3 @@ -7,7 +7,7 @@
     4.4      in a subpage, this action just moves the queued page content into the
     4.5      existing page when approving the changes.
     4.6  
     4.7 -    @copyright: 2011 Paul Boddie <paul@boddie.org.uk>
     4.8 +    @copyright: 2011, 2013 Paul Boddie <paul@boddie.org.uk>
     4.9      @license: GNU GPL (v2 or later), see COPYING.txt for details.
    4.10  """
    4.11  
    4.12 @@ -25,6 +25,8 @@
    4.13  
    4.14      "An action which approves a queued page version."
    4.15  
    4.16 +    queued_content_directives = ["acl", "parent-revision", "unapproved-user", "unapproved-user-queue"]
    4.17 +
    4.18      def __init__(self, pagename, request):
    4.19          ActionBase.__init__(self, pagename, request)
    4.20          _ = self._
    4.21 @@ -61,11 +63,11 @@
    4.22          # Get information about the queued changes.
    4.23  
    4.24          body = self.get_body(rev)
    4.25 -        _body, directives = remove_directives(body, ["acl", "parent-revision", "unapproved-user"])
    4.26 +        _body, directives = remove_directives(body, self.queued_content_directives)
    4.27  
    4.28          # Get the target page's parent revision for the queued changes.
    4.29  
    4.30 -        target_page_name = get_target_page_name(self.pagename)
    4.31 +        target_page_name = get_target_page_name(self.page)
    4.32          target_page = PageEditor(request, target_page_name)
    4.33  
    4.34          current_rev = target_page.current_rev()
    4.35 @@ -146,11 +148,11 @@
    4.36  
    4.37          # Remove any introduced directives.
    4.38  
    4.39 -        body, directives = remove_directives(body, ["acl", "parent-revision", "unapproved-user"])
    4.40 +        body, directives = remove_directives(body, self.queued_content_directives)
    4.41  
    4.42          # Get the target page's parent revision for the queued changes.
    4.43  
    4.44 -        target_page_name = get_target_page_name(self.pagename)
    4.45 +        target_page_name = get_target_page_name(self.page)
    4.46          target_page = PageEditor(request, target_page_name)
    4.47  
    4.48          current_rev = target_page.current_rev()
    4.49 @@ -200,7 +202,9 @@
    4.50  
    4.51          # Prepare a comment.
    4.52  
    4.53 -        comment = _("Changes to page approved from queue revision %d.") % rev
    4.54 +        comment = username and \
    4.55 +            _("Changes to page by %s approved from queue revision %d.") % (username, rev) or \
    4.56 +            _("Changes to page approved from queue revision %d.") % rev
    4.57  
    4.58          # Save the target page, but only if there is no conflict.
    4.59  
     5.1 --- a/events/queue_for_review.py	Tue Sep 03 00:33:30 2013 +0200
     5.2 +++ b/events/queue_for_review.py	Tue Nov 05 20:33:53 2013 +0100
     5.3 @@ -5,7 +5,7 @@
     5.4      Queue changed pages edited by unprivileged users for review by the
     5.5      ApproveChanges action.
     5.6  
     5.7 -    @copyright: 2011 Paul Boddie <paul@boddie.org.uk>
     5.8 +    @copyright: 2011, 2013 Paul Boddie <paul@boddie.org.uk>
     5.9      @license: GNU GPL, see COPYING for details.
    5.10  """
    5.11  
    5.12 @@ -18,6 +18,7 @@
    5.13      _ = request.getText
    5.14  
    5.15      queued_changes_page = get_queued_changes_page(request)
    5.16 +    user_specific_queue = get_user_specific_queue(request)
    5.17  
    5.18      pagename = event.page_editor.page_name
    5.19      body = event.new_text
    5.20 @@ -43,7 +44,7 @@
    5.21  
    5.22          # Save the page in the queue.
    5.23  
    5.24 -        new_page = PageEditor(request, "%s/%s" % (pagename, queued_changes_page))
    5.25 +        new_page = PageEditor(request, "%s/%s%s" % (pagename, user_specific_queue, queued_changes_page))
    5.26  
    5.27          # Add an ACL to prevent normal users from seeing the page anywhere.
    5.28          # Add a parent revision to the page.
    5.29 @@ -51,7 +52,8 @@
    5.30          directives = [
    5.31              get_access_control_directive(request),
    5.32              get_parent_revision_directive(request, pagename),
    5.33 -            get_user_directive(request)
    5.34 +            get_user_directive(request),
    5.35 +            get_user_queue_directive(request)
    5.36              ]
    5.37  
    5.38          body = add_directives(body, directives)
     6.1 --- a/setup.py	Tue Sep 03 00:33:30 2013 +0200
     6.2 +++ b/setup.py	Tue Nov 05 20:33:53 2013 +0100
     6.3 @@ -8,6 +8,6 @@
     6.4      author       = "Paul Boddie",
     6.5      author_email = "paul@boddie.org.uk",
     6.6      url          = "http://moinmo.in/ActionMarket/ApproveChanges",
     6.7 -    version      = "0.1.1",
     6.8 +    version      = "0.2",
     6.9      py_modules   = ["ApproveChangesSupport"]
    6.10      )