[Rt-commit] rt branch 5.0/default-priority-value created. rt-5.0.2-57-ge59d9a37ce

BPS Git Server git at git.bestpractical.com
Thu Dec 23 20:20:04 UTC 2021


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/default-priority-value has been created
        at  e59d9a37ce245e23f0702750210c392dc2ce055d (commit)

- Log -----------------------------------------------------------------
commit e59d9a37ce245e23f0702750210c392dc2ce055d
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Dec 24 03:17:43 2021 +0800

    Add tests for %PriorityAsString that does not have "0" mapped

diff --git a/t/web/priority.t b/t/web/priority.t
index f0e744eba6..2eee6ffbc3 100644
--- a/t/web/priority.t
+++ b/t/web/priority.t
@@ -192,4 +192,57 @@ $m->submit_form_ok( { fields => { TicketPriorityOp => '=', ValueOfTicketPriority
 $m->title_is('Found 4 transactions');
 $m->text_contains('Test PriorityAsString');
 
+diag "Set PriorityAsString without 0";
+
+$m->goto_ticket( RT::Test->last_ticket->id );
+$m->follow_link_ok( { text => 'Basics' } );
+$m->form_name('TicketModify');
+$m->submit_form_ok( { fields => { Priority => 0 } }, 'Update Priority' );
+$m->text_contains( qq{Priority changed from 'High' to 'VeryLow'}, 'Priority is updated' );
+
+sleep 1;
+
+( $ret, $msg ) = $config->SetContent( { General => { Low => 5, Medium => 50, High => 100 } }, );
+ok( $ret, 'Updated config' );
+
+$m->reload;
+$form = $m->form_name('TicketModify');
+for my $field (qw/Priority FinalPriority/) {
+    my $priority_input = $form->find_input($field);
+    is( $priority_input->type, 'option', "$field input is a select" );
+    if ( $field eq 'Priority' ) {
+        is_deeply( [ $priority_input->possible_values ], [ 0, 5, 50, 100 ], "$field options" );
+        is( $form->value($field), 0, "$field default value" );
+    }
+    else {
+        is_deeply( [ $priority_input->possible_values ], [ 5, 50, 100 ], "$field options" );
+        is( $form->value($field), 100, "$field default value" );
+    }
+}
+
+$m->goto_create_ticket( $queue->Id );
+$form = $m->form_name('TicketCreate');
+is( $form->value('InitialPriority'), 50,  'InitialPriority default value on page' );
+is( $form->value('FinalPriority'),   100, 'FinalPriority default value on page' );
+
+ok( $queue->SetDefaultValue( Name => 'InitialPriority', Value => undef ) );
+ok( $queue->SetDefaultValue( Name => 'FinalPriority',   Value => undef ) );
+
+is( $queue->DefaultValue('InitialPriority'), 5, 'InitialPriority default value inferred by config' );
+is( $queue->DefaultValue('FinalPriority'),   5, 'FinalPriority default value inferred by config' );
+
+$m->goto_create_ticket( $queue->Id );
+$form = $m->form_name('TicketCreate');
+is( $form->value('InitialPriority'), 5, 'InitialPriority default value on page' );
+is( $form->value('FinalPriority'),   5, 'FinalPriority default value on page' );
+
+my $ticket = RT::Test->create_ticket(
+    Subject => 'Test default priority',
+    Queue   => 'General',
+);
+
+for my $field (qw/InitialPriority Priority FinalPriority/) {
+    is( $ticket->$field, 5, "$field is set correctly" );
+}
+
 done_testing;

commit 71742a9351ef2657def942d0ca1f9e6447e1a4ff
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Dec 24 01:59:14 2021 +0800

    Add "unknown" default priority option to priority select list
    
    This could happen when ticket's priority is not valid any more(either
    because it's an old ticket or %PriorityAsString got updated, especialy
    if priority "0" is not mapped), in which case "unknown" would be shown.
    Previously "unknown" was never an option of the priority select list,
    which brought in 2 issues:
    
    * Unexpected updates
    
    On ticket basics page, if you want to update status only and not touch
    priority, there was actually no way to do it.
    
    * Set default priority value in inline edit
    
    Inline edit submits form on input changes. Assuming "Low" is the default
    value(it was selected by default), you would need to change it to some
    other values(e.g. "Medium") and then change it back to "Low" to set
    priority from "unknown" to "Low".

diff --git a/share/html/Elements/SelectPriorityAsString b/share/html/Elements/SelectPriorityAsString
index b2e24b2b15..b077b5a92a 100644
--- a/share/html/Elements/SelectPriorityAsString
+++ b/share/html/Elements/SelectPriorityAsString
@@ -83,4 +83,13 @@ if ( defined $Default && length $Default && $QueueObj ) {
 
 my %config = RT->Config->Get('PriorityAsString');
 my $group_by_name = keys %Options > 1;
+
+if ( $QueueObj ) {
+    # Make sure we show default value if that's not in the list.
+    # This is for the unusual "unknown" value
+    my $list = $Options{ ( keys %Options )[0] };
+    if ( not grep { $_->{Label} eq $default_label } @$list ) {
+        unshift @$list, { Label => loc( "[_1] (Unchanged)", $default_label ), Value => $Default };
+    }
+}
 </%INIT>

commit 227f7a58f6fc729220b7d1f19ac9659ddbef9b25
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Dec 23 23:59:06 2021 +0800

    Update tests for the default priority change when PriorityAsString is enabled
    
    The behavior change is in cdf5c489d0.

diff --git a/t/web/priority.t b/t/web/priority.t
index 717aa92734..f0e744eba6 100644
--- a/t/web/priority.t
+++ b/t/web/priority.t
@@ -16,8 +16,8 @@ my $form = $m->form_name('TicketCreate');
 for my $field (qw/InitialPriority FinalPriority/) {
     my $priority_input = $form->find_input($field);
     is( $priority_input->type, 'option', "$field input is a select" );
-    is_deeply( [ $priority_input->possible_values ], [ '', 0, 50, 100 ], "$field options" );
-    is( $form->value($field), '', "$field default value" );
+    is_deeply( [ $priority_input->possible_values ], [ 0, 50, 100 ], "$field options" );
+    is( $form->value($field), 0, "$field default value" );
 }
 
 $m->submit_form_ok( { fields => { Subject => 'Test PriorityAsString', InitialPriority => 50 }, button => 'SubmitTicket' }, 'Create ticket' );
@@ -75,8 +75,8 @@ $form = $m->form_name('TicketCreate');
 for my $field (qw/InitialPriority FinalPriority/) {
     my $priority_input = $form->find_input($field);
     is( $priority_input->type, 'option', "$field input is a select" );
-    is_deeply( [ $priority_input->possible_values ], [ '', 0, 20, 50, 100, 200 ], "$field options" );
-    is( $form->value($field), '', "$field default value" );
+    is_deeply( [ $priority_input->possible_values ], [ 0, 20, 50, 100, 200 ], "$field options" );
+    is( $form->value($field), 0, "$field default value" );
 }
 
 diag "Disable PriorityAsString for General";
@@ -111,8 +111,8 @@ $form = $m->form_name('TicketCreate');
 for my $field (qw/InitialPriority FinalPriority/) {
     my $priority_input = $form->find_input($field);
     is( $priority_input->type, 'option', "$field input is a select" );
-    is_deeply( [ $priority_input->possible_values ], [ '', 50, 0, 20, 100, 200 ], "$field options" );
-    is( $form->value($field), '', "$field default value" );
+    is_deeply( [ $priority_input->possible_values ], [ 50, 0, 20, 100, 200 ], "$field options" );
+    is( $form->value($field), 50, "$field default value" );
 }
 
 diag "Queue default values";
@@ -122,7 +122,7 @@ $form = $m->form_name('ModifyDefaultValues');
 for my $field (qw/InitialPriority FinalPriority/) {
     my $priority_input = $form->find_input($field);
     is( $priority_input->type, 'option', 'Priority input is a select' );
-    is_deeply( [ $priority_input->possible_values ], [ '', 50, 0, 20, 100, 200 ], 'Priority options' );
+    is_deeply( [ $priority_input->possible_values ], [ 50, 0, 20, 100, 200 ], 'Priority options' );
 }
 $m->submit_form_ok( { fields => { InitialPriority => 50, FinalPriority => 100 }, button => 'Update' },
     'Update default values' );

commit cdf5c489d03e47d616a4c6d1d856ba5454cbb3b7
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Dec 23 23:21:44 2021 +0800

    Fall back priority to the first value in %PriorityAsStringMapping config
    
    Previously it was 0(unless queue level default value is set), even if
    %PriorityAsStringMapping doesn't have a mapping for that, in which case
    the priority will be shown as "unknown", an unusual value. Using the
    first priority value defined in %PriorityAsStringMapping config makes
    more sense.

diff --git a/lib/RT/Queue.pm b/lib/RT/Queue.pm
index 91541c4298..e0f2c019b0 100644
--- a/lib/RT/Queue.pm
+++ b/lib/RT/Queue.pm
@@ -1175,8 +1175,32 @@ sub DefaultValue {
     my $self = shift;
     my $field = shift;
     my $attr = $self->FirstAttribute('DefaultValues');
-    return undef unless $attr && $attr->Content;
-    return $attr->Content->{$field};
+
+    my $fallback;
+    if ( $field =~ /Priority/
+        && RT->Config->Get('EnablePriorityAsString') )
+    {
+        my %config = RT->Config->Get('PriorityAsString');
+        my $queue_name = $self->__Value('Name');
+        if ( my $value = exists $config{$queue_name} ? $config{$queue_name} : $config{Default} ) {
+
+            # For ordered list(array), use the first entry. For unordered list(hash), use the lowest value.
+            # This is also consistent with the priority order on web pages
+            if ( ref $value eq 'ARRAY' ) {
+                $fallback = $value->[1];
+            }
+            elsif ( ref $value eq 'HASH' ) {
+                $fallback = ( sort { $a <=> $b } values %$value )[0];
+            }
+            else {
+                RT->Logger->warning("Invalid PriorityAsString value: $value");
+            }
+        }
+    }
+
+    return $fallback unless $attr && $attr->Content;
+    my $value = $attr->Content->{$field};
+    return $value // $fallback;
 }
 
 sub SetDefaultValue {

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list