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 check_page(request, body) or is_reviewer(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 # NOTE: Record the parent revision. 45 # NOTE: (to-do/record-parent-for-proper-merges.txt) 46 47 new_page = PageEditor(request, "%s/%s" % (pagename, queued_changes_page)) 48 49 # Add an ACL to prevent normal users from seeing the page anywhere. 50 51 body = add_access_control(request, body) 52 53 # Sign the page to prevent modification in the queue. 54 55 body = sign_page(request, body) 56 username = request.user.name 57 comment = (username or _("anonymous")) + " : " + _("Queued page edit") 58 59 try: 60 try: 61 new_page.saveText(body, 0, comment=comment) 62 63 # Switch user in order to save a page with an ACL. 64 65 except PageEditor.AccessDenied: 66 user = request.user 67 request.user = get_user_for_saving(request) 68 try: 69 new_page.saveText(body, 0, comment=comment) 70 finally: 71 request.user = user 72 73 except PageEditor.Unchanged: 74 pass 75 76 # Abort the page save operation. 77 78 return Abort(_("Your changes have been queued for approval.")) 79 80 return None 81 82 def handle(event): 83 if isinstance(event, PagePreSaveEvent): 84 return handle_presave(event) 85 86 # vim: tabstop=4 expandtab shiftwidth=4