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. 40 41 elif not is_approved(request): 42 43 # Save the page in the queue. 44 45 new_page = PageEditor(request, "%s/%s" % (pagename, queued_changes_page)) 46 47 # Add an ACL to prevent normal users from seeing the page anywhere. 48 # Add a parent revision to the page. 49 50 directives = [ 51 get_access_control_directive(request), 52 get_parent_revision_directive(request, pagename), 53 get_user_directive(request) 54 ] 55 56 body = add_directives(body, directives) 57 58 username = request.user.name 59 comment = (username or _("anonymous")) + " : " + _("Queued page edit") 60 61 try: 62 # Switch user in order to save a page with an ACL. 63 64 user = request.user 65 request.user = get_user_for_saving(request) 66 try: 67 new_page.saveText(body, 0, comment=comment) 68 finally: 69 request.user = user 70 71 except PageEditor.Unchanged: 72 pass 73 74 # Abort the page save operation. 75 76 return Abort(_("Your changes have been queued for approval.")) 77 78 return None 79 80 def handle(event): 81 if isinstance(event, PagePreSaveEvent): 82 return handle_presave(event) 83 84 # vim: tabstop=4 expandtab shiftwidth=4