[Rt-commit] rt branch, 5.0-trunk, updated. rt-5.0.0-107-g0ac3ad1f63
? sunnavy
sunnavy at bestpractical.com
Tue Nov 10 08:47:22 EST 2020
The branch, 5.0-trunk has been updated
via 0ac3ad1f634bbcfb6524f5b3fae1ace563617e11 (commit)
via ba31c6fc303e72f0f0e212fb0559adc677627b00 (commit)
via 550768088d5cd6dcbb46f1c7ac92578881e67743 (commit)
from 0ce9a9b130340977b9eb2d5970e95c1b36ccadce (commit)
Summary of changes:
lib/RT/Ticket.pm | 54 ++++++++++++++++++++++++++++++++++++++++++++++-------
t/ticket/priority.t | 12 +++++++++++-
2 files changed, 58 insertions(+), 8 deletions(-)
- Log -----------------------------------------------------------------
commit ba31c6fc303e72f0f0e212fb0559adc677627b00
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Mon Nov 9 14:52:18 2020 -0500
Accept string priority values in SetPriority
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 287177adbe..8adff7fd8b 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -3398,13 +3398,29 @@ Returns the current value of Priority.
=head2 SetPriority VALUE
-Set Priority to VALUE.
+Set Priority to VALUE. Accepts numeric and string values for priority.
Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
(In the database, Priority will be stored as a int(11).)
=cut
+sub SetPriority {
+ my $self = shift;
+ my $priority = shift;
+ my $number;
+
+ if ( $priority =~ /^\d+$/ ) {
+ # Already a digit
+ $number = $priority;
+ }
+ else {
+ # Try to load a digit from the string
+ $number = $self->_PriorityAsNumber($priority);
+ }
+
+ return $self->_Set( Field => 'Priority', Value => $number || 0 );
+}
=head2 TimeEstimated
@@ -3771,6 +3787,20 @@ sub _PriorityAsString {
return "unknown";
}
+sub _PriorityAsNumber {
+ my $self = shift;
+ my $priority = shift;
+ my $queue_name = shift || $self->QueueObj->__Value('Name'); # Skip ACL check
+
+ return undef unless defined $priority && length $priority && RT->Config->Get('EnablePriorityAsString');
+
+ my $map_ref = $self->GetPriorityAsStringMapping($queue_name);
+ return undef unless $map_ref;
+
+ return $map_ref->{$priority} if exists $map_ref->{$priority};
+ return undef;
+}
+
sub GetPriorityAsStringMapping {
my $self = shift;
my $queue_name = shift || $self->QueueObj->__Value('Name'); # Skip ACL check
diff --git a/t/ticket/priority.t b/t/ticket/priority.t
index ee76e46cb9..6a40a5b7cb 100644
--- a/t/ticket/priority.t
+++ b/t/ticket/priority.t
@@ -50,6 +50,16 @@ my ( $ret, $msg ) = $ticket->SetPriority(50);
ok( $ret, "Priority is updated" );
is( $msg, "Priority changed from 'VeryLow' to 'Medium'", 'Priority updated message' );
+( $ret, $msg ) = $ticket->SetPriority('Low');
+ok( $ret, "Priority is updated" );
+is( $msg, "Priority changed from 'Medium' to 'Low'", 'Priority updated message' );
+is( $ticket->Priority, 20, 'Priority is 20');
+
+( $ret, $msg ) = $ticket->SetPriority('Medium');
+ok( $ret, "Priority is updated" );
+is( $msg, "Priority changed from 'Low' to 'Medium'", 'Priority updated message' );
+is( $ticket->Priority, 50, 'Priority is 50');
+
( $ret, $msg ) = $ticket->SetFinalPriority(100);
ok( $ret, "FinalPriority is updated" );
is( $msg, "FinalPriority changed from 'VeryLow' to 'High'", 'FinalPriority updated message' );
@@ -97,7 +107,7 @@ while ( my $ticket = $tickets->Next ) {
my $txns = RT::Transactions->new( RT->SystemUser );
$txns->FromSQL("TicketQueue = 'General' AND TicketPriority = 'Medium' AND Field = 'Priority'");
-is( $txns->Count, 1, 'Found 1 txn' );
+is( $txns->Count, 3, 'Found 3 txn' );
my $txn = $txns->First;
is( $txn->OldValue, 0, 'OldValue is correct' );
is( $txn->NewValue, 50, 'NewValue is correct' );
commit 0ac3ad1f634bbcfb6524f5b3fae1ace563617e11
Merge: 0ce9a9b130 ba31c6fc30
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Nov 10 21:24:21 2020 +0800
Merge branch '5.0/set-priority-as-string' into 5.0-trunk
-----------------------------------------------------------------------
More information about the rt-commit
mailing list