[Bps-public-commit] RT-Extension-ReportSpam branch, master, updated. 0.12
Thomas Sibley
trs at bestpractical.com
Thu Aug 1 16:39:19 EDT 2013
The branch, master has been updated
via dee62261ea1c35a176a2fc2a42faaf54bc87fbf6 (commit)
via 5ece5e74f8a50f73c7327aa62e4de7445df5a59b (commit)
via 7dc00d3ec19216e7aa87492135cb078a55c291cd (commit)
via 9247a434bc2465f34650333e38aeb510ee5b2f9d (commit)
via d5175334c9733e2cfd385e4d54f67f6bd1aa3940 (commit)
via 9a4f7197ee899cc178a65680325d81dfdf5c7458 (commit)
from 8f7c1e30c2d7c2f2d055e2c317b846475890bc64 (commit)
Summary of changes:
Changes | 10 ++++++++++
MANIFEST | 2 ++
META.yml | 2 +-
README | 7 +++++++
bin/auto-delete-retroactively | 42 +++++++++++++++++++++++++++++++++++++++++
bin/spam-report-statistics | 39 ++++++++++++++++++++++++++++++++++++++
html/Ticket/Elements/ReportSpam | 41 +++++++++++++++++++++++++++++++++-------
lib/RT/Extension/ReportSpam.pm | 8 +++++++-
8 files changed, 142 insertions(+), 9 deletions(-)
create mode 100644 bin/auto-delete-retroactively
create mode 100644 bin/spam-report-statistics
- Log -----------------------------------------------------------------
commit 9a4f7197ee899cc178a65680325d81dfdf5c7458
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu Aug 1 12:44:46 2013 -0700
Don't try to delete already deleted tickets
diff --git a/html/Ticket/Elements/ReportSpam b/html/Ticket/Elements/ReportSpam
index 9f27be9..dfdde5b 100644
--- a/html/Ticket/Elements/ReportSpam
+++ b/html/Ticket/Elements/ReportSpam
@@ -32,7 +32,7 @@ if ( $Toggle ) {
push @$reports, $uid;
}
if ( @$reports ) {
- if ( $ticket->CurrentUserHasRight('DeleteTicket') ) {
+ if (lc $ticket->Status ne 'deleted' and $ticket->CurrentUserHasRight('DeleteTicket')) {
my ($status, $msg) = $ticket->SetStatus('deleted');
RT->Logger->error("Couldn't delete ticket: $msg")
unless $status;
commit d5175334c9733e2cfd385e4d54f67f6bd1aa3940
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu Aug 1 13:11:54 2013 -0700
Auto-delete threshold
diff --git a/README b/README
index 84eb899..9983a39 100644
--- a/README
+++ b/README
@@ -18,6 +18,13 @@ INSTALLATION
or add "RT::Extension::ReportSpam" to your existing @Plugins line.
+ You may also want to set the $SpamAutoDeleteThreshold config option
+ to the number of spam reports required before the system will
+ automatically delete the ticket. This is useful if none of your
+ users have DeleteTicket themselves, but collectively they should be
+ able to delete spam tickets for good. Auto-delete is disabled by
+ leaving $SpamAutoDeleteThreshold unset or setting it to 0.
+
Clear your mason cache
rm -rf /opt/rt4/var/mason_data/obj
diff --git a/html/Ticket/Elements/ReportSpam b/html/Ticket/Elements/ReportSpam
index dfdde5b..6119459 100644
--- a/html/Ticket/Elements/ReportSpam
+++ b/html/Ticket/Elements/ReportSpam
@@ -24,6 +24,7 @@ $reports = $reports->Content if $reports;
$reports ||= [];
my $reported = grep $_ == $uid, @$reports;
+my $autodelete = RT->Config->Get("SpamAutoDeleteThreshold") || 0;
if ( $Toggle ) {
if ( $reported ) {
@@ -37,6 +38,21 @@ if ( $Toggle ) {
RT->Logger->error("Couldn't delete ticket: $msg")
unless $status;
}
+ elsif ($autodelete) {
+ # Automatically delete or re-open depending on current report count
+ my $status = @$reports >= $autodelete ? 'deleted' : 'open';
+
+ if (lc $ticket->Status ne lc $status) {
+ RT->Logger->debug(scalar @$reports . " spam reports for ticket @{[$ticket->id]}; automatically setting status to $status");
+
+ my $as_system = RT::Ticket->new( RT->SystemUser );
+ $as_system->Load($ticket->id);
+
+ my ($ok, $msg) = $as_system->SetStatus($status);
+ RT->Logger->error("Couldn't set ticket status to $status as system: $msg")
+ unless $ok;
+ }
+ }
my ($status, $msg) = $ticket->SetAttribute(
Name => 'SpamReports',
Content => $reports,
@@ -44,12 +60,23 @@ if ( $Toggle ) {
RT->Logger->error("Couldn't set attribute: $msg")
unless $status;
} else {
- if ( $ticket->Status eq 'deleted'
- && $ticket->CurrentUserHasRight('ModifyTicket')
- ) {
- my ($status, $msg) = $ticket->SetStatus('open');
- RT->Logger->error("Couldn't undelete ticket: $msg")
- unless $status;
+ if (lc $ticket->Status eq 'deleted') {
+ if ($ticket->CurrentUserHasRight('ModifyTicket')) {
+ my ($status, $msg) = $ticket->SetStatus('open');
+ RT->Logger->error("Couldn't undelete ticket: $msg")
+ unless $status;
+ }
+ elsif ($autodelete) {
+ # Autodelete is enabled, but there are no reports so we should always re-open
+ RT->Logger->debug("No more spam reports for ticket @{[$ticket->id]}; automatically undeleting ticket");
+
+ my $as_system = RT::Ticket->new( RT->SystemUser );
+ $as_system->Load($ticket->id);
+
+ my ($ok, $msg) = $as_system->SetStatus('open');
+ RT->Logger->error("Couldn't undelete ticket as system: $msg")
+ unless $ok;
+ }
}
my ($status, $msg) = $ticket->DeleteAttribute(
'SpamReports'
diff --git a/lib/RT/Extension/ReportSpam.pm b/lib/RT/Extension/ReportSpam.pm
index bce856d..d662a36 100644
--- a/lib/RT/Extension/ReportSpam.pm
+++ b/lib/RT/Extension/ReportSpam.pm
@@ -37,6 +37,12 @@ Add this line:
or add C<RT::Extension::ReportSpam> to your existing C<@Plugins> line.
+You may also want to set the C<$SpamAutoDeleteThreshold> config option to the
+number of spam reports required before the system will automatically delete the
+ticket. This is useful if none of your users have DeleteTicket themselves, but
+collectively they should be able to delete spam tickets for good. Auto-delete
+is disabled by leaving C<$SpamAutoDeleteThreshold> unset or setting it to 0.
+
=item Clear your mason cache
rm -rf /opt/rt4/var/mason_data/obj
commit 9247a434bc2465f34650333e38aeb510ee5b2f9d
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu Aug 1 13:13:29 2013 -0700
Use the first active status instead of hardcoding "open"
More flexibility for lifecycles.
diff --git a/html/Ticket/Elements/ReportSpam b/html/Ticket/Elements/ReportSpam
index 6119459..bd52c40 100644
--- a/html/Ticket/Elements/ReportSpam
+++ b/html/Ticket/Elements/ReportSpam
@@ -40,7 +40,7 @@ if ( $Toggle ) {
}
elsif ($autodelete) {
# Automatically delete or re-open depending on current report count
- my $status = @$reports >= $autodelete ? 'deleted' : 'open';
+ my $status = @$reports >= $autodelete ? 'deleted' : $ticket->FirstActiveStatus;
if (lc $ticket->Status ne lc $status) {
RT->Logger->debug(scalar @$reports . " spam reports for ticket @{[$ticket->id]}; automatically setting status to $status");
@@ -62,7 +62,7 @@ if ( $Toggle ) {
} else {
if (lc $ticket->Status eq 'deleted') {
if ($ticket->CurrentUserHasRight('ModifyTicket')) {
- my ($status, $msg) = $ticket->SetStatus('open');
+ my ($status, $msg) = $ticket->SetStatus($ticket->FirstActiveStatus);
RT->Logger->error("Couldn't undelete ticket: $msg")
unless $status;
}
@@ -73,7 +73,7 @@ if ( $Toggle ) {
my $as_system = RT::Ticket->new( RT->SystemUser );
$as_system->Load($ticket->id);
- my ($ok, $msg) = $as_system->SetStatus('open');
+ my ($ok, $msg) = $as_system->SetStatus($ticket->FirstActiveStatus);
RT->Logger->error("Couldn't undelete ticket as system: $msg")
unless $ok;
}
commit 7dc00d3ec19216e7aa87492135cb078a55c291cd
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu Aug 1 13:15:59 2013 -0700
Quick lightweight tool to gather spam report stats
diff --git a/bin/spam-report-statistics b/bin/spam-report-statistics
new file mode 100644
index 0000000..db2d8a0
--- /dev/null
+++ b/bin/spam-report-statistics
@@ -0,0 +1,39 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use RT -init;
+
+my $attributes = RT::Attributes->new( RT->SystemUser );
+$attributes->Limit( FIELD => 'Name', VALUE => 'SpamReports' );
+$attributes->Limit( FIELD => 'ObjectType', VALUE => 'RT::Ticket' );
+
+my $tickets = 0;
+my $reports = 0;
+
+my $tickets_deleted = 0;
+my $deleted = 0;
+
+my %users;
+
+while (my $attr = $attributes->Next) {
+ $tickets++;
+
+ my $users = $attr->Content || [];
+ $reports += @$users;
+
+ $users{$_}++ for @$users;
+
+ if ($attr->Object->Status eq 'deleted') {
+ $tickets_deleted++;
+ $deleted += @$users;
+ }
+}
+
+my $u = RT::User->new( RT->SystemUser );
+
+printf "Average %4.1f reports per ticket\n", $reports/$tickets;
+printf "Average %4.1f reports per deleted ticket\n", $deleted/$tickets_deleted;
+printf "Top users:\n";
+printf " %4d %s\n", @$_
+ for map { $u->Load($_); [$users{$_}, $u->Name]; } (sort { $users{$b} <=> $users{$a} } keys %users)[0..9];
commit 5ece5e74f8a50f73c7327aa62e4de7445df5a59b
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu Aug 1 13:30:34 2013 -0700
Tool to apply current auto-delete threshold retroactively
Use with caution!
diff --git a/bin/auto-delete-retroactively b/bin/auto-delete-retroactively
new file mode 100644
index 0000000..97aa861
--- /dev/null
+++ b/bin/auto-delete-retroactively
@@ -0,0 +1,42 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use RT -init;
+
+my $attributes = RT::Attributes->new( RT->SystemUser );
+$attributes->Limit( FIELD => 'Name', VALUE => 'SpamReports' );
+$attributes->Limit( FIELD => 'ObjectType', VALUE => 'RT::Ticket' );
+
+my $tickets = $attributes->Join(
+ FIELD1 => 'ObjectId',
+ TABLE2 => 'Tickets',
+ FIELD2 => 'id',
+);
+$attributes->Limit(
+ ALIAS => $tickets,
+ FIELD => 'Status',
+ OPERATOR => '!=',
+ VALUE => 'deleted',
+);
+
+my $deleted = 0;
+my $autodelete = RT->Config->Get("SpamAutoDeleteThreshold") || 0;
+
+die "SpamAutoDeleteThreshold is unset or 0\n"
+ unless $autodelete;
+
+while (my $attr = $attributes->Next) {
+ my $users = $attr->Content || [];
+ next unless @$users >= $autodelete;
+ print "Deleting ticket ", $attr->ObjectId, " with ", scalar @$users, " reports\n";
+
+ my ($ok, $msg) = $attr->Object->SetStatus("deleted");
+ if ($ok) {
+ $deleted++;
+ } else {
+ warn " Failed to delete ", $attr->ObjectId, ": $msg\n";
+ }
+}
+
+print "Deleted $deleted tickets.\n";
commit dee62261ea1c35a176a2fc2a42faaf54bc87fbf6
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu Aug 1 13:16:43 2013 -0700
Releng 0.12
diff --git a/Changes b/Changes
index 8ae48d4..0b73042 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,13 @@
+0.12 Thu Aug 1 13:14:20 PDT 2013
+ * Auto-delete threshold
+ * Use the first active status of the lifecycle instead of hardcoding open
+ * Don't try to delete already deleted tickets
+ * Quick command-line tool to gather spam report stats
+
+0.11 Thu Aug 1 13:12:11 PDT 2013
+ * Improved usage docs
+ * Fix typo in error message when a ticket couldn't be undeleted
+
0.10 Tue Apr 2 09:14:44 PDT 2013
* RT 4.0 compatibility. This release requires RT 4.0. Users of 3.8 should
diff --git a/MANIFEST b/MANIFEST
index 817ffeb..802ed63 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,3 +1,5 @@
+bin/auto-delete-retroactively
+bin/spam-report-statistics
Changes
html/Callbacks/RT-Extension-ReportSpam/Elements/RT__Ticket/ColumnMap/Once
html/Callbacks/RT-Extension-ReportSpam/Elements/Tabs/Privileged
diff --git a/META.yml b/META.yml
index 70a07a3..d133f98 100644
--- a/META.yml
+++ b/META.yml
@@ -22,4 +22,4 @@ requires:
perl: 5.8.0
resources:
license: http://dev.perl.org/licenses/
-version: 0.11
+version: 0.12
diff --git a/lib/RT/Extension/ReportSpam.pm b/lib/RT/Extension/ReportSpam.pm
index d662a36..1051063 100644
--- a/lib/RT/Extension/ReportSpam.pm
+++ b/lib/RT/Extension/ReportSpam.pm
@@ -4,7 +4,7 @@ use 5.008;
use strict;
use warnings;
-our $VERSION = '0.11';
+our $VERSION = '0.12';
=encoding utf-8
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list