1.1 --- a/ApproveChangesSupport.py Sat Oct 15 01:45:27 2011 +0200
1.2 +++ b/ApproveChangesSupport.py Sat Oct 15 01:48:48 2011 +0200
1.3 @@ -70,12 +70,21 @@
1.4 "Return a user that can save pages with ACLs."
1.5
1.6 username = get_queued_changes_user(request)
1.7 - uid = user.getUserId(request, username)
1.8
1.9 # If the user does not exist, just return the existing user.
1.10
1.11 + return get_user(request, username) or request.user
1.12 +
1.13 +def get_user(request, username):
1.14 +
1.15 + "Return the user having the given 'username'."
1.16 +
1.17 + uid = user.getUserId(request, username)
1.18 +
1.19 + # If the user does not exist, just return None.
1.20 +
1.21 if not uid:
1.22 - return request.user
1.23 + return None
1.24
1.25 # Otherwise, return the privileged user.
1.26
1.27 @@ -101,6 +110,18 @@
1.28 return "#acl %s:read,write,delete,revert,admin All:" % (
1.29 get_page_reviewers_group(request))
1.30
1.31 +def get_user_directive(request):
1.32 +
1.33 + """
1.34 + Using the 'request', return a user directive for use in a page body in order
1.35 + to record who saved the changes originally.
1.36 + """
1.37 +
1.38 + if request.user.valid:
1.39 + return "#unapproved-user %s" % request.user.name
1.40 + else:
1.41 + return ""
1.42 +
1.43 def add_directives(body, directives):
1.44
1.45 "Add to the page 'body' the given 'directives'."
2.1 --- a/actions/ApproveChanges.py Sat Oct 15 01:45:27 2011 +0200
2.2 +++ b/actions/ApproveChanges.py Sat Oct 15 01:48:48 2011 +0200
2.3 @@ -101,7 +101,7 @@
2.4
2.5 # Remove any introduced directives.
2.6
2.7 - body, directives = remove_directives(body, ["acl", "parent-revision"])
2.8 + body, directives = remove_directives(body, ["acl", "parent-revision", "unapproved-user"])
2.9
2.10 # Get the target page's parent revision for the queued changes.
2.11
2.12 @@ -151,10 +151,32 @@
2.13 # Save the target page, but only if there is no conflict.
2.14
2.15 if not conflict:
2.16 +
2.17 + # Switch user if a specific user was recorded.
2.18 +
2.19 + username = directives.get("unapproved-user")
2.20 + if username:
2.21 + new_user = get_user(request, username)
2.22 + else:
2.23 + new_user = None
2.24 +
2.25 + if new_user:
2.26 + user = request.user
2.27 + request.user = new_user
2.28 +
2.29 + # Save the page.
2.30 +
2.31 try:
2.32 - target_page.saveText(body, 0, comment=comment)
2.33 - except PageEditor.Unchanged:
2.34 - pass
2.35 + try:
2.36 + target_page.saveText(body, 0, comment=comment)
2.37 + except PageEditor.Unchanged:
2.38 + pass
2.39 +
2.40 + # Restore the user.
2.41 +
2.42 + finally:
2.43 + if new_user:
2.44 + request.user = user
2.45
2.46 # Redirect to the target page.
2.47
3.1 --- a/events/queue_for_review.py Sat Oct 15 01:45:27 2011 +0200
3.2 +++ b/events/queue_for_review.py Sat Oct 15 01:48:48 2011 +0200
3.3 @@ -49,7 +49,8 @@
3.4
3.5 directives = [
3.6 get_access_control_directive(request),
3.7 - get_parent_revision_directive(request, pagename)
3.8 + get_parent_revision_directive(request, pagename),
3.9 + get_user_directive(request)
3.10 ]
3.11
3.12 body = add_directives(body, directives)