ApproveChanges

Changeset

33:b1d7199b2668
2013-11-10 Paul Boddie raw files shortlog changelog graph Changed the action to support discarding of edits, review of other queued edits, and the eventual possibility to block users.
actions/ApproveChanges.py (file)
     1.1 --- a/actions/ApproveChanges.py	Wed Nov 06 17:20:30 2013 +0100
     1.2 +++ b/actions/ApproveChanges.py	Sun Nov 10 01:47:57 2013 +0100
     1.3 @@ -17,6 +17,7 @@
     1.4  from MoinMoin.Page import Page
     1.5  from MoinMoin.PageEditor import PageEditor, conflict_markers
     1.6  from MoinMoin.util import diff3
     1.7 +from MoinSupport import getPagesForSearch
     1.8  from ApproveChangesSupport import *
     1.9  
    1.10  # Action class and supporting functions.
    1.11 @@ -30,8 +31,8 @@
    1.12      def __init__(self, pagename, request):
    1.13          ActionBase.__init__(self, pagename, request)
    1.14          _ = self._
    1.15 -        self.form_trigger = "approve"
    1.16 -        self.form_trigger_label = _("Approve changes")
    1.17 +        self.form_trigger = "execute"
    1.18 +        self.form_trigger_label = _("Execute the indicated changes")
    1.19  
    1.20      def get_revision(self):
    1.21          request = self.request
    1.22 @@ -54,6 +55,7 @@
    1.23          _ = self._
    1.24          request = self.request
    1.25          fmt = request.formatter
    1.26 +        form = get_form(request)
    1.27  
    1.28          if not is_queued_changes_page(request, self.pagename):
    1.29              return fmt.paragraph(1) + fmt.text(_("This page does not show queued changes.")) + fmt.paragraph(0)
    1.30 @@ -77,36 +79,98 @@
    1.31  
    1.32          username = directives.get("unapproved-user")
    1.33  
    1.34 +        # Get other edit details, if requested.
    1.35 +
    1.36 +        if form.get("show-edits") and username:
    1.37 +            queued_edits = getPagesForSearch("title:regex:%s/ApprovalQueue$" % username, request)
    1.38 +        else:
    1.39 +            queued_edits = []
    1.40 +
    1.41          d = {
    1.42              "approval_label"        : escape(_("Make %s an approved user") % username),
    1.43 +            "approve_edit_label"    : escape(_("Approve the displayed page version")),
    1.44 +            "block_label"           : escape(_("Block user %s by disabling their account") % username),
    1.45              "buttons_html"          : buttons_html,
    1.46 -            "prompt"                : escape(_("Approve the displayed page version?")),
    1.47 +            "discard_edit_label"    : escape(_("Discard the displayed page version")),
    1.48 +            "editaction_label"      : escape(_("Edit action")),
    1.49 +            "nothing_label"         : escape(_("Take no action for now")),
    1.50              "rev"                   : escattr(rev),
    1.51              "notice"                : escape(_("The affected page has been edited since the queued changes were made.")),
    1.52 +            "show_edits_label"      : escattr(_("Show all queued edits by this user.")),
    1.53 +            "showing_edits_label"   : escape(_("Queued edits by this user")),
    1.54 +            "useraction_label"      : escape(_("User action")),
    1.55              }
    1.56  
    1.57 +        # Make sure that the radio buttons are selected.
    1.58 +
    1.59 +        for value in "nothing", "approve", "block":
    1.60 +            d["useraction_%s" % value] = form.get("useraction", ["nothing"])[0] == value and "checked='checked'" or ""
    1.61 +
    1.62 +        for value in "approve", "discard":
    1.63 +            d["editaction_%s" % value] = form.get("editaction", ["approve"])[0] == value and "checked='checked'" or ""
    1.64 +
    1.65          # Prepare the output HTML.
    1.66  
    1.67          html = '''
    1.68 -<table>
    1.69 -    <tr>
    1.70 -        <td>%(prompt)s</td>
    1.71 -    </tr>''' % d
    1.72 +<table>'''
    1.73  
    1.74          if parent_rev != current_rev:
    1.75              html += '''
    1.76      <tr>
    1.77 -        <td><em>%(notice)s</em></td>
    1.78 +        <td colspan="2"><strong>%(notice)s</strong></td>
    1.79      </tr>''' % d
    1.80  
    1.81 +        # Actions to be taken with the edit.
    1.82 +
    1.83 +        html += '''
    1.84 +    <tr>
    1.85 +        <td class="label" rowspan="2"><label>%(editaction_label)s</label></td>
    1.86 +        <td><input name="editaction" type="radio" value="approve" %(editaction_approve)s /> <label>%(approve_edit_label)s</label></td>
    1.87 +    </tr>
    1.88 +    <tr>
    1.89 +        <td><input name="editaction" type="radio" value="discard" %(editaction_discard)s /> <label>%(discard_edit_label)s</label></td>
    1.90 +    </tr>''' % d
    1.91 +
    1.92 +        # User information and actions.
    1.93 +
    1.94          if username and not user_is_approved(request, username):
    1.95 +            if not queued_edits:
    1.96 +                html += '''
    1.97 +    <tr>
    1.98 +        <td></td>
    1.99 +        <td><input name="show-edits" type="submit" value="%(show_edits_label)s" /></td>
   1.100 +    </tr>''' % d
   1.101 +            else:
   1.102 +                html += '''
   1.103 +    <tr>
   1.104 +        <td class="label"><label>%(showing_edits_label)s</label></td>
   1.105 +        <td><ul>''' % d
   1.106 +
   1.107 +                for queued_page in queued_edits:
   1.108 +                    html += '''
   1.109 +        <li>%s</li>''' % escape(queued_page.page_name)
   1.110 +
   1.111 +                html += '''
   1.112 +        </ul></td>
   1.113 +    </tr>'''
   1.114 +
   1.115 +            # Actions to be taken with the user.
   1.116 +
   1.117              html += '''
   1.118      <tr>
   1.119 -        <td><input name="approve" type="checkbox" value="true" /> %(approval_label)s</td>
   1.120 +        <td class="label" rowspan="3"><label>%(useraction_label)s</label></td>
   1.121 +        <td><input name="useraction" type="radio" value="nothing" %(useraction_nothing)s /> <label>%(nothing_label)s</label></td>
   1.122 +    </tr>
   1.123 +    <tr>
   1.124 +        <td><input name="useraction" type="radio" value="approve" %(useraction_approve)s /> <label>%(approval_label)s</label></td>
   1.125 +    </tr>
   1.126 +    <tr>
   1.127 +        <td><input name="useraction" type="radio" value="block" %(useraction_block)s /> <label>%(block_label)s</label></td>
   1.128      </tr>''' % d
   1.129  
   1.130          html += '''
   1.131      <tr>
   1.132 +        <td></td>
   1.133          <td class="buttons">
   1.134              %(buttons_html)s
   1.135          </td>
   1.136 @@ -164,9 +228,27 @@
   1.137  
   1.138          # Approve the user if requested, regardless of what happens below.
   1.139  
   1.140 -        if username and form.get("approve", ["false"])[0] == "true":
   1.141 +        if username and form.get("useraction", [""])[0] == "approve":
   1.142              add_to_group_page(request, username, get_approved_editors_group(request))
   1.143  
   1.144 +        # NOTE: Add user blocking.
   1.145 +
   1.146 +        # Discard the edit if requested.
   1.147 +
   1.148 +        if form.get("editaction", [""])[0] == "discard":
   1.149 +
   1.150 +            # NOTE: The page could be deleted completely or certain revisions
   1.151 +            # NOTE: purged.
   1.152 +            # NOTE: (to-do/proper-queued-page-deletion.txt)
   1.153 +
   1.154 +            current_page = PageEditor(request, self.pagename)
   1.155 +            current_page.deletePage(_("Changes to page discarded."))
   1.156 +
   1.157 +            # Redirect to the target page.
   1.158 +
   1.159 +            request.http_redirect(target_page.url(request))
   1.160 +            return 1, None
   1.161 +
   1.162          # Where the parent revision differs from the current revision of the
   1.163          # page, attempt to merge the changes.
   1.164