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@0 | 6 | unprivileged user attempted to save a page. Since queued pages are placed in |
paul@0 | 7 | a subpage area, 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@0 | 18 | |
paul@0 | 19 | # Action class and supporting functions. |
paul@0 | 20 | |
paul@0 | 21 | class ApproveChanges(ActionBase): |
paul@0 | 22 | |
paul@0 | 23 | "An action which approves a queued page version." |
paul@0 | 24 | |
paul@0 | 25 | def __init__(self, pagename, request): |
paul@0 | 26 | ActionBase.__init__(self, pagename, request) |
paul@0 | 27 | _ = self._ |
paul@0 | 28 | self.form_trigger = "approve" |
paul@0 | 29 | self.form_trigger_label = _("Approve changes") |
paul@0 | 30 | |
paul@0 | 31 | def get_form_html(self, buttons_html): |
paul@0 | 32 | _ = self._ |
paul@0 | 33 | request = self.request |
paul@0 | 34 | fmt = request.formatter |
paul@0 | 35 | prompt = _("Approve the displayed page version?") |
paul@0 | 36 | return fmt.paragraph(1) + fmt.text(prompt) + fmt.paragraph(0) + \ |
paul@0 | 37 | fmt.paragraph(1) + fmt.rawHTML(buttons_html) + fmt.paragraph(0) |
paul@0 | 38 | |
paul@0 | 39 | def do_action(self): |
paul@0 | 40 | |
paul@0 | 41 | "Approve the page and move it into place." |
paul@0 | 42 | |
paul@0 | 43 | _ = self._ |
paul@0 | 44 | request = self.request |
paul@0 | 45 | |
paul@0 | 46 | # Make sure that only suitably privileged users can perform this action. |
paul@0 | 47 | |
paul@0 | 48 | reviewers_group = getattr(request.cfg, "reviewers_group", "PageReviewersGroup") |
paul@0 | 49 | |
paul@0 | 50 | if not request.user.valid or ( |
paul@0 | 51 | not request.dicts.has_member(reviewers_group, request.user.name) and \ |
paul@0 | 52 | not request.user.isSuperUser()): |
paul@0 | 53 | |
paul@0 | 54 | return 0, _("Only page reviewers can perform this action.") |
paul@0 | 55 | |
paul@0 | 56 | # Edit the target page, using this page's content. |
paul@0 | 57 | # The current page should have a name of the form... |
paul@0 | 58 | # ".../TargetPage/ApprovalQueue/n" |
paul@0 | 59 | |
paul@0 | 60 | target_page_name = "/".join(self.pagename.split("/")[:-2]) |
paul@0 | 61 | target_page = PageEditor(request, target_page_name) |
paul@0 | 62 | |
paul@0 | 63 | # Save the target page. |
paul@0 | 64 | |
paul@0 | 65 | try: |
paul@0 | 66 | target_page.saveText(self.page.get_raw_body(), 0) |
paul@0 | 67 | except PageEditor.Unchanged: |
paul@0 | 68 | pass |
paul@0 | 69 | |
paul@0 | 70 | # Delete the current page. |
paul@0 | 71 | |
paul@0 | 72 | current_page = PageEditor(request, self.pagename) |
paul@0 | 73 | current_page.deletePage(_("Changes to page approved.")) |
paul@0 | 74 | |
paul@0 | 75 | # Redirect to the target page. |
paul@0 | 76 | |
paul@0 | 77 | request.http_redirect(target_page.url(request)) |
paul@0 | 78 | return 1, None |
paul@0 | 79 | |
paul@0 | 80 | def render_success(self, msg, msgtype): |
paul@0 | 81 | |
paul@0 | 82 | """ |
paul@0 | 83 | Render neither 'msg' nor 'msgtype' since redirection should occur |
paul@0 | 84 | instead. |
paul@0 | 85 | NOTE: msgtype is optional because MoinMoin 1.5.x does not support it. |
paul@0 | 86 | """ |
paul@0 | 87 | |
paul@0 | 88 | pass |
paul@0 | 89 | |
paul@0 | 90 | # Action function. |
paul@0 | 91 | |
paul@0 | 92 | def execute(pagename, request): |
paul@0 | 93 | ApproveChanges(pagename, request).render() |
paul@0 | 94 | |
paul@0 | 95 | # vim: tabstop=4 expandtab shiftwidth=4 |