[Bps-public-commit] rt-extension-spamfilter branch add-checkbox-selection created. 27717d5461b9ae3aabf5475516a3dcba385ea114
BPS Git Server
git at git.bestpractical.com
Fri Jul 7 19:26:55 UTC 2023
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt-extension-spamfilter".
The branch, add-checkbox-selection has been created
at 27717d5461b9ae3aabf5475516a3dcba385ea114 (commit)
- Log -----------------------------------------------------------------
commit 27717d5461b9ae3aabf5475516a3dcba385ea114
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date: Fri Jul 7 16:26:05 2023 -0300
Implement checkbox selection for spam filter actions
It's now possible to select multiple spam filter actions and perform
bulk actions on them.
diff --git a/html/Elements/RT__Spam/ColumnMap b/html/Elements/RT__Spam/ColumnMap
index 339867d..81ea987 100644
--- a/html/Elements/RT__Spam/ColumnMap
+++ b/html/Elements/RT__Spam/ColumnMap
@@ -53,25 +53,6 @@ $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 = {
@@ -111,10 +92,52 @@ $COLUMN_MAP = {
title => 'Score', # loc
value => sub { return $_[0]->Score }
},
- Disposition => {
- title => 'Disposition', #loc
- value => $buttons_sub,
+ NotSpam => {
+ # 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.
+ title => sub {
+ return \qq{
+<div class="custom-control custom-checkbox">
+ <input type="checkbox" name="not_spam_all" id="not_spam_all" value="1" class="checkbox custom-control-input" />
+ <label class="custom-control-label" for="not_spam_all">Not Spam</label>
+</div>
+};
+ },
+ value => sub {
+ if ( $_[0]->Status ne 'resolved' ) {
+ return \(
+'<div class="custom-control custom-checkbox">
+ <input type="checkbox" name="Release" id="Release-'.$_[0]->id.'" value="'.$_[0]->id.'" class="not_spam checkbox custom-control-input" />
+ <label class="custom-control-label" for="Release-'.$_[0]->id.'"></label>
+</div>');
+ }
+ },
},
+ Delete => {
+ # 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.
+ title => sub {
+ return \qq{
+<div class="custom-control custom-checkbox">
+ <input type="checkbox" name="discard_all" id="discard_all" value="1" class="checkbox custom-control-input" />
+ <label class="custom-control-label" for="discard_all">Delete</label>
+</div>
+};
+ },
+ value => sub {
+ if ( $_[0]->Status ne 'deleted' ) {
+ return \(
+'<div class="custom-control custom-checkbox">
+ <input type="checkbox" name="Delete" id="Delete-'.$_[0]->id.'" value="'.$_[0]->id.'" class="discard checkbox custom-control-input" />
+ <label class="custom-control-label" for="Delete-'.$_[0]->id.'"></label>
+</div>');
+ }
+ },
+ },
+
+
};
</%once>
diff --git a/html/Tools/SpamFilter/List.html b/html/Tools/SpamFilter/List.html
index cd02b90..cbf32c3 100644
--- a/html/Tools/SpamFilter/List.html
+++ b/html/Tools/SpamFilter/List.html
@@ -50,17 +50,40 @@
<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('#not_spam_all').change( function () {
+ // toggle all checkboxes
+ jQuery('input.not_spam').prop('checked', this.checked).change();
+ jQuery('#discard_all').prop('checked', false);
});
- 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;
+ jQuery('#discard_all').change( function () {
+ // toggle all checkboxes
+ jQuery('input.discard').prop('checked', this.checked).change();
+ jQuery('#not_spam_all').prop('checked', false);
+ });
+ // check if the corresponding Release-X or Delete-X is already checked
+ // and uncheck it
+ jQuery('input.not_spam,input.discard').change( function () {
+ // get id and split it
+ var id = this.id.split('-');
+
+ if (!this.checked) {
+ // disable the oposite checkbox
+ if (id[0] == 'Release') {
+ jQuery('#not_spam_all').prop('checked', false);
+ } else {
+ jQuery('#discard_all').prop('checked', false);
+ }
+ return;
+ } else {
+ // disable the oposite checkbox
+ if (id[0] == 'Release') {
+ jQuery('#Delete-' + id[1]).prop('checked', false);
+ jQuery('#discard_all').prop('checked', false);
+ } else {
+ jQuery('#Release-' + id[1]).prop('checked', false);
+ jQuery('#not_spam_all').prop('checked', false);
+ }
+ }
});
});
</script>
@@ -68,6 +91,7 @@
<& /Elements/ListActions, actions => \@results &>
<div class="spams">
+<form method="post" enctype="multipart/form-data" name="SpamUpdate" id="SpamUpdate">
<& /Elements/CollectionList,
Collection => $emails,
AllowSorting => 1,
@@ -81,10 +105,43 @@
&>
</div>
+<hr />
+
+<div class="form-row">
+ <div class="col-12">
+ <& /Elements/Submit, Label => loc('Update') &>
+ </div>
+</div>
+
+</form>
+
<%init>
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__};
+$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__
+};
+
+if (!$Status || $Status eq 'new') {
+ $Format .= qq{
+ __NotSpam__,
+ __Delete__
+ };
+} elsif ($Status eq 'resolved') {
+ $Format .= qq{
+ __Delete__
+ };
+} elsif ($Status eq 'deleted') {
+ $Format .= qq{
+ __NotSpam__
+ };
+}
$Order ||= 'ASC';
$OrderBy ||= 'id';
@@ -94,19 +151,36 @@ $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 ($Delete) {
+ my @ToBeDeleted;
+ if (ref $Delete eq 'ARRAY') {
+ @ToBeDeleted = @$Delete;
+ } else {
+ push @ToBeDeleted, $Delete;
+ };
+ foreach my $id (@ToBeDeleted) {
+ my $email = RT::Spam->new($session{'CurrentUser'}) ;
+ $email->Load($id);
+ if ($email->id) {
+ my ($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 ($Release) {
+ my @ToBeReleased;
+ if (ref $Release eq 'ARRAY') {
+ @ToBeReleased = @$Release;
+ } else {
+ push @ToBeReleased, $Release;
+ };
+ foreach my $id (@ToBeReleased) {
+ my $email = RT::Spam->new($session{'CurrentUser'}) ;
+ $email->Load($id);
+ if ($email->id) {
+ my ($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));
}
@@ -138,6 +212,6 @@ $Page => 1
$OrderBy => undef
$Order => undef
$Status => 'new'
-$Action => undef,
-$emailid => undef
+$Delete => undef
+$Release => undef
</%ARGS>
commit e7a4079a5471dd8edb674060179b178f380742aa
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date: Fri Jul 7 16:23:17 2023 -0300
Fix keeping the same Status after update
SpamFilter List was loosing Status filter and going back to the home page
after update.
diff --git a/html/Tools/SpamFilter/List.html b/html/Tools/SpamFilter/List.html
index 79db9eb..cd02b90 100644
--- a/html/Tools/SpamFilter/List.html
+++ b/html/Tools/SpamFilter/List.html
@@ -76,6 +76,8 @@
Rows => $Rows,
Page => $Page,
Format => $Format,
+ PassArguments => ['Status'],
+ Status => $Status,
&>
</div>
commit 58bb58fd600fb52594ea829c36c261aa9580cec8
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date: Fri Jul 7 16:09:39 2023 -0300
Update POD with correct version of RT where patch was cored
The required patch was added to RT 5.0.5 and not on 5.0.2.
diff --git a/lib/RT/Extension/SpamFilter.pm b/lib/RT/Extension/SpamFilter.pm
index 4cef706..6be72b5 100644
--- a/lib/RT/Extension/SpamFilter.pm
+++ b/lib/RT/Extension/SpamFilter.pm
@@ -72,7 +72,7 @@ in your database.
If you are upgrading this module, check for upgrading instructions
in case changes need to be made to your database.
-=item Patch RT earlier than 5.0.2
+=item Patch RT earlier than 5.0.5
patch -d /opt/rt5 -p1 < patches/0001-Pass-action-info-to-GetCurrentUser-for-email-interfa.patch
-----------------------------------------------------------------------
hooks/post-receive
--
rt-extension-spamfilter
More information about the Bps-public-commit
mailing list