[Bps-public-commit] rt-extension-spamfilter branch, master, updated. bea1b0c0b71f40bff70bdbe8204f080c1573759b

? sunnavy sunnavy at bestpractical.com
Fri Mar 5 08:44:22 EST 2021


The branch, master has been updated
       via  bea1b0c0b71f40bff70bdbe8204f080c1573759b (commit)
       via  37745c331f761f0581f9dc97e43ee06b32716692 (commit)
       via  f3e2969a70cf859c807ba951fba8c33ec92fd485 (commit)
      from  121bb2d8bfe3cde44972be28b4ae8b68ffb61050 (commit)

Summary of changes:
 html/Elements/RT__Spam/ColumnMap   | 24 +++++++++++++++++++
 html/Tools/SpamFilter/Display.html | 25 ++++----------------
 html/Tools/SpamFilter/List.html    | 46 ++++++++++++++++++++++++++++++++++++-
 lib/RT/Spam.pm                     | 47 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 121 insertions(+), 21 deletions(-)

- Log -----------------------------------------------------------------
commit 37745c331f761f0581f9dc97e43ee06b32716692
Author: Dianne Skoll <dianne at bestpractical.com>
Date:   Wed Mar 3 09:26:36 2021 -0500

    Implement "Delete" and "Not Spam" buttons in each row of the list view

diff --git a/html/Elements/RT__Spam/ColumnMap b/html/Elements/RT__Spam/ColumnMap
index 67b79d4..339867d 100644
--- a/html/Elements/RT__Spam/ColumnMap
+++ b/html/Elements/RT__Spam/ColumnMap
@@ -52,6 +52,26 @@ $Attr => undef
 
 
 <%once>
+
+# For readability, ncapsulate the button-generating code into a
+# function here rather than putting it inline in the big hash.
+my $buttons_sub = sub {
+    my ($email) = @_;
+
+    my $ret = '';
+    if ($email->Status ne 'resolved') {
+       $ret .= '<button type="button" class="create_user" name="Release-' . $email->id . '">' . loc('Not Spam') . '</button>';
+    }
+    if ($email->Status ne 'deleted') {
+        $ret .= ' <button type="button" class="discard" name="Delete-' . $email->id . '">' . loc('Delete') . '</button>';
+    }
+
+    # Here's a magical thing... if you return a *reference* to a scalar,
+    # the result is not HTML-escaped.  If you just return a scalar, it is.
+    # Hence the \ before $ret.
+    return \$ret;
+};
+
 my $COLUMN_MAP;
 
 $COLUMN_MAP = {
@@ -91,6 +111,10 @@ $COLUMN_MAP = {
         title     => 'Score', # loc
         value     => sub { return $_[0]->Score }
     },
+    Disposition => {
+        title     => 'Disposition', #loc
+        value     => $buttons_sub,
+    },
 };
 
 </%once>
diff --git a/html/Tools/SpamFilter/List.html b/html/Tools/SpamFilter/List.html
index 87d1e8c..79db9eb 100644
--- a/html/Tools/SpamFilter/List.html
+++ b/html/Tools/SpamFilter/List.html
@@ -48,6 +48,25 @@
 <& /Elements/Header, Title => $title &>
 <& /Elements/Tabs &>
 
+<script type="text/javascript">
+    jQuery( function() {
+        jQuery('button.create_user').click( function () {
+            url = new URL(window.location.href);
+            status = url.searchParams.get('Status') || 'new';
+            bits = this.name.split('-');
+            window.location.href = '?emailid=' + bits[1] + '&Action=' + bits[0] + '&Status=' + status;
+        });
+        jQuery('button.discard').click( function () {
+            url = new URL(window.location.href);
+            status = url.searchParams.get('Status') || 'new';
+            bits = this.name.split('-');
+            window.location.href = '?emailid=' + bits[1] + '&Action=' + bits[0] + '&Status=' + status;
+        });
+    });
+</script>
+
+<& /Elements/ListActions, actions => \@results &>
+
 <div class="spams">
 <& /Elements/CollectionList, 
     Collection => $emails,
@@ -62,7 +81,9 @@
 
 <%init>
 
-$Format ||= qq{'<a href="__WebPath__/Tools/SpamFilter/Display.html?id=__id__">__id__</a>/TITLE:#','<a href="__WebPath__/Tools/SpamFilter/Display.html?id=__id__">__Subject__</a>',__From__,__To__,__Status__,__Date__,__Score__};
+my @results;
+$Format ||= qq{'<a href="__WebPath__/Tools/SpamFilter/Display.html?id=__id__">__id__</a>/TITLE:#','<a href="__WebPath__/Tools/SpamFilter/Display.html?id=__id__">__Subject__</a>',__From__,__To__,__Status__,__Date__,__Score__,__Disposition__};
+
 $Order    ||= 'ASC';
 $OrderBy  ||= 'id';
 
@@ -70,6 +91,27 @@ $Rows ||= 50;
 $Page = 1 unless $Page && $Page > 0;
 
 use RT::Spams;
+use RT::Spam;
+
+if ($Action && $emailid) {
+    my $email = RT::Spam->new($session{'CurrentUser'}) ;
+    $email->Load($emailid);
+    if ($email->id) {
+        my ($ret, $msg, $ticket);
+        if ($Action eq 'Delete') {
+            ($ret, $msg) = $email->Delete();
+            if ($ret) {
+                push(@results, loc('Marked item [_1] as spam', $email->id));
+            }
+        } elsif ($Action eq 'Release') {
+            ($ret, $msg, $ticket) = $email->Release(\%session);
+            if ($ret) {
+                push(@results, loc('Marked item [_1] as non-spam and created ticket #[_2]', $email->id, $ticket->Id));
+            }
+        }
+    }
+}
+
 my $emails = RT::Spams->new($session{'CurrentUser'}) ;
 $emails->Limit(FIELD => 'Status', VALUE => $Status );
 $emails->OrderBy( FIELD => $OrderBy, ORDER => $Order );
@@ -94,4 +136,6 @@ $Page => 1
 $OrderBy => undef
 $Order => undef
 $Status => 'new'
+$Action => undef,
+$emailid => undef
 </%ARGS>

commit bea1b0c0b71f40bff70bdbe8204f080c1573759b
Merge: 121bb2d 37745c3
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Mar 5 21:43:36 2021 +0800

    Merge branch 'add-spam-notspam-buttons-to-list-display'


-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list