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, 2013 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 user_specific_queue = get_user_specific_queue(request) 22 23 pagename = event.page_editor.page_name 24 body = event.new_text 25 26 # Saving into queues has to be permitted or the mechanism will keep trying 27 # to save into a queue of the specified page. 28 29 if is_queued_changes_page(request, pagename): 30 31 # Test the integrity of the page in order to prevent direct replacement 32 # of the page. Reviewers can change the page as they please. 33 34 if is_reviewer(request) or is_queued_changes_user(request): 35 return None 36 else: 37 return Abort(_("Queued changes may not be edited.")) 38 39 # For normal pages, the user has to be approved. Otherwise, the page will be 40 # saved into a queue. If the save operation occurs as part of an approval 41 # action, however, the effective user will be able to save the page. 42 43 elif not request.action == "ApproveChanges" and not is_approved(request): 44 45 # Save the page in the queue. 46 47 new_page = PageEditor(request, "%s/%s%s" % (pagename, user_specific_queue, queued_changes_page)) 48 49 # Add an ACL to prevent normal users from seeing the page anywhere. 50 # Add a parent revision to the page. 51 52 directives = [ 53 get_access_control_directive(request), 54 get_parent_revision_directive(request, pagename), 55 get_user_directive(request), 56 get_user_queue_directive(request) 57 ] 58 59 body = add_directives(body, directives) 60 61 username = request.user.name 62 comment = (username or _("anonymous")) + " : " + _("Queued page edit") 63 64 try: 65 # Switch user in order to save a page with an ACL. 66 67 user = request.user 68 request.user = get_user_for_saving(request) 69 try: 70 new_page.saveText(body, 0, comment=comment) 71 finally: 72 request.user = user 73 74 except PageEditor.Unchanged: 75 pass 76 77 # Abort the page save operation. 78 79 return Abort(_("Your changes have been queued for approval.")) 80 81 return None 82 83 def handle(event): 84 if isinstance(event, PagePreSaveEvent): 85 return handle_presave(event) 86 87 # vim: tabstop=4 expandtab shiftwidth=4