# HG changeset patch # User Paul Boddie # Date 1318636128 -7200 # Node ID f0f973f66678eb012921ec6fc9203eb0391fc7db # Parent 27d8fc550d5eb9ed393503d3b9e311d643345fe5 Added support for noting the unapproved user whose changes are being saved, along with support for switching to the user when approving the changes. Unfortunately, saving a target page will not work as an unapproved user and the changes will just be requeued, so this feature is probably not feasible without bypassing the higher-level page saving support. diff -r 27d8fc550d5e -r f0f973f66678 ApproveChangesSupport.py --- a/ApproveChangesSupport.py Sat Oct 15 01:45:27 2011 +0200 +++ b/ApproveChangesSupport.py Sat Oct 15 01:48:48 2011 +0200 @@ -70,12 +70,21 @@ "Return a user that can save pages with ACLs." username = get_queued_changes_user(request) - uid = user.getUserId(request, username) # If the user does not exist, just return the existing user. + return get_user(request, username) or request.user + +def get_user(request, username): + + "Return the user having the given 'username'." + + uid = user.getUserId(request, username) + + # If the user does not exist, just return None. + if not uid: - return request.user + return None # Otherwise, return the privileged user. @@ -101,6 +110,18 @@ return "#acl %s:read,write,delete,revert,admin All:" % ( get_page_reviewers_group(request)) +def get_user_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: + return "#unapproved-user %s" % request.user.name + else: + return "" + def add_directives(body, directives): "Add to the page 'body' the given 'directives'." diff -r 27d8fc550d5e -r f0f973f66678 actions/ApproveChanges.py --- a/actions/ApproveChanges.py Sat Oct 15 01:45:27 2011 +0200 +++ b/actions/ApproveChanges.py Sat Oct 15 01:48:48 2011 +0200 @@ -101,7 +101,7 @@ # Remove any introduced directives. - body, directives = remove_directives(body, ["acl", "parent-revision"]) + body, directives = remove_directives(body, ["acl", "parent-revision", "unapproved-user"]) # Get the target page's parent revision for the queued changes. @@ -151,10 +151,32 @@ # Save the target page, but only if there is no conflict. if not conflict: + + # Switch user if a specific user was recorded. + + username = directives.get("unapproved-user") + if username: + new_user = get_user(request, username) + else: + new_user = None + + if new_user: + user = request.user + request.user = new_user + + # Save the page. + try: - target_page.saveText(body, 0, comment=comment) - except PageEditor.Unchanged: - pass + try: + target_page.saveText(body, 0, comment=comment) + except PageEditor.Unchanged: + pass + + # Restore the user. + + finally: + if new_user: + request.user = user # Redirect to the target page. diff -r 27d8fc550d5e -r f0f973f66678 events/queue_for_review.py --- a/events/queue_for_review.py Sat Oct 15 01:45:27 2011 +0200 +++ b/events/queue_for_review.py Sat Oct 15 01:48:48 2011 +0200 @@ -49,7 +49,8 @@ directives = [ get_access_control_directive(request), - get_parent_revision_directive(request, pagename) + get_parent_revision_directive(request, pagename), + get_user_directive(request) ] body = add_directives(body, directives)