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