[Rt-commit] rt branch, 5.0/set-priority-as-string, created. rt-5.0.0-106-gc502cc5bf2
Jim Brandt
jbrandt at bestpractical.com
Mon Nov 9 15:02:25 EST 2020
The branch, 5.0/set-priority-as-string has been created
at c502cc5bf2e26120f78c5efe1e9ca7412b0e794c (commit)
- Log -----------------------------------------------------------------
commit 550768088d5cd6dcbb46f1c7ac92578881e67743
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Mon Nov 9 14:26:25 2020 -0500
Extract PriorityAsString config mapping in a method
This makes it easier to reuse in other code that might
want just the PriorityAsString mapping for a given
queue.
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 7ef41e494d..287177adbe 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -3760,6 +3760,21 @@ sub _PriorityAsString {
return undef unless defined $priority && length $priority && RT->Config->Get('EnablePriorityAsString');
+ my $map_ref = $self->GetPriorityAsStringMapping($queue_name);
+ return undef unless $map_ref;
+
+ # Count from high down to low until we find one that our number is
+ # greater than or equal to.
+ foreach my $label ( sort { $map_ref->{$b} <=> $map_ref->{$a} } keys %$map_ref ) {
+ return $label if $priority >= $map_ref->{$label};
+ }
+ return "unknown";
+}
+
+sub GetPriorityAsStringMapping {
+ my $self = shift;
+ my $queue_name = shift || $self->QueueObj->__Value('Name'); # Skip ACL check
+
my %config = RT->Config->Get('PriorityAsString');
my $value = ( exists $config{$queue_name} ? $config{$queue_name} : $config{Default} ) or return undef;
my %map;
@@ -3773,12 +3788,7 @@ sub _PriorityAsString {
RT->Logger->warning("Invalid PriorityAsString value: $value");
}
- # Count from high down to low until we find one that our number is
- # greater than or equal to.
- foreach my $label ( sort { $map{$b} <=> $map{$a} } keys %map ) {
- return $label if $priority >= $map{$label};
- }
- return "unknown";
+ return \%map;
}
RT::Base->_ImportOverlays();
commit c502cc5bf2e26120f78c5efe1e9ca7412b0e794c
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..0070dee7b3 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 );
+}
=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' );
-----------------------------------------------------------------------
More information about the rt-commit
mailing list