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