paul@0 | 1 | # -*- coding: iso-8859-1 -*- |
paul@0 | 2 | """ |
paul@0 | 3 | MoinMoin - ApproveChanges |
paul@0 | 4 | |
paul@0 | 5 | Permit the approval of an edited page queued by the page editor when an |
paul@3 | 6 | unprivileged user attempted to save a page. Since queued changes are placed |
paul@3 | 7 | in a subpage, this action just moves the queued page content into the |
paul@0 | 8 | existing page when approving the changes. |
paul@0 | 9 | |
paul@0 | 10 | @copyright: 2011 Paul Boddie <paul@boddie.org.uk> |
paul@0 | 11 | @license: GNU GPL (v2 or later), see COPYING.txt for details. |
paul@0 | 12 | """ |
paul@0 | 13 | |
paul@0 | 14 | Dependencies = ['pages'] |
paul@0 | 15 | |
paul@0 | 16 | from MoinMoin.action import ActionBase |
paul@0 | 17 | from MoinMoin.PageEditor import PageEditor |
paul@1 | 18 | from MoinMoin.wikiutil import escape |
paul@1 | 19 | from ApproveChangesSupport import * |
paul@0 | 20 | |
paul@0 | 21 | # Action class and supporting functions. |
paul@0 | 22 | |
paul@0 | 23 | class ApproveChanges(ActionBase): |
paul@0 | 24 | |
paul@0 | 25 | "An action which approves a queued page version." |
paul@0 | 26 | |
paul@0 | 27 | def __init__(self, pagename, request): |
paul@0 | 28 | ActionBase.__init__(self, pagename, request) |
paul@0 | 29 | _ = self._ |
paul@0 | 30 | self.form_trigger = "approve" |
paul@0 | 31 | self.form_trigger_label = _("Approve changes") |
paul@0 | 32 | |
paul@0 | 33 | def get_form_html(self, buttons_html): |
paul@0 | 34 | _ = self._ |
paul@0 | 35 | request = self.request |
paul@0 | 36 | fmt = request.formatter |
paul@1 | 37 | |
paul@1 | 38 | d = { |
paul@1 | 39 | "buttons_html" : buttons_html, |
paul@1 | 40 | "prompt" : escape(_("Approve the displayed page version?")), |
paul@1 | 41 | } |
paul@1 | 42 | |
paul@1 | 43 | # Prepare the output HTML. |
paul@1 | 44 | |
paul@1 | 45 | html = ''' |
paul@1 | 46 | <table> |
paul@1 | 47 | <tr> |
paul@4 | 48 | <td>%(prompt)s</td> |
paul@1 | 49 | </tr> |
paul@1 | 50 | <tr> |
paul@1 | 51 | <td class="buttons"> |
paul@1 | 52 | %(buttons_html)s |
paul@1 | 53 | </td> |
paul@1 | 54 | </tr> |
paul@1 | 55 | </table>''' % d |
paul@1 | 56 | |
paul@1 | 57 | return html |
paul@0 | 58 | |
paul@0 | 59 | def do_action(self): |
paul@0 | 60 | |
paul@0 | 61 | "Approve the page and move it into place." |
paul@0 | 62 | |
paul@0 | 63 | _ = self._ |
paul@0 | 64 | request = self.request |
paul@0 | 65 | |
paul@0 | 66 | # Make sure that only suitably privileged users can perform this action. |
paul@0 | 67 | |
paul@3 | 68 | queued_changes_page = get_queued_changes_page(request) |
paul@0 | 69 | |
paul@4 | 70 | if not is_reviewer(request): |
paul@0 | 71 | return 0, _("Only page reviewers can perform this action.") |
paul@0 | 72 | |
paul@0 | 73 | # Edit the target page, using this page's content. |
paul@1 | 74 | # The current page must be a queued page version. |
paul@0 | 75 | |
paul@3 | 76 | if not is_queued_changes_page(request, self.pagename): |
paul@1 | 77 | return 0, _("This page is not queued for approval.") |
paul@1 | 78 | |
paul@1 | 79 | target_page_name = get_target_page_name(self.pagename) |
paul@0 | 80 | target_page = PageEditor(request, target_page_name) |
paul@0 | 81 | |
paul@4 | 82 | # Save the target page, first removing the signature and then removing |
paul@4 | 83 | # any protective ACL. |
paul@4 | 84 | |
paul@4 | 85 | body = self.page.get_raw_body() |
paul@4 | 86 | |
paul@4 | 87 | body = check_page(request, body) |
paul@4 | 88 | if not body: |
paul@4 | 89 | return 0, _("The queued changes have been modified somehow. Not saving!") |
paul@4 | 90 | |
paul@4 | 91 | body = remove_access_control(request, body) |
paul@0 | 92 | |
paul@0 | 93 | try: |
paul@4 | 94 | target_page.saveText(body, 0, comment=_("Changes to page approved.")) |
paul@0 | 95 | except PageEditor.Unchanged: |
paul@0 | 96 | pass |
paul@0 | 97 | |
paul@0 | 98 | # Delete the current page. |
paul@3 | 99 | # NOTE: The page could be deleted completely or certain revisions |
paul@3 | 100 | # NOTE: purged. |
paul@3 | 101 | # NOTE: (to-do/proper-queued-page-deletion.txt) |
paul@0 | 102 | |
paul@0 | 103 | current_page = PageEditor(request, self.pagename) |
paul@0 | 104 | current_page.deletePage(_("Changes to page approved.")) |
paul@0 | 105 | |
paul@0 | 106 | # Redirect to the target page. |
paul@0 | 107 | |
paul@0 | 108 | request.http_redirect(target_page.url(request)) |
paul@0 | 109 | return 1, None |
paul@0 | 110 | |
paul@0 | 111 | def render_success(self, msg, msgtype): |
paul@0 | 112 | |
paul@0 | 113 | """ |
paul@0 | 114 | Render neither 'msg' nor 'msgtype' since redirection should occur |
paul@0 | 115 | instead. |
paul@0 | 116 | NOTE: msgtype is optional because MoinMoin 1.5.x does not support it. |
paul@0 | 117 | """ |
paul@0 | 118 | |
paul@0 | 119 | pass |
paul@0 | 120 | |
paul@0 | 121 | # Action function. |
paul@0 | 122 | |
paul@0 | 123 | def execute(pagename, request): |
paul@0 | 124 | ApproveChanges(pagename, request).render() |
paul@0 | 125 | |
paul@0 | 126 | # vim: tabstop=4 expandtab shiftwidth=4 |