ApproveChanges

Changeset

34:5e947e093388
2013-11-10 Paul Boddie raw files shortlog changelog graph Added user blocking and the removal of all queued edits for a user. Fixed "ApprovalQueue" usage, retrieving the configured approval queue page name. default tip
actions/ApproveChanges.py (file)
     1.1 --- a/actions/ApproveChanges.py	Sun Nov 10 01:47:57 2013 +0100
     1.2 +++ b/actions/ApproveChanges.py	Sun Nov 10 15:19:00 2013 +0100
     1.3 @@ -8,6 +8,7 @@
     1.4      existing page when approving the changes.
     1.5  
     1.6      @copyright: 2011, 2013 Paul Boddie <paul@boddie.org.uk>
     1.7 +    @copyright: 2006 MoinMoin:ThomasWaldmann
     1.8      @license: GNU GPL (v2 or later), see COPYING.txt for details.
     1.9  """
    1.10  
    1.11 @@ -16,6 +17,7 @@
    1.12  from MoinMoin.action import ActionBase
    1.13  from MoinMoin.Page import Page
    1.14  from MoinMoin.PageEditor import PageEditor, conflict_markers
    1.15 +from MoinMoin.user import User
    1.16  from MoinMoin.util import diff3
    1.17  from MoinSupport import getPagesForSearch
    1.18  from ApproveChangesSupport import *
    1.19 @@ -51,6 +53,9 @@
    1.20          page = Page(request, self.page.page_name, rev=rev)
    1.21          return page.get_raw_body()
    1.22  
    1.23 +    def get_queued_edits(self, request, username):
    1.24 +        return getPagesForSearch("title:regex:%s/%s$" % (username, get_queued_changes_page(request)), request)
    1.25 +
    1.26      def get_form_html(self, buttons_html):
    1.27          _ = self._
    1.28          request = self.request
    1.29 @@ -82,7 +87,7 @@
    1.30          # Get other edit details, if requested.
    1.31  
    1.32          if form.get("show-edits") and username:
    1.33 -            queued_edits = getPagesForSearch("title:regex:%s/ApprovalQueue$" % username, request)
    1.34 +            queued_edits = self.get_queued_edits(request, username)
    1.35          else:
    1.36              queued_edits = []
    1.37  
    1.38 @@ -94,9 +99,10 @@
    1.39              "discard_edit_label"    : escape(_("Discard the displayed page version")),
    1.40              "editaction_label"      : escape(_("Edit action")),
    1.41              "nothing_label"         : escape(_("Take no action for now")),
    1.42 +            "remove_all_label"      : escape(_("Remove all queued edits by this user")),
    1.43              "rev"                   : escattr(rev),
    1.44              "notice"                : escape(_("The affected page has been edited since the queued changes were made.")),
    1.45 -            "show_edits_label"      : escattr(_("Show all queued edits by this user.")),
    1.46 +            "show_edits_label"      : escattr(_("Show all queued edits by this user")),
    1.47              "showing_edits_label"   : escape(_("Queued edits by this user")),
    1.48              "useraction_label"      : escape(_("User action")),
    1.49              }
    1.50 @@ -106,7 +112,7 @@
    1.51          for value in "nothing", "approve", "block":
    1.52              d["useraction_%s" % value] = form.get("useraction", ["nothing"])[0] == value and "checked='checked'" or ""
    1.53  
    1.54 -        for value in "approve", "discard":
    1.55 +        for value in "approve", "discard", "remove_all":
    1.56              d["editaction_%s" % value] = form.get("editaction", ["approve"])[0] == value and "checked='checked'" or ""
    1.57  
    1.58          # Prepare the output HTML.
    1.59 @@ -124,11 +130,14 @@
    1.60  
    1.61          html += '''
    1.62      <tr>
    1.63 -        <td class="label" rowspan="2"><label>%(editaction_label)s</label></td>
    1.64 +        <td class="label" rowspan="3"><label>%(editaction_label)s</label></td>
    1.65          <td><input name="editaction" type="radio" value="approve" %(editaction_approve)s /> <label>%(approve_edit_label)s</label></td>
    1.66      </tr>
    1.67      <tr>
    1.68          <td><input name="editaction" type="radio" value="discard" %(editaction_discard)s /> <label>%(discard_edit_label)s</label></td>
    1.69 +    </tr>
    1.70 +    <tr>
    1.71 +        <td><input name="editaction" type="radio" value="remove_all" %(editaction_remove_all)s /> <label>%(remove_all_label)s</label></td>
    1.72      </tr>''' % d
    1.73  
    1.74          # User information and actions.
    1.75 @@ -225,17 +234,45 @@
    1.76          # Get the user who submitted the changes.
    1.77  
    1.78          username = directives.get("unapproved-user")
    1.79 +        useraction = form.get("useraction", [""])[0]
    1.80 +        editaction = form.get("editaction", [""])[0]
    1.81  
    1.82          # Approve the user if requested, regardless of what happens below.
    1.83  
    1.84 -        if username and form.get("useraction", [""])[0] == "approve":
    1.85 -            add_to_group_page(request, username, get_approved_editors_group(request))
    1.86 +        if username:
    1.87 +            if useraction == "approve":
    1.88 +                add_to_group_page(request, username, get_approved_editors_group(request))
    1.89 +
    1.90 +            # Disable the user if requested.
    1.91 +
    1.92 +            elif useraction == "block":
    1.93 +                user = User(request, None, username)
    1.94 +
    1.95 +                # From the MoinMoin.script.account.disable module.
    1.96  
    1.97 -        # NOTE: Add user blocking.
    1.98 +                if not user.disabled:
    1.99 +                    user.disabled = 1
   1.100 +                    user.name = "%s-%s" % (user.name, user.id)
   1.101 +                    if user.email:
   1.102 +                        user.email = "%s-%s" % (user.email, user.id)
   1.103 +                    user.subscribed_pages = "" # avoid using email
   1.104 +                    user.save()
   1.105 +
   1.106 +            # Remove all edits if requested.
   1.107 +
   1.108 +            if editaction == "remove_all":
   1.109 +                for queued_page in self.get_queued_edits(request, username):
   1.110 +                    queued_page = PageEditor(request, queued_page.page_name)
   1.111 +                    queued_page.deletePage(_("Changes to page discarded."))
   1.112 +
   1.113 +                # Redirect to the target page.
   1.114 +
   1.115 +                request.http_redirect(target_page.url(request))
   1.116 +                return 1, None
   1.117  
   1.118          # Discard the edit if requested.
   1.119  
   1.120 -        if form.get("editaction", [""])[0] == "discard":
   1.121 +        if editaction == "discard":
   1.122  
   1.123              # NOTE: The page could be deleted completely or certain revisions
   1.124              # NOTE: purged.