[Rt-commit] rt branch, 5.0/on-email-add-time-worked, created. rt-5.0.0-2-gf444123c5e
Craig Kaiser
craig at bestpractical.com
Wed Feb 3 08:13:25 EST 2021
The branch, 5.0/on-email-add-time-worked has been created
at f444123c5e8112ff8f6a3b70cd91562bc686bceb (commit)
- Log -----------------------------------------------------------------
commit 5ac68f31588e29b9f2d61c428932cfd57ea3c2fa
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 1949560948..6622186af2 100644
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -249,6 +249,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',
+ },
);
commit f444123c5e8112ff8f6a3b70cd91562bc686bceb
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 6622186af2..017b263cfe 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..4951294daa
--- /dev/null
+++ b/lib/RT/Action/SetTimeWorked.pm
@@ -0,0 +1,116 @@
+# 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;
+
+ # If we are batch stage we will check to see if any time worked values have already been set
+ if ( $self->ScripObj->Stage( TicketObj => $self->TicketObj ) eq 'TransactionBatch' ) {
+ foreach my $transaction ( @{$self->TicketObj->TransactionBatch} ) {
+ next unless $self->TransactionObj->TimeTaken;
+ return;
+ }
+ }
+ # Skip this action if TimeTaken is being updated
+ return if $self->TransactionObj->TimeTaken;
+
+ 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;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list