[Rt-commit] rt branch 5.0/add-auth-token-expires-field updated. rt-5.0.3-523-g0c03be27cb

BPS Git Server git at git.bestpractical.com
Fri Jun 16 15:56:25 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".

The branch, 5.0/add-auth-token-expires-field has been updated
       via  0c03be27cb399bc871e64c0faa689977420592c1 (commit)
      from  6456bbdcd0d6a6a7abc9b1912c76db503b349284 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 0c03be27cb399bc871e64c0faa689977420592c1
Author: Brad Embree <brad at bestpractical.com>
Date:   Fri Jun 16 08:55:01 2023 -0700

    Fix incorrect Limit calls on Pg
    
    The Limit calls were tested on MySQL which is more forgiving than Pg.
    Had to fix the Limit call for the NOT NULL check and remove the Limit
    call that checked for an empty string for it to work on Pg.

diff --git a/local/man/auto/RT/Extension/SMSWebhook/Twilio/.packlist b/local/man/auto/RT/Extension/SMSWebhook/Twilio/.packlist
new file mode 100644
index 0000000000..c88d15fbee
--- /dev/null
+++ b/local/man/auto/RT/Extension/SMSWebhook/Twilio/.packlist
@@ -0,0 +1,4 @@
+/home/brad/BPS/work/rt/local/man/man3/RT::Extension::SMSWebhook::Twilio.3
+/home/brad/BPS/work/rt/local/man/man3/RT::User_Local.3
+/home/brad/BPS/work/rt/local/plugins/RT-Extension-SMSWebhook-Twilio/lib/RT/Extension/SMSWebhook/Twilio.pm
+/home/brad/BPS/work/rt/local/plugins/RT-Extension-SMSWebhook-Twilio/lib/RT/User_Local.pm
diff --git a/local/man/man3/RT::Extension::SMSWebhook::Twilio.3 b/local/man/man3/RT::Extension::SMSWebhook::Twilio.3
new file mode 100644
index 0000000000..92440034d3
--- /dev/null
+++ b/local/man/man3/RT::Extension::SMSWebhook::Twilio.3
@@ -0,0 +1,141 @@
+.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
+.\"
+.\" Standard preamble:
+.\" ========================================================================
+.de Sp \" Vertical space (when we can't use .PP)
+.if t .sp .5v
+.if n .sp
+..
+.de Vb \" Begin verbatim text
+.ft CW
+.nf
+.ne \\$1
+..
+.de Ve \" End verbatim text
+.ft R
+.fi
+..
+.\" Set up some character translations and predefined strings.  \*(-- will
+.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
+.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
+.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
+.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
+.\" nothing in troff, for use with C<>.
+.tr \(*W-
+.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
+.ie n \{\
+.    ds -- \(*W-
+.    ds PI pi
+.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
+.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
+.    ds L" ""
+.    ds R" ""
+.    ds C` ""
+.    ds C' ""
+'br\}
+.el\{\
+.    ds -- \|\(em\|
+.    ds PI \(*p
+.    ds L" ``
+.    ds R" ''
+.    ds C`
+.    ds C'
+'br\}
+.\"
+.\" Escape single quotes in literal strings from groff's Unicode transform.
+.ie \n(.g .ds Aq \(aq
+.el       .ds Aq '
+.\"
+.\" If the F register is >0, we'll generate index entries on stderr for
+.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
+.\" entries marked with X<> in POD.  Of course, you'll have to process the
+.\" output yourself in some meaningful fashion.
+.\"
+.\" Avoid warning from groff about undefined register 'F'.
+.de IX
+..
+.nr rF 0
+.if \n(.g .if rF .nr rF 1
+.if (\n(rF:(\n(.g==0)) \{\
+.    if \nF \{\
+.        de IX
+.        tm Index:\\$1\t\\n%\t"\\$2"
+..
+.        if !\nF==2 \{\
+.            nr % 0
+.            nr F 2
+.        \}
+.    \}
+.\}
+.rr rF
+.\" ========================================================================
+.\"
+.IX Title "RT::Extension::SMSWebhook::Twilio 3"
+.TH RT::Extension::SMSWebhook::Twilio 3 "2022-03-31" "perl v5.34.0" "User Contributed Perl Documentation"
+.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
+.\" way too many mistakes in technical documents.
+.if n .ad l
+.nh
+.SH "NAME"
+RT\-Extension\-SMSWebhook\-Twilio \- [One line description of module's purpose here]
+.SH "DESCRIPTION"
+.IX Header "DESCRIPTION"
+[Why would someone install this extension? What does it do? What problem
+does it solve?]
+.SH "RT VERSION"
+.IX Header "RT VERSION"
+Works with \s-1RT\s0 [What versions of \s-1RT\s0 is this known to work with?]
+.PP
+[Make sure to use requires_rt and rt_too_new in Makefile.PL]
+.SH "INSTALLATION"
+.IX Header "INSTALLATION"
+.ie n .IP """perl Makefile.PL""" 4
+.el .IP "\f(CWperl Makefile.PL\fR" 4
+.IX Item "perl Makefile.PL"
+.PD 0
+.ie n .IP """make""" 4
+.el .IP "\f(CWmake\fR" 4
+.IX Item "make"
+.ie n .IP """make install""" 4
+.el .IP "\f(CWmake install\fR" 4
+.IX Item "make install"
+.PD
+May need root permissions
+.ie n .IP """make initdb""" 4
+.el .IP "\f(CWmake initdb\fR" 4
+.IX Item "make initdb"
+Only run this the first time you install this module.
+.Sp
+If you run this twice, you may end up with duplicate data
+in your database.
+.Sp
+If you are upgrading this module, check for upgrading instructions
+in case changes need to be made to your database.
+.IP "Edit your \fI/opt/rt4/etc/RT_SiteConfig.pm\fR" 4
+.IX Item "Edit your /opt/rt4/etc/RT_SiteConfig.pm"
+Add this line:
+.Sp
+.Vb 1
+\&    Plugin(\*(AqRT::Extension::SMSWebhook::Twilio\*(Aq);
+.Ve
+.IP "Clear your mason cache" 4
+.IX Item "Clear your mason cache"
+.Vb 1
+\&    rm \-rf /opt/rt4/var/mason_data/obj
+.Ve
+.IP "Restart your webserver" 4
+.IX Item "Restart your webserver"
+.SH "AUTHOR"
+.IX Header "AUTHOR"
+Best Practical Solutions, \s-1LLC\s0 <modules at bestpractical.com>
+.SH "BUGS"
+.IX Header "BUGS"
+.SH "LICENSE AND COPYRIGHT"
+.IX Header "LICENSE AND COPYRIGHT"
+This software is Copyright (c) 2022 by \s-1BPS\s0
+.PP
+This is free software, licensed under:
+.PP
+.Vb 1
+\&  The GNU General Public License, Version 2, June 1991
+.Ve
diff --git a/local/man/man3/RT::User_Local.3 b/local/man/man3/RT::User_Local.3
new file mode 100644
index 0000000000..5aec4d6ba9
--- /dev/null
+++ b/local/man/man3/RT::User_Local.3
@@ -0,0 +1,88 @@
+.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
+.\"
+.\" Standard preamble:
+.\" ========================================================================
+.de Sp \" Vertical space (when we can't use .PP)
+.if t .sp .5v
+.if n .sp
+..
+.de Vb \" Begin verbatim text
+.ft CW
+.nf
+.ne \\$1
+..
+.de Ve \" End verbatim text
+.ft R
+.fi
+..
+.\" Set up some character translations and predefined strings.  \*(-- will
+.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
+.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
+.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
+.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
+.\" nothing in troff, for use with C<>.
+.tr \(*W-
+.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
+.ie n \{\
+.    ds -- \(*W-
+.    ds PI pi
+.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
+.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
+.    ds L" ""
+.    ds R" ""
+.    ds C` ""
+.    ds C' ""
+'br\}
+.el\{\
+.    ds -- \|\(em\|
+.    ds PI \(*p
+.    ds L" ``
+.    ds R" ''
+.    ds C`
+.    ds C'
+'br\}
+.\"
+.\" Escape single quotes in literal strings from groff's Unicode transform.
+.ie \n(.g .ds Aq \(aq
+.el       .ds Aq '
+.\"
+.\" If the F register is >0, we'll generate index entries on stderr for
+.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
+.\" entries marked with X<> in POD.  Of course, you'll have to process the
+.\" output yourself in some meaningful fashion.
+.\"
+.\" Avoid warning from groff about undefined register 'F'.
+.de IX
+..
+.nr rF 0
+.if \n(.g .if rF .nr rF 1
+.if (\n(rF:(\n(.g==0)) \{\
+.    if \nF \{\
+.        de IX
+.        tm Index:\\$1\t\\n%\t"\\$2"
+..
+.        if !\nF==2 \{\
+.            nr % 0
+.            nr F 2
+.        \}
+.    \}
+.\}
+.rr rF
+.\" ========================================================================
+.\"
+.IX Title "RT::User_Local 3"
+.TH RT::User_Local 3 "2022-03-31" "perl v5.34.0" "User Contributed Perl Documentation"
+.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
+.\" way too many mistakes in technical documents.
+.if n .ad l
+.nh
+.SS "LoadOrCreateByPagerPhone \s-1NUMBER\s0"
+.IX Subsection "LoadOrCreateByPagerPhone NUMBER"
+Attempts to find a user who has the provided pager phone number. If that fails,
+creates an unprivileged user with the provided pager phone number and loads them.
+.PP
+Returns a tuple of the user's id and a status message.
+0 will be returned in place of the user's id in case of failure.
+.SS "LoadByPagerPhone"
+.IX Subsection "LoadByPagerPhone"
+Tries to load this user object from the database by the user's pager phone number.
diff --git a/local/plugins/RT-Extension-SMSWebhook-Twilio/html/SMSWebhook/Twilio.html b/local/plugins/RT-Extension-SMSWebhook-Twilio/html/SMSWebhook/Twilio.html
new file mode 100644
index 0000000000..6284cd082e
--- /dev/null
+++ b/local/plugins/RT-Extension-SMSWebhook-Twilio/html/SMSWebhook/Twilio.html
@@ -0,0 +1,109 @@
+<%init>
+use JSON;
+use Data::Dumper;
+use Digest::SHA qw(hmac_sha1_base64);
+
+RT->Logger->debug( 'twilio webhook got args: ' . Dumper( \%ARGS ) );
+
+my $from = $ARGS{From};
+my $to   = $ARGS{To};
+my $body = $ARGS{Body};
+my $sig  = RT::Interface::Web::RequestENV('HTTP_X_TWILIO_SIGNATURE');
+
+if ( !( $from && $to && $body && $sig ) ) {
+    RT->Logger->error('twilio webhook failed: missing args');
+    $m->abort(400);
+}
+
+# validate the signature
+# see: https://www.twilio.com/docs/usage/security#validating-requests
+my $config      = RT::Config->Get('SMSWebhookTwilio') // {};
+my $webhook_url = $config->{url};
+my $token       = $config->{token};
+
+if ( !( $webhook_url && $token ) ) {
+    RT->Logger->error('twilio webhook failed: missing config');
+    $m->abort(400);
+}
+
+for my $post_arg ( sort keys %ARGS ) {
+    $webhook_url .= $post_arg . $ARGS{$post_arg};
+}
+
+my $calc_sig = hmac_sha1_base64( $webhook_url, $token );
+
+# need to pad the digest: https://metacpan.org/pod/Digest::SHA#PADDING-OF-BASE64-DIGESTS
+while ( length($calc_sig) % 4 ) {
+    $calc_sig .= '=';
+}
+
+if ( $sig ne $calc_sig ) {
+    RT->Logger->error(
+        'twilio webhook failed: cannot validate twilio signature');
+    $m->abort(400);
+}
+
+RT->Logger->debug(
+    "twilio webhook got data:\n\nfrom:\t$from\nto:\t$to\nbody:\t$body\nsig:\t$sig\ncalc:\t$calc_sig\n\n\n"
+);
+
+my $user_obj = $session{CurrentUser};
+unless ($user_obj) {
+    RT->Logger->error('twilio webhook failed: no current user');
+    $m->abort(401);
+}
+
+my $User = RT::User->new($user_obj);
+my ( $id, $msg ) = $User->LoadOrCreateByPagerPhone($from);
+unless ($id) {
+    RT->Logger->error(
+        "twilio webhook failed: could not load or create user - $msg");
+    $m->abort(400);
+}
+
+my $current_user = RT::CurrentUser->new($id);
+RT->Logger->debug( 'twilio webhook found user: ' . $current_user->Name );
+
+# find all active tickets for the user sending the sms
+my $tickets = RT::Tickets->new($current_user);
+$tickets->FromSQL( "Watcher.id = " . $id . " AND Status = '__Active__'" );
+RT->Logger->debug(
+    'twilio webhook # of active tickets for user: ' . $tickets->Count );
+
+if ( $tickets->Count == 1 ) {
+
+    # only one active ticket so add a comment to it
+    my $ticket = $tickets->First;
+    my ( $ret, $msg )
+        = $ticket->Comment( Content => "To: $to\nFrom: $from\n\n$body" );
+    unless ($ret) {
+        RT->Logger->error("twilio webhook could not add comment: $msg");
+    }
+} else {
+
+    # either zero or more than one active tickets
+    # don't know which one the text relates to so create a new ticket
+    my $mime = HTML::Mason::Commands::MakeMIMEEntity(
+        Body => "To: $to\nFrom: $from\n\n$body",
+        Type => 'text/plain',
+    );
+    my $Ticket = RT::Ticket->new($current_user);
+    my ( $id, $Trans, $ErrMsg ) = $Ticket->Create(
+        Requestor => $user->Name,
+        Type      => 'ticket',
+        Queue     => $config->{queue} // 'General',
+        Subject   => "SMS Message from " . $user->RealName,
+        MIMEObj   => $mime,
+    );
+
+    if ($id) {
+        RT::Logger->debug("twilio webhook created new ticket: $id");
+    } else {
+        RT::Logger->error(
+            "twilio webhook failed to create new ticket: $ErrMsg");
+    }
+}
+
+</%init>
+<Response></Response>
+% $m->abort;
diff --git a/local/plugins/RT-Extension-SMSWebhook-Twilio/lib/RT/Extension/SMSWebhook/Twilio.pm b/local/plugins/RT-Extension-SMSWebhook-Twilio/lib/RT/Extension/SMSWebhook/Twilio.pm
new file mode 100644
index 0000000000..2d82704718
--- /dev/null
+++ b/local/plugins/RT-Extension-SMSWebhook-Twilio/lib/RT/Extension/SMSWebhook/Twilio.pm
@@ -0,0 +1,85 @@
+use strict;
+use warnings;
+package RT::Extension::SMSWebhook::Twilio;
+
+our $VERSION = '0.01';
+
+=head1 NAME
+
+RT-Extension-SMSWebhook-Twilio - [One line description of module's purpose here]
+
+=head1 DESCRIPTION
+
+[Why would someone install this extension? What does it do? What problem
+does it solve?]
+
+=head1 RT VERSION
+
+Works with RT [What versions of RT is this known to work with?]
+
+[Make sure to use requires_rt and rt_too_new in Makefile.PL]
+
+=head1 INSTALLATION
+
+=over
+
+=item C<perl Makefile.PL>
+
+=item C<make>
+
+=item C<make install>
+
+May need root permissions
+
+=item C<make initdb>
+
+Only run this the first time you install this module.
+
+If you run this twice, you may end up with duplicate data
+in your database.
+
+If you are upgrading this module, check for upgrading instructions
+in case changes need to be made to your database.
+
+=item Edit your F</opt/rt4/etc/RT_SiteConfig.pm>
+
+Add this line:
+
+    Plugin('RT::Extension::SMSWebhook::Twilio');
+
+=item Clear your mason cache
+
+    rm -rf /opt/rt4/var/mason_data/obj
+
+=item Restart your webserver
+
+=back
+
+=head1 AUTHOR
+
+Best Practical Solutions, LLC E<lt>modules at bestpractical.comE<gt>
+
+=head1 BUGS
+
+=for html <p>All bugs should be reported via email to <a
+href="mailto:bug-RT-Extension-SMSWebhook-Twilio at rt.cpan.org">bug-RT-Extension-SMSWebhook-Twilio at rt.cpan.org</a>
+or via the web at <a
+href="http://rt.cpan.org/Public/Dist/Display.html?Name=RT-Extension-SMSWebhook-Twilio">rt.cpan.org</a>.</p>
+
+=for text
+    All bugs should be reported via email to
+        bug-RT-Extension-SMSWebhook-Twilio at rt.cpan.org
+    or via the web at
+        http://rt.cpan.org/Public/Dist/Display.html?Name=RT-Extension-SMSWebhook-Twilio
+
+=head1 LICENSE AND COPYRIGHT
+
+This software is Copyright (c) 2022 by BPS
+
+This is free software, licensed under:
+
+  The GNU General Public License, Version 2, June 1991
+
+=cut
+
+1;
diff --git a/local/plugins/RT-Extension-SMSWebhook-Twilio/lib/RT/User_Local.pm b/local/plugins/RT-Extension-SMSWebhook-Twilio/lib/RT/User_Local.pm
new file mode 100644
index 0000000000..d4468d5b09
--- /dev/null
+++ b/local/plugins/RT-Extension-SMSWebhook-Twilio/lib/RT/User_Local.pm
@@ -0,0 +1,83 @@
+use strict;
+use warnings;
+
+package RT::User;
+
+=head2 LoadOrCreateByPagerPhone NUMBER
+
+Attempts to find a user who has the provided pager phone number. If that fails,
+creates an unprivileged user with the provided pager phone number and loads them.
+
+Returns a tuple of the user's id and a status message.
+0 will be returned in place of the user's id in case of failure.
+
+=cut
+
+sub LoadOrCreateByPagerPhone {
+    my $self  = shift;
+    my $pager = shift;
+
+    # find the user with the phone number sending the sms
+    my $users
+        = RT::Users->new( $HTML::Mason::Commands::session{CurrentUser} );
+    $users->Limit(
+        FIELD    => 'PagerPhone',
+        VALUE    => $pager,
+        OPERATOR => '=',
+    );
+    if ( $users->Count > 0 ) {
+
+       # XXX - should we check if there is more than one user with same pager?
+        $self->Load( $users->First->Id );
+    }
+
+    return wantarray ? ( $self->Id, $self->loc("User loaded") ) : $self->Id
+        if $self->Id;
+
+    my ( $val, $message ) = $self->Create(
+        Name       => "SMS-$pager",
+        PagerPhone => $pager,
+        Privileged => 0,
+        Comments   => 'Autocreated when creating ticket from SMS',
+    );
+    return wantarray ? ( $self->Id, $self->loc("User loaded") ) : $self->Id
+        if $self->Id;
+
+    # Deal with the race condition of two account creations at once
+    $self->LoadByPagerPhone($pager);
+    unless ( $self->Id ) {
+        sleep 5;
+        $self->LoadByPagerPhone($pager);
+    }
+
+    if ( $self->Id ) {
+        $RT::Logger->error(
+            "Recovered from creation failure due to race condition");
+        return
+            wantarray ? ( $self->Id, $self->loc("User loaded") ) : $self->Id;
+    } else {
+        $RT::Logger->crit("Failed to create user SMS-$pager: $message");
+        return wantarray ? ( 0, $message ) : 0 unless $self->id;
+    }
+}
+
+=head2 LoadByPagerPhone
+
+Tries to load this user object from the database by the user's pager phone number.
+
+=cut
+
+sub LoadByPagerPhone {
+    my $self  = shift;
+    my $pager = shift;
+
+    # Never load an empty pager.
+    unless ($pager) {
+        return (undef);
+    }
+
+    #$RT::Logger->debug("Trying to load a pager phone: $pager");
+    return $self->LoadByCol( "PagerPhone", $pager );
+}
+
+1;
diff --git a/local/plugins/RT-Extension-SMSWebhook-Twilio/lib/perllocal.pod b/local/plugins/RT-Extension-SMSWebhook-Twilio/lib/perllocal.pod
new file mode 100644
index 0000000000..72c1b8f02f
--- /dev/null
+++ b/local/plugins/RT-Extension-SMSWebhook-Twilio/lib/perllocal.pod
@@ -0,0 +1,22 @@
+=head2 Thu Mar 31 16:24:41 2022: C<Module> L<RT::Extension::SMSWebhook::Twilio|RT::Extension::SMSWebhook::Twilio>
+
+=over 4
+
+=item *
+
+C<installed into: /home/brad/BPS/work/rt/local/plugins/RT-Extension-SMSWebhook-Twilio/lib>
+
+=item *
+
+C<LINKTYPE: dynamic>
+
+=item *
+
+C<VERSION: 0.01>
+
+=item *
+
+C<EXE_FILES: >
+
+=back
+
diff --git a/sbin/rt-clean-attributes b/sbin/rt-clean-attributes
new file mode 100755
index 0000000000..60a030365c
--- /dev/null
+++ b/sbin/rt-clean-attributes
@@ -0,0 +1,150 @@
+#!/home/brad/perl5/perlbrew/perls/perl-5.34.0/bin/perl
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2023 Best Practical Solutions, LLC
+#                                          <sales at bestpractical.com>
+#
+# (Except where explicitly superseded by other copyright notices)
+#
+#
+# LICENSE:
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+#
+#
+# CONTRIBUTION SUBMISSION POLICY:
+#
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+#
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+#
+# END BPS TAGGED BLOCK }}}
+use strict;
+use warnings;
+
+# fix lib paths, some may be relative
+BEGIN { # BEGIN RT CMD BOILERPLATE
+    require File::Spec;
+    require Cwd;
+    my @libs = ("./lib", "./local/lib");
+    my $bin_path;
+
+    for my $lib (@libs) {
+        unless ( File::Spec->file_name_is_absolute($lib) ) {
+            $bin_path ||= ( File::Spec->splitpath(Cwd::abs_path(__FILE__)) )[1];
+            $lib = File::Spec->catfile( $bin_path, File::Spec->updir, $lib );
+        }
+        unshift @INC, $lib;
+    }
+
+}
+
+use RT::Interface::CLI qw(Init);
+my %opt;
+Init(\%opt, 'older=s', 'verbose');
+
+$opt{'older'} ||= '1M';
+unless ( $opt{'older'} =~ /^\s*([0-9]+)\s*(H|D|M|Y)?$/i ) {
+    print STDERR "Incorrect format used for the 'older' argument\n";
+    exit(1);
+}
+my ( $num, $unit ) = ( $1, uc( $2 || 'D' ) );
+my %factor = ( H => 60 * 60 );
+$factor{'D'}  = $factor{'H'} * 24;
+$factor{'M'}  = $factor{'D'} * 31;
+$factor{'Y'}  = $factor{'D'} * 365;
+$opt{'older'} = $num * $factor{$unit};
+
+if ( $opt{'older'} < 7*3600*24 ) {
+    print STDERR "The 'older' argument should be greater than 7 days to avoid removing deferred email before it is sent\n";
+    exit(1);
+}
+
+if ( $opt{'verbose'} ) {
+    print "Running...\n";
+}
+
+require POSIX;
+my $date = POSIX::strftime("%Y-%m-%d %H:%M", gmtime( time - $opt{'older'} ) );
+
+my $dbh = RT->DatabaseHandle->dbh;
+my $sth = $dbh->prepare("DELETE FROM Attributes WHERE Name='DeferredRecipients' AND Created < ?");
+die "Couldn't prepare query: ". $dbh->errstr unless $sth;
+my $rows = $sth->execute( $date );
+die "Couldn't execute query: ". $dbh->errstr unless defined $rows;
+
+RT->Logger->info("Successfully deleted $rows DeferredRecipients attributes") if $rows > 0;
+
+if ( $opt{'verbose'} ) {
+    if ( $rows > 0 ) {
+        print "Successfully deleted $rows DeferredRecipients attributes";
+    }
+    else {
+        print "No rows to delete\n";
+    }
+}
+
+__END__
+
+=head1 NAME
+
+rt-clean-attributes - clean obsolete RT attributes
+
+=head1 SYNOPSIS
+
+     rt-clean-attributes
+     rt-clean-attributes --older 1M
+
+=head1 DESCRIPTION
+
+This script deletes obsolete C<DeferredRecipients> attributes.
+
+C<DeferredRecipients> attributes are used by L<rt-email-digest> to store
+email to be sent at a later time, either daily or weekly. Since
+L<rt-email-digest> processes transactions created at most one week in
+the past, it's safe to delete C<DeferredRecipients> attributes older than
+one week since they will never be accessed.
+
+=head1 OPTIONS
+
+=over 4
+
+=item C<--older>
+
+Date interval in the C<< <NUM>[<unit>] >> format. Default unit is D(ays),
+H(our), M(onth) and Y(ear) are also supported.
+
+=item C<--verbose>
+
+Show additional output on the command line when running.
+
+=back
+
+=cut
diff --git a/sbin/rt-email-expiring-auth-tokens.in b/sbin/rt-email-expiring-auth-tokens.in
index 326eefedc1..0d042b85e1 100644
--- a/sbin/rt-email-expiring-auth-tokens.in
+++ b/sbin/rt-email-expiring-auth-tokens.in
@@ -123,13 +123,7 @@ $authTokens->Limit(
 $authTokens->Limit(
     FIELD           => 'Expires',
     VALUE           => 'NULL',
-    OPERATOR        => '!=',
-    ENTRYAGGREGATOR => 'AND',
-);
-$authTokens->Limit(
-    FIELD           => 'Expires',
-    VALUE           => '',
-    OPERATOR        => '!=',
+    OPERATOR        => 'IS NOT',
     ENTRYAGGREGATOR => 'AND',
 );
 

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

Summary of changes:
 .../auto/RT/Extension/SMSWebhook/Twilio/.packlist  |   4 +
 local/man/man3/RT::Extension::SMSWebhook::Twilio.3 | 141 +++++++++++++++++++++
 local/man/man3/RT::User_Local.3                    |  88 +++++++++++++
 .../html/SMSWebhook/Twilio.html                    | 109 ++++++++++++++++
 .../lib/RT/Extension/SMSWebhook/Twilio.pm          |  85 +++++++++++++
 .../lib/RT/User_Local.pm                           |  83 ++++++++++++
 .../lib/perllocal.pod                              |  22 ++++
 ...{rt-clean-attributes.in => rt-clean-attributes} |   4 +-
 sbin/rt-email-expiring-auth-tokens.in              |   8 +-
 9 files changed, 535 insertions(+), 9 deletions(-)
 create mode 100644 local/man/auto/RT/Extension/SMSWebhook/Twilio/.packlist
 create mode 100644 local/man/man3/RT::Extension::SMSWebhook::Twilio.3
 create mode 100644 local/man/man3/RT::User_Local.3
 create mode 100644 local/plugins/RT-Extension-SMSWebhook-Twilio/html/SMSWebhook/Twilio.html
 create mode 100644 local/plugins/RT-Extension-SMSWebhook-Twilio/lib/RT/Extension/SMSWebhook/Twilio.pm
 create mode 100644 local/plugins/RT-Extension-SMSWebhook-Twilio/lib/RT/User_Local.pm
 create mode 100644 local/plugins/RT-Extension-SMSWebhook-Twilio/lib/perllocal.pod
 copy sbin/{rt-clean-attributes.in => rt-clean-attributes} (97%)
 mode change 100644 => 100755


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list