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 pages are placed in 7 a subpage area, 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 "purge_label" : escape(_("Purge all other queued versions")) 42 } 43 44 # Prepare the output HTML. 45 46 html = ''' 47 <table> 48 <tr> 49 <td colspan="2">%(prompt)s</td> 50 </tr> 51 <tr> 52 <td class="label"><label>%(purge_label)s</label></td> 53 <td> 54 <input name="purge" type="checkbox" value="yes" /> 55 </td> 56 </tr> 57 <tr> 58 <td></td> 59 <td class="buttons"> 60 %(buttons_html)s 61 </td> 62 </tr> 63 </table>''' % d 64 65 return html 66 67 def do_action(self): 68 69 "Approve the page and move it into place." 70 71 _ = self._ 72 request = self.request 73 74 # Make sure that only suitably privileged users can perform this action. 75 76 queued_changes_area = get_queued_changes_area(request) 77 reviewers_group = getattr(request.cfg, "reviewers_group", "PageReviewersGroup") 78 79 if not request.user.valid or ( 80 not request.dicts.has_member(reviewers_group, request.user.name) and \ 81 not request.user.isSuperUser()): 82 83 return 0, _("Only page reviewers can perform this action.") 84 85 # Edit the target page, using this page's content. 86 # The current page must be a queued page version. 87 88 if not is_queued_page(self.pagename, queued_changes_area): 89 return 0, _("This page is not queued for approval.") 90 91 target_page_name = get_target_page_name(self.pagename) 92 target_page = PageEditor(request, target_page_name) 93 94 # Save the target page. 95 96 try: 97 target_page.saveText(self.page.get_raw_body(), 0) 98 except PageEditor.Unchanged: 99 pass 100 101 # Delete the current page. 102 103 current_page = PageEditor(request, self.pagename) 104 current_page.deletePage(_("Changes to page approved.")) 105 106 # Delete the rest of the queue if requested. 107 108 form = get_form(request) 109 110 if form.get("purge"): 111 for name in get_queue_pages(request, target_page_name, queued_changes_area): 112 queue_page = PageEditor(request, name) 113 queue_page.deletePage(_("Changes to page rejected.")) 114 115 # Redirect to the target page. 116 117 request.http_redirect(target_page.url(request)) 118 return 1, None 119 120 def render_success(self, msg, msgtype): 121 122 """ 123 Render neither 'msg' nor 'msgtype' since redirection should occur 124 instead. 125 NOTE: msgtype is optional because MoinMoin 1.5.x does not support it. 126 """ 127 128 pass 129 130 # Action function. 131 132 def execute(pagename, request): 133 ApproveChanges(pagename, request).render() 134 135 # vim: tabstop=4 expandtab shiftwidth=4