[Rt-commit] rt branch, 4.6/priority-as-string, repushed

Michel Rodriguez michel at bestpractical.com
Fri Dec 20 13:47:22 EST 2019


The branch 4.6/priority-as-string was deleted and repushed:
       was c74f4d8e5d37c4c4c799d7123a37a3d722d5ee39
       now c15f80d23918ff1434bea4b166301f07ae27fa7a

1: fdf7660796 ! 1: 147508b3a2 Cores PriorityAsString
    @@ -2,20 +2,28 @@
     
         Cores PriorityAsString
         
    -    Adds final proposal for the feature:
    +    Add PriorityAsString to core.
         
    -       Set($EnablePriorityAsString, 1);
    +    Priority is kept as a number in the DB, but is displayed
    +    as a string, based on the mapping defined in the config.
    +    
    +    Everywhere a priority needs to be displayed or input, the
    +    Ticket object can return the string, based on the queue.
    +    
    +    Example configuration:
    +    
    +        Set($EnablePriorityAsString, 1);
         
             Set(%PriorityAsString,
    -          # default (for non specified queues)
    -          Default => { Low => 0, Medium => 50, High => 100 },
    -          # per queue priorities
    -          General    => { Low => 0, High => 1 },
    -          # drop-downs will display in order Low/High/Medium
    -          LHM        => [ Low => 0, High => 100, Medium => 50 ],
    -          # use numerical priorities
    -          NumQueue   => 0,
    -        );
    +        # default (for non specified queues)
    +        Default => { Low => 0, Medium => 50, High => 100 },
    +        # per queue priorities
    +        General    => { Low => 0, High => 1 },
    +        # drop-downs will display in order Low/High/Medium
    +        LHM        => [ Low => 0, High => 100, Medium => 50 ],
    +        # use numerical priorities
    +        NumQueue   => 0,
    +      );
     
     diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
     --- a/etc/RT_Config.pm.in
    @@ -37,10 +45,10 @@
     +
     +RT can assign a priority value to tickets. Priority is stored as an
     +integer in the database, but RT supports mapping strings to numerical
    -+values. 
    ++values.
     +
     +RT supports different priority string mappings for individual queues
    -+with C<%PriorityAsString>. 
    ++with C<%PriorityAsString>.
     +
     +For example, the default mapping is:
     +
    @@ -48,19 +56,19 @@
     +      Default => { Low => 0, Medium => 50, High => 100 },
     +    )
     +
    -+Use queue names as keys in this hash. 
    ++Use queue names as keys in this hash.
     +
     +Values in the hash define the mapping:
     +
     +=over 4
     +
    -+=item 
    ++=item
     +
     +C<0> sets the queue to use numerical priorities:
     +
     +    NumQueue => 0
     +
    -+=item 
    ++=item
     +
     +a hash C<< { string => numerical_value,... } >> maps each string to
     +the numerical value:
    @@ -74,7 +82,7 @@
     +order they were given in drop-down menus:
     +
     +      Ordered => [ Low => 0, High => 100, Medium => 50 ]
    -+    
    ++
     +In this case the drop-down menus used to choose the priority in RT will
     +display Low/High/Medium, in this order
     +
    @@ -83,12 +91,13 @@
     +Tickets in queues that aren't defined in this hash will use the mapping
     +defined for C<Default>.
     +
    -+A complete exampl of per-queue priority strings:
    ++A complete example of per-queue priority strings:
     +
     +    Set(%PriorityAsString,
     +      # all queues not listed here will use this mapping
     +      Default    => { Low => 0, Medium => 50, High => 100 },
    -+      # 
    ++      # These queues use strings,
    ++      # drop-downs show labels ordered by ascending priority value
     +      General    => { Low => 0, High => 1 },
     +      ColorQueue => { Green => 0, Yellow => 50, Red => 100 },
     +      # drop-downs will display in order Low/High/Medium
    @@ -100,7 +109,7 @@
     +Redefine C<%PriorityAsString> in C<RT_SiteConfig.pm> to set site
     +priority strings.
     +
    -+The default is 3 levels of priority: Low, Medium and High 
    ++The default is 3 levels of priority: Low, Medium and High
     +
     +=cut
     +
    @@ -111,47 +120,6 @@
      =back
      
      =head2 Group Summary Configuration
    -
    -diff --git a/etc/RT_SiteConfig.pm b/etc/RT_SiteConfig.pm
    -deleted file mode 100644
    ---- a/etc/RT_SiteConfig.pm
    -+++ /dev/null
    -@@
    --use utf8;
    --
    --# Any configuration directives you include  here will override
    --# RT's default configuration file, RT_Config.pm
    --#
    --# To include a directive here, just copy the equivalent statement
    --# from RT_Config.pm and change the value. We've included a single
    --# sample value below.
    --#
    --# If this file includes non-ASCII characters, it must be encoded in
    --# UTF-8.
    --#
    --# This file is actually a perl module, so you can include valid
    --# perl code, as well.
    --#
    --# The converse is also true, if this file isn't valid perl, you're
    --# going to run into trouble. To check your SiteConfig file, use
    --# this command:
    --#
    --#   perl -c /path/to/your/etc/RT_SiteConfig.pm
    --#
    --# You must restart your webserver after making changes to this file.
    --#
    --
    --# You may also split settings into separate files under the etc/RT_SiteConfig.d/
    --# directory.  All files ending in ".pm" will be parsed, in alphabetical order,
    --# after this file is loaded.
    --
    --Set( $rtname, 'example.com');
    --
    --# You must install Plugins on your own, this is only an example
    --# of the correct syntax to use when activating them:
    --#     Plugin( "RT::Authen::ExternalAuth" );
    --
    --1;
     
     diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
     --- a/lib/RT/Config.pm
    @@ -164,7 +132,7 @@
     +        Widget => '/Widgets/Form/Boolean',
     +    },
     +    PriorityAsString => {
    -+        DependsOn => 'EnablePriorityAsString',
    ++        Widget => '/Widgets/Form/String',
     +    },
     +
     +
    @@ -177,19 +145,19 @@
      
     +=head2 Methods for specific options
     +
    -+=head2 PriorityMap( <optional_queue_name>)
    -+
    -+Returns a hash ref C<< { <priority_as_string> => <priority_value>, ... } >> 
    ++=head2 PriorityMap( <optional_queue_name> )
    ++
    ++Returns a hash ref C<< { <priority_as_string> => <priority_value>, ... } >>
     +
     +If no queue name is given uses the configuration for C<'Default'>.
     +
     +If the queue has no C<PriorityAsString> option, uses the one for  C<'Default'>.
     +
     +Returns C<undef> if C<EnablePriorityAsString> is set to 0, if the
    -+queue has C<PriorityAsString> switched off (by setting it to C<0>) or if no 
    ++queue has C<PriorityAsString> switched off (by setting it to C<0>) or if no
     +map is available.
     +
    -+Logs an error if a PriorityAsString is found but it is neither a hash nor an 
    ++Logs an error if a PriorityAsString is found but it is neither a hash nor an
     +array, nor 0.
     +
     +=cut
    @@ -198,12 +166,12 @@
     +  { my $self  = shift;
     +    my $queue = shift || 'Default';
     +
    -+    my $option = $self->_get_PriorityAsString_for_queue( $queue );
    ++    my $option = $self->PriorityAsStringForQueue( $queue );
     +    return undef if ! $option;
     +
     +    my $map;
     +    if ( ref $option eq 'HASH' ) {
    -+        # regular map 
    ++        # regular map
     +        $map = $option
     +    } elsif ( ref $option eq 'ARRAY' ) {
     +        # order is irrelevent here, load the array as a hash
    @@ -218,18 +186,18 @@
     +                       : defined $queues->{Default} ? 'Default queue'
     +                       :                              'cannot happen';
     +
    -+        # what's in the map definition 
    -+        my $option_desc = ref $option         ? "map is a " . ref( $option)
    ++        # what's in the map definition
    ++        my $option_desc = ref $option         ? "map is a " . ref( $option )
     +                        : length $option < 20 ? $option
    -+                        :                     substr( $option, 0, 17) . '...';
    -+
    -+        $RT::Logger->error("Wrong priority map for $real_queue: $option_desc");
    ++                        :                     substr( $option, 0, 17 ) . '...';
    ++
    ++        $RT::Logger->error( "Wrong priority map for $real_queue: $option_desc" );
     +        return undef;
     +    }
     +    return $map;
     +  }
     +
    -+=head2 PriorityMapOrder( <optional_queue_name>)
    ++=head2 PriorityMapOrder( <optional_queue_name> )
     +
     +Returns an array of priority strings, in the proper order for display.
     +
    @@ -243,7 +211,7 @@
     +  { my $self  = shift;
     +    my $queue = shift || 'Default';
     +
    -+    my $option = $self->_get_PriorityAsString_for_queue( $queue );
    ++    my $option = $self->PriorityAsStringForQueue( $queue );
     +    return undef if ! $option;
     +
     +    my @ordered;
    @@ -263,10 +231,11 @@
     +
     +  }
     +
    -+# internal method, _get_PriorityAsString_for_queue( <queue name> )
    -+# returns 
    -+
    -+sub _get_PriorityAsString_for_queue
    ++# internal method, PriorityAsStringForQueue( <queue name> )
    ++# returns a hashref { <label> => <value>, ... } or undef if no
    ++# priority mapping was found
    ++
    ++sub PriorityAsStringForQueue
     +  { my $self  = shift;
     +    my $queue = shift;
     +
    @@ -294,8 +263,8 @@
          );
      
     +    if( $args{Name}=~ /^(Initial|Final)Priority/ ) {
    -+        $old_value= $self->_PriorityAsString( $old_value );
    -+        $new_value= $self->_PriorityAsString( $new_value );
    ++        $old_value= $self->PriorityAsString( $old_value );
    ++        $new_value= $self->PriorityAsString( $new_value );
     +    }
     +
          if ( $ret ) {
    @@ -305,8 +274,8 @@
          }
      }
      
    -+sub _PriorityAsString {
    -+    my( $self, $priority)= @_;
    ++sub PriorityAsString {
    ++    my( $self, $priority )= @_;
     +    my $map = RT->Config->PriorityMap( $self->Name );
     +    return RT::Ticket->_PriorityAsString( $priority, $map );
     +}
    @@ -325,7 +294,7 @@
     +
     +    my $New= $args{'Value'};
     +    # *Priority fields may need to be translated
    -+    if( $args{'Field'} =~ m{^(Initial|Final)?Priority$}) {
    ++    if( $args{'Field'} =~ m{^(Initial|Final)?Priority$} ) {
     +        $Old= $self->_PriorityAsString( $Old );
     +        $New= $self->_PriorityAsString( $New );
     +    }
    @@ -394,17 +363,19 @@
     +    return undef unless defined $priority && length $priority;
     +
     +    my $map;
    -+    if( @_ ) {
    ++    if ( @_ ) {
     +        $map = shift;
     +    } else {
     +        my $queue_name = $self->QueueObj->Name;
    -+        $map = RT->Config->PriorityMap( $queue_name);
    ++        $map = RT->Config->PriorityMap( $queue_name );
     +    }
     +
     +    return $priority if ! $map;
     +
     +    my @orderedLabels = sort { $map->{$b} <=> $map->{$a} }  keys %$map;
     +
    ++    # priority could be '(no value)' (or a localized version)
    ++    $priority = 0 if $priority !~ m{^\d+$};
     +    # return the label for the first priority <= $priority
     +    foreach my $label ( @orderedLabels ) {
     +        return $label if $priority >= $map->{ $label };
    @@ -430,7 +401,7 @@
     +      <& /Elements/SelectPriority,
     +         Name => "InitialPriority",
     +         Default => $queue->DefaultValue('InitialPriority'),
    -+         QueueObj  => $queue
    ++         QueueObj => $queue
     +      &>
          </div>
        </div>
    @@ -443,7 +414,7 @@
     +      <& /Elements/SelectPriority,
     +         Name => "FinalPriority",
     +         Default => $queue->DefaultValue('FinalPriority'),
    -+         QueueObj  => $queue
    ++         QueueObj => $queue
     +      &>
            <span><em><&|/l&>requires running rt-crontool</&></em></span>
          </div>
    @@ -457,9 +428,9 @@
          Priority => {
              title     => 'Priority', # loc
     -        value     => sub { return join '-', $_[0]->DefaultValue('InitialPriority') || '', $_[0]->DefaultValue('FinalPriority') || '' },
    -+        value     => sub { return join '/', 
    -+                               map { $_[0]->_PriorityAsString( $_[0]->DefaultValue($_) || 0) }
    -+                                   qw( InitialPriority FinalPriority); 
    ++        value     => sub { return join '/',
    ++                               map { $_[0]->PriorityAsString( $_[0]->DefaultValue( $_ ) || 0 ) }
    ++                                   qw( InitialPriority FinalPriority );
     +                     },
          },
          DefaultDueIn => {
    @@ -473,30 +444,30 @@
      }
      
     +my $printer = sub {
    -+    my ($class, $string) = @_;
    ++    my ( $class, $string ) = @_;
     +    return '' unless defined $string && length $string;
     +
     +    my $request_path = $HTML::Mason::Commands::r->path_info;
    -+    if ($request_path and $request_path =~ /Results\.tsv/) {
    -+        return loc($string);
    -+    }
    -+
    -+    my $escaped = $m->interp->apply_escapes($string, 'h');
    -+    my $loc_escaped = $m->interp->apply_escapes(loc($string), 'h');
    -+    return \( qq{<span class="ticket-info-$class-}. lc($escaped) .qq{">$loc_escaped</span>} );
    ++    if ( $request_path and $request_path =~ /Results\.tsv/ ) {
    ++        return loc( $string);
    ++    }
    ++
    ++    my $escaped = $m->interp->apply_escapes( $string, 'h' );
    ++    my $loc_escaped = $m->interp->apply_escapes( loc( $string ), 'h' );
    ++    return \( qq{<span class="ticket-info-$class-} . lc( $escaped ) . qq{">$loc_escaped</span>} );
     +};
     +
    -+my $queues = RT->Config->Get('PriorityAsString') || {};
    -+
    -+foreach my $field (qw(Priority InitialPriority FinalPriority)) {
    ++my $queues = RT->Config->Get( 'PriorityAsString' ) || {};
    ++
    ++foreach my $field ( qw( Priority InitialPriority FinalPriority ) ) {
     +    $COLUMN_MAP->{ $field .'Number' } ||= $COLUMN_MAP->{ $field };
     +
    -+    my $class = lc($field);
    ++    my $class = lc( $field );
     +    $class =~ s/(?=<.)(?=priority)/-/;
     +
    -+    my $method = $field .'AsString';
    -+
    -+    if (not keys %$queues) {
    ++    my $method = $field . 'AsString';
    ++
    ++    if ( not keys %$queues ) {
     +        $COLUMN_MAP->{ $field }{'value'} = sub {
     +            return $printer->( $class, $_[0]->$method() );
     +        };
    @@ -520,26 +491,25 @@
      %# those contributions and any derivatives thereof.
      %#
      %# END BPS TAGGED BLOCK }}}
    --<input name="<% $Name %>" type="text" value="<% $Default %>" size="5" class="form-control" />
    -+% if (%map) {
    ++% if ( %Map ) {
     +<select class="select-priority form-control" name="<% $Name %>">
     +%     unless ( defined $Default ) {
     +<option value="">-</option>
     +%     }
     +<%PERL>
    -+foreach my $label ( @order ) {
    -+    my ($value, $selected);
    -+    if ( $label eq $default_label ) {
    -+        ($value, $selected) = ($Default, 'selected="selected"');
    ++foreach my $Label ( @Order ) {
    ++    my ( $Value, $Selected );
    ++    if ( $Label eq $DefaultLabel ) {
    ++        ( $Value, $Selected ) = ( $Default, 'selected="selected"' );
     +    } else {
    -+        ($value, $selected) = ($map{ $label }, '');
    ++        ( $Value, $Selected ) = ( $Map{ $Label }, '' );
     +    }
     +</%PERL>
    -+<option class="<% lc $label %>" value="<% $value %>" <% $selected |n %>><% loc($label) %></option>
    ++<option class="<% lc $Label %>" value="<% $Value %>" <% $Selected |n %>><% loc($Label) %></option>
     +% }
     +</select>
     +% } else {
    -+<input name="<% $Name %>" value="<% $Default %>" size="5" class="form-control" />
    + <input name="<% $Name %>" type="text" value="<% $Default %>" size="5" class="form-control" />
     +% }
      <%ARGS>
      $Name => 'Priority'
    @@ -549,18 +519,17 @@
      </%ARGS>
      <%INIT>
     +
    -+my $priority_is_string = undef;
    -+my @order;
    -+my $default_label = '';
    -+my %map = ();
    -+
    -+
    -+if( $QueueObj ) {
    -+    if( my $map = RT->Config->PriorityMap( $QueueObj->Name ) ) {
    -+        %map   = %$map;
    -+        @order = @{RT->Config->PriorityMapOrder( $QueueObj->Name)};
    ++my @Order;
    ++my $DefaultLabel = '';
    ++my %Map = ();
    ++
    ++
    ++if ( $QueueObj and $QueueObj->Id ) {
    ++    if ( my $Map = RT->Config->PriorityMap( $QueueObj->Name ) ) {
    ++        %Map   = %$Map;
    ++        @Order = @{RT->Config->PriorityMapOrder( $QueueObj->Name )};
     +        if ( defined $Default && length $Default ) {
    -+        $default_label = RT::Ticket->_PriorityAsString( $Default, \%map ) || '';
    ++        $DefaultLabel = $QueueObj->PriorityAsString( $Default );
     +        }
     +    }
     +}
    @@ -572,25 +541,24 @@
     --- a/share/html/Search/Elements/PickBasics
     +++ b/share/html/Search/Elements/PickBasics
     @@
    -     },
    - );
    - 
    -+
    -+if ( RT->Config->Get('EnablePriorityAsString') ) {
    -+    my ($priority_dropdown) = grep {$_->{Name} eq "Priority"} @lines;
    -+    my %priority_map = ( '-' => '' );
    -+    for my $queue (keys %queues) {
    -+    my $queue_priority_map= RT::Config->PriorityMap( $queue );
    -+    for my $priority ( keys %$queue_priority_map ) {
    -+        $priority_map{ keys %queues > 1 ? "$queue: $priority" : "$priority" } = $queue_priority_map->{$priority};
    -+    }
    -+    }
    -+    $priority_dropdown->{Value}{Arguments}{PriorityStringMap} = \%priority_map;
    -+}
    -+
    +             Value => { Type => 'text', Size => 5 }
    +         },
    +     );
    ++
    ++    if ( RT->Config->Get('EnablePriorityAsString') ) {
    ++        my ( $priority_dropdown ) = grep { $_->{Name} eq "Priority" } @lines;
    ++        my %priority_map = ( '-' => '' );
    ++        for my $queue (keys %queues) {
    ++            my $queue_priority_map= RT::Config->PriorityMap( $queue );
    ++            for my $priority ( keys %$queue_priority_map ) {
    ++                $priority_map{ keys %queues > 1 ? "$queue: $priority" : "$priority" } = $queue_priority_map->{$priority};
    ++            }
    ++        }
    ++        $priority_dropdown->{Value}{Arguments}{PriorityStringMap} = \%priority_map;
    ++    }
    + }
    + 
      $m->callback( Conditions => \@lines );
    - 
    - </%INIT>
     
     diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
     --- a/share/html/Ticket/Create.html
    @@ -647,7 +615,7 @@
      use RT::Test tests => 170;
      
     +# we want to check the numerical priorities
    -+RT::Config->Set( EnablePriorityAsString => 0);
    ++RT::Config->Set( EnablePriorityAsString => 0 );
     +
      my ( $url, $m ) = RT::Test->started_ok;
      my $root = RT::Test->load_or_create_user( Name => 'root' );
2: c74f4d8e5d ! 2: c15f80d239 Test PriorityAsString.
    @@ -1,41 +1,6 @@
     Author: michel <michel at bestpractical.com>
     
    -    Adds tests and removes a warning
    -    
    -    Saving either the default values form for a queue or basics for a ticket
    -    without changing any value in the form generates an error in the logs.
    -
    -diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
    ---- a/lib/RT/Ticket.pm
    -+++ b/lib/RT/Ticket.pm
    -@@
    - 
    -     my @orderedLabels = sort { $map->{$b} <=> $map->{$a} }  keys %$map;
    - 
    -+    # priority could be '(no value)' (or a localized version)
    -+    $priority = 0 if $priority !~ m{^\d+$};
    -     # return the label for the first priority <= $priority
    -     foreach my $label ( @orderedLabels ) {
    -         return $label if $priority >= $map->{ $label };
    -
    -diff --git a/share/html/Elements/SelectPriority b/share/html/Elements/SelectPriority
    ---- a/share/html/Elements/SelectPriority
    -+++ b/share/html/Elements/SelectPriority
    -@@
    - my %map = ();
    - 
    - 
    --if( $QueueObj ) {
    -+if( $QueueObj and $QueueObj->Id ) {
    -     if( my $map = RT->Config->PriorityMap( $QueueObj->Name ) ) {
    -         %map   = %$map;
    -         @order = @{RT->Config->PriorityMapOrder( $QueueObj->Name)};
    -         if ( defined $Default && length $Default ) {
    --        $default_label = RT::Ticket->_PriorityAsString( $Default, \%map ) || '';
    -+        $default_label = $QueueObj->_PriorityAsString( $Default);
    -         }
    -     }
    - }
    +    Test PriorityAsString.
     
     diff --git a/t/web/queue_create.t b/t/web/queue_create.t
     --- a/t/web/queue_create.t



More information about the rt-commit mailing list