1 # -*- coding: iso-8859-1 -*- 2 """ 3 MoinMoin - Queue changes for review 4 5 Queue changed pages edited by unprivileged users for review by the 6 ApproveChanges action. 7 8 @copyright: 2011 Paul Boddie <paul@boddie.org.uk> 9 @license: GNU GPL, see COPYING for details. 10 """ 11 12 from MoinMoin.PageEditor import PageEditor 13 from MoinMoin.events import PagePreSaveEvent, Abort 14 from ApproveChangesSupport import * 15 16 def handle_presave(event): 17 request = event.request 18 _ = request.getText 19 20 queued_changes_page = get_queued_changes_page(request) 21 22 pagename = event.page_editor.page_name 23 body = event.new_text 24 25 # Saving into queues has to be permitted or the mechanism will keep trying 26 # to save into a queue of the specified page. 27 28 if is_queued_changes_page(request, pagename): 29 30 # Test the integrity of the page in order to prevent direct replacement 31 # of the page. Reviewers can change the page as they please. 32 33 if is_reviewer(request) or is_queued_changes_user(request): 34 return None 35 else: 36 return Abort(_("Queued changes may not be edited.")) 37 38 # For normal pages, the user has to be approved. Otherwise, the page will be 39 # saved into a queue. If the save operation occurs as part of an approval 40 # action, however, the effective user will be able to save the page. 41 42 elif not request.action == "ApproveChanges" and not is_approved(request): 43 44 # Save the page in the queue. 45 46 new_page = PageEditor(request, "%s/%s" % (pagename, queued_changes_page)) 47 48 # Add an ACL to prevent normal users from seeing the page anywhere. 49 # Add a parent revision to the page. 50 51 directives = [ 52 get_access_control_directive(request), 53 get_parent_revision_directive(request, pagename), 54 get_user_directive(request) 55 ] 56 57 body = add_directives(body, directives) 58 59 username = request.user.name 60 comment = (username or _("anonymous")) + " : " + _("Queued page edit") 61 62 try: 63 # Switch user in order to save a page with an ACL. 64 65 user = request.user 66 request.user = get_user_for_saving(request) 67 try: 68 new_page.saveText(body, 0, comment=comment) 69 finally: 70 request.user = user 71 72 except PageEditor.Unchanged: 73 pass 74 75 # Abort the page save operation. 76 77 return Abort(_("Your changes have been queued for approval.")) 78 79 return None 80 81 def handle(event): 82 if isinstance(event, PagePreSaveEvent): 83 return handle_presave(event) 84 85 # vim: tabstop=4 expandtab shiftwidth=4