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 import re 15 16 def match_queue_pages(pagename, queued_changes_area): 17 18 "Return a filter function which matches subpages of 'pagename'." 19 20 return re.compile(ur"^%s/%s/.*$" % (re.escape(pagename), re.escape(queued_changes_area)), re.UNICODE).match 21 22 def handle_presave(event): 23 request = event.request 24 _ = request.getText 25 26 approved_editors_group = getattr(request.cfg, "approved_editors_group", "ApprovedGroup") 27 queued_changes_area = getattr(request.cfg, "queued_changes_area", "ApprovalQueue") 28 29 pagename = event.page_editor.page_name 30 parts = pagename.split("/") 31 32 # Saving into queues has to be permitted or the mechanism will keep trying 33 # to save into a queue of the specified page. 34 35 if len(parts) > 2 and parts[-2] == queued_changes_area: 36 return None 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 request.user.valid or ( 42 not request.dicts.has_member(approved_editors_group, request.user.name) and \ 43 not request.user.isSuperUser()): 44 45 # Get a queue number by listing the subpages of the queue area and 46 # finding the highest queue number, then adding one to it. 47 48 queue_number = -1 49 50 for name in request.rootpage.getPageList(exists=1, filter=match_queue_pages(pagename, queued_changes_area)): 51 number = name.split("/")[-1] 52 if number.isdigit(): 53 queue_number = max(queue_number, int(number)) 54 55 queue_number += 1 56 57 # Save the page in the queue. 58 59 new_page = PageEditor(request, "%s/%s/%s" % (pagename, queued_changes_area, queue_number)) 60 61 try: 62 new_page.saveText(event.new_text, 0) 63 except PageEditor.Unchanged: 64 pass 65 66 # Abort the page save operation. 67 68 return Abort(_("Your changes have been queued for approval.")) 69 70 def handle(event): 71 if isinstance(event, PagePreSaveEvent): 72 return handle_presave(event) 73 74 # vim: tabstop=4 expandtab shiftwidth=4