[Rt-commit] rt branch, 5.0/on-email-add-time-worked, created. rt-5.0.0-2-gc802a814ff

Craig Kaiser craig at bestpractical.com
Tue Feb 2 09:54:26 EST 2021


The branch, 5.0/on-email-add-time-worked has been created
        at  c802a814fff360dec561e4145871c5686505ab5d (commit)

- Log -----------------------------------------------------------------
commit cb8438a33541ab62926cb407a158caf7af6d9e93
Author: craig kaiser <craig at bestpractical.com>
Date:   Tue Feb 2 09:26:54 2021 -0500

    Add RT::Action::SetTimeWorked action and initialdata action

diff --git a/etc/initialdata b/etc/initialdata
index 1949560948..9772490b33 100644
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -125,6 +125,12 @@
        Description => 'Set the due date according to an agreement' , # loc
        ExecModule  => 'SLA_SetDue',
     },
+    {
+      Name        => 'Add 15 Minutes To Time Worked',              # loc
+      Description => 'Add 15 Minutes To Ticket Time Worked Value', # loc
+      ExecModule  => 'SetTimeWorked',
+      Argument    => '15'
+    },
 );
 
 @ScripConditions = (
diff --git a/lib/RT/Action/SetTimeWorked.pm b/lib/RT/Action/SetTimeWorked.pm
new file mode 100644
index 0000000000..bde69bc6a7
--- /dev/null
+++ b/lib/RT/Action/SetTimeWorked.pm
@@ -0,0 +1,105 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2020 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 }}}
+
+package RT::Action::SetTimeWorked;
+
+use strict;
+use warnings;
+use base qw(RT::Action);
+
+use Scalar::Util qw(looks_like_number);
+
+=head1 DESCRIPTION
+
+Provide a time argument in minutes for how much time to add to
+the current tickets time worked value. This action will only
+run when Privileged users comment or reply.
+
+=cut
+
+sub Prepare {
+    my $self = shift;
+
+    # Only set time worked for privileged users
+    return 0 unless $self->TransactionObj->CreatorObj->Privileged;
+    return 1;
+}
+
+sub Commit {
+    my $self = shift;
+    my $time = $self->Argument;
+    unless ( $time ) {
+        RT::Logger->error( "Time argument required for RT::Action::SetTimeWorked, none was provided" );
+        return;
+    }
+    unless ( looks_like_number( $time ) ) {
+        RT::Logger->error( "Time argument for RT::Action::SetTimeWorked must be a number: $time is invalid" );
+        return;
+    }
+
+    my $timeWorked = $self->TicketObj->TimeWorked || 0;
+
+    # Add 15 minutes to time worked
+    my $newValue = $timeWorked + $time;
+
+    # Load a ticket in the context of the user sending the message
+    my $ticketObj = RT::Ticket->new( $self->TransactionObj->CreatorObj );
+    my ($ret, $msg) = $ticketObj->Load( $self->TicketObj->Id );
+    unless ( $ret ) {
+        RT::Logger->error( "Could not load ticket #".$self->TicketObj->Id." in user context: $msg" );
+        return;
+    }
+
+    ($ret, $msg) = $ticketObj->SetTimeWorked( $newValue );
+    RT::Logger->error ( "Could not update time worked: $msg" ) unless $ret;
+    return $ret;
+}
+
+RT::Base->_ImportOverlays();
+
+1;

commit c802a814fff360dec561e4145871c5686505ab5d
Author: craig kaiser <craig at bestpractical.com>
Date:   Tue Feb 2 09:27:16 2021 -0500

    Add default scrip condition 'On Comment Or Reply'

diff --git a/etc/initialdata b/etc/initialdata
index 9772490b33..017b263cfe 100644
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -255,6 +255,12 @@
        ApplicableTransTypes => 'Any',
        ExecModule           => 'TimeWorkedChange',
     },
+    {
+      Name                 => 'On Comment Or Reply',                                # loc
+      Description          => 'When a ticket is commented on or replied to',        # loc
+      ApplicableTransTypes => 'Comment,Correspond',
+      ExecModule           => 'AnyTransaction',
+    },
 
 );
 

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


More information about the rt-commit mailing list