1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/actions/ApproveChanges.py Sun Oct 09 20:37:21 2011 +0200
1.3 @@ -0,0 +1,95 @@
1.4 +# -*- coding: iso-8859-1 -*-
1.5 +"""
1.6 + MoinMoin - ApproveChanges
1.7 +
1.8 + Permit the approval of an edited page queued by the page editor when an
1.9 + unprivileged user attempted to save a page. Since queued pages are placed in
1.10 + a subpage area, this action just moves the queued page content into the
1.11 + existing page when approving the changes.
1.12 +
1.13 + @copyright: 2011 Paul Boddie <paul@boddie.org.uk>
1.14 + @license: GNU GPL (v2 or later), see COPYING.txt for details.
1.15 +"""
1.16 +
1.17 +Dependencies = ['pages']
1.18 +
1.19 +from MoinMoin.action import ActionBase
1.20 +from MoinMoin.PageEditor import PageEditor
1.21 +
1.22 +# Action class and supporting functions.
1.23 +
1.24 +class ApproveChanges(ActionBase):
1.25 +
1.26 + "An action which approves a queued page version."
1.27 +
1.28 + def __init__(self, pagename, request):
1.29 + ActionBase.__init__(self, pagename, request)
1.30 + _ = self._
1.31 + self.form_trigger = "approve"
1.32 + self.form_trigger_label = _("Approve changes")
1.33 +
1.34 + def get_form_html(self, buttons_html):
1.35 + _ = self._
1.36 + request = self.request
1.37 + fmt = request.formatter
1.38 + prompt = _("Approve the displayed page version?")
1.39 + return fmt.paragraph(1) + fmt.text(prompt) + fmt.paragraph(0) + \
1.40 + fmt.paragraph(1) + fmt.rawHTML(buttons_html) + fmt.paragraph(0)
1.41 +
1.42 + def do_action(self):
1.43 +
1.44 + "Approve the page and move it into place."
1.45 +
1.46 + _ = self._
1.47 + request = self.request
1.48 +
1.49 + # Make sure that only suitably privileged users can perform this action.
1.50 +
1.51 + reviewers_group = getattr(request.cfg, "reviewers_group", "PageReviewersGroup")
1.52 +
1.53 + if not request.user.valid or (
1.54 + not request.dicts.has_member(reviewers_group, request.user.name) and \
1.55 + not request.user.isSuperUser()):
1.56 +
1.57 + return 0, _("Only page reviewers can perform this action.")
1.58 +
1.59 + # Edit the target page, using this page's content.
1.60 + # The current page should have a name of the form...
1.61 + # ".../TargetPage/ApprovalQueue/n"
1.62 +
1.63 + target_page_name = "/".join(self.pagename.split("/")[:-2])
1.64 + target_page = PageEditor(request, target_page_name)
1.65 +
1.66 + # Save the target page.
1.67 +
1.68 + try:
1.69 + target_page.saveText(self.page.get_raw_body(), 0)
1.70 + except PageEditor.Unchanged:
1.71 + pass
1.72 +
1.73 + # Delete the current page.
1.74 +
1.75 + current_page = PageEditor(request, self.pagename)
1.76 + current_page.deletePage(_("Changes to page approved."))
1.77 +
1.78 + # Redirect to the target page.
1.79 +
1.80 + request.http_redirect(target_page.url(request))
1.81 + return 1, None
1.82 +
1.83 + def render_success(self, msg, msgtype):
1.84 +
1.85 + """
1.86 + Render neither 'msg' nor 'msgtype' since redirection should occur
1.87 + instead.
1.88 + NOTE: msgtype is optional because MoinMoin 1.5.x does not support it.
1.89 + """
1.90 +
1.91 + pass
1.92 +
1.93 +# Action function.
1.94 +
1.95 +def execute(pagename, request):
1.96 + ApproveChanges(pagename, request).render()
1.97 +
1.98 +# vim: tabstop=4 expandtab shiftwidth=4