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

Brian Duggan brian at bestpractical.com
Fri Jun 15 19:05:24 EDT 2018


The branch 4.6/priority-as-string was deleted and repushed:
       was 3527362186da7e752ccff70d46575499026d7b07
       now b2f029ac4c1cd33289f752882316c453214fc284

1: 352736218 ! 1: b2f029ac4 Core RT::Extension::PriorityAsString
    @@ -10,14 +10,17 @@
     +++ b/etc/RT_Config.pm.in
     @@
      
    - =back
    - 
    -+
    -+
    -+
    -+=head1 Priority strings
    -+
    -+=over 4
    + Set($LinkArticlesOnInclude, 1);
    + 
    ++=item C<%NumericalPriority>
    ++
    ++Disable string priorities
    ++
    ++    Set($NumericalPriority, 0);
    ++
    ++=cut
    ++
    ++Set($NumericalPriority, 0);
     +
     +=item C<%PriorityAsString>
     +
    @@ -32,7 +35,7 @@
     +
     +=cut
     +
    -+Set(%PriorityAsString, (Low => 0, Medium => 50, High => 100));
    ++Set(%DefaultPriorityAsString, (Low => 0, Medium => 50, High => 100));
     +
     +=item C<%PriorityAsStringOrder>
     +
    @@ -69,29 +72,56 @@
     +
     +=cut
     +
    -+=back
    -+
    -+
    -+
    - =head1 Administrative interface
    - 
    - =over 4
    + =back
    + 
    + =head1 Assets
    +
    +diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
    +--- a/lib/RT/Config.pm
    ++++ b/lib/RT/Config.pm
    +@@
    +     ServiceAgreements => {
    +         Type => 'HASH',
    +     },
    ++
    ++    PriorityAsStringQueues => {
    ++        Type => 'HASH',
    ++        PostLoadCheck => sub {
    ++            my $self = shift;
    ++
    ++            my $numerical_priority = $self->Get('NumericalPriority');
    ++            my %default_config = $self->Get('DefaultPriorityAsString');
    ++            my %user_config = $self->Get('PriorityAsString');
    ++            my %config = $self->Get('PriorityAsStringQueues');
    ++
    ++            if ($numerical_priority) {
    ++               %default_config = undef;
    ++            } elsif (%user_config) {
    ++               %default_config = %user_config;
    ++            }
    ++
    ++            my $queues = RT::Queues->new(RT->SystemUser);
    ++            $queues->Limit(
    ++                FIELD    => 'Name',
    ++                OPERATOR => '!=',
    ++                VALUE    => '___Approvals',
    ++            );
    ++            my @queue_configs = keys %config;
    ++            while (my $queue = $queues->Next) {
    ++               $config{$queue->Name} = {%default_config} unless defined $config{$queue->Name};
    ++            }
    ++
    ++            $self->Set( 'PriorityAsStringQueues', %config );
    ++        },
    ++    },
    + );
    + my %OPTIONS = ();
    + my @LOADED_CONFIGS = ();
     
     diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
     --- a/lib/RT/Ticket.pm
     +++ b/lib/RT/Ticket.pm
     @@
    - use MIME::Entity;
    - use Devel::GlobalDestruction;
    - 
    -+$RT::Config::META{PriorityAsString}{Type} = 'HASH';
    -+$RT::Config::META{PriorityAsStringOrder}{Type} = 'ARRAY';
    -+$RT::Config::META{PriorityAsStringQueues}{Type} = 'HASH';
    -+
    - sub LifecycleColumn { "Queue" }
    - 
    - my %ROLES = (
    -@@
      Returns the current value of InitialPriority.
      (In the database, InitialPriority is stored as int(11).)
      
    @@ -125,13 +155,6 @@
          return %store;
      }
      
    -+sub PriorityIsString {
    -+    my $self = shift;
    -+    my %queues = RT->Config->Get('PriorityAsStringQueues');
    -+    return 0 if (keys %queues and not $queues{$self->QueueObj->Name});
    -+    return 1;
    -+}
    -+
     +# Returns String: Various Ticket Priorities as either a string or integer
     +sub PriorityAsString {
     +    my $self = shift;
    @@ -227,96 +250,14 @@
     --- a/share/html/Elements/SelectPriority
     +++ b/share/html/Elements/SelectPriority
     @@
    - <input name="<% $Name %>" value="<% $Default %>" size="5" />
    - <%ARGS>
    - $Name => 'Priority'
    --$Default => ''
    -+$Default => undef
    - </%ARGS>
    - <%INIT>
    -+
    -+my %queues = RT->Config->Get('PriorityAsStringQueues');
    -+
    -+# If enabled for all queues, always show the drop-down
    -+return $m->comp("/Elements/SelectPriorityAsString",%ARGS)
    -+    unless keys %queues;
    -+
    -+# Some callsites we can easily override with callbacks with logic to
    -+# know when to call SelectPriorityAsString; for ticket create and queue
    -+# modify, we need to inspect the callstack.
    -+my $caller      = $m->callers(1)->path;
    -+my $caller_args = $m->caller_args(1);
    -+my $QueueObj = RT::Queue->new( $session{'CurrentUser'} );
    -+if ( $caller eq "/Admin/Queues/Modify.html") {
    -+    $QueueObj->Load( $caller_args->{id} ) || $QueueObj->Load( $caller_args->{Name} );
    -+} elsif ( $caller eq "/Ticket/Create.html" or $caller eq "/m/ticket/create" ) {
    -+    RT::Logger->debug("Pri3");
    -+    $QueueObj->Load( $caller_args->{Queue} );
    -+}
    -+RT::Logger->debug("Queue ID: ".$QueueObj->Id);
    -+RT::Logger->debug("Queue Name: ".$QueueObj->Name);
    -+return $m->comp("/Elements/SelectPriorityAsString",%ARGS, Mapping => $queues{$QueueObj->Name})
    -+    if $QueueObj->Id and $queues{$QueueObj->Name};
    -+
    - $Default = '' unless defined $Default;
    - </%INIT>
    -
    -diff --git a/share/html/Elements/SelectPriorityAsString b/share/html/Elements/SelectPriorityAsString
    -new file mode 100644
    ---- /dev/null
    -+++ b/share/html/Elements/SelectPriorityAsString
    -@@
    -+%# BEGIN BPS TAGGED BLOCK {{{
    -+%#
    -+%# COPYRIGHT:
    -+%#
    -+%# This software is Copyright (c) 1996-2017 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 }}}
    + %# those contributions and any derivatives thereof.
    + %#
    + %# END BPS TAGGED BLOCK }}}
    ++% if (%map) {
     +<select class="select-priority" name="<% $Name %>">
    -+% unless ( defined $Default ) {
    ++%     unless ( defined $Default ) {
     +<option value="">-</option>
    -+% }
    ++%     }
     +<%PERL>
     +foreach my $label ( @order ) {
     +    my ($value, $selected);
    @@ -329,26 +270,45 @@
     +<option class="<% lc $label %>" value="<% $value %>" <% $selected |n %>><% loc($label) %></option>
     +% }
     +</select>
    -+<%ARGS>
    -+$Name => 'Priority'
    ++% } else {
    + <input name="<% $Name %>" value="<% $Default %>" size="5" />
    ++% }
    + <%ARGS>
    + $Name => 'Priority'
    +-$Default => ''
     +$Default => undef
    -+$Mapping => undef
    -+</%ARGS>
    -+<%INIT>
    -+
    -+my %map   = $Mapping ? %{ $Mapping } : RT->Config->Get('PriorityAsString');
    ++$QueueObj => undef
    ++$PriorityStringMap => undef
    + </%ARGS>
    + <%INIT>
    ++
    ++my $priority_is_string = undef;
     +my @order;
    -+if (not $Mapping and RT->Config->Get('PriorityAsStringOrder')) {
    -+    @order = grep {exists $map{$_}} RT->Config->Get('PriorityAsStringOrder');
    -+} else {
    -+    @order = sort { $map{$a} <=> $map{$b} } keys %map;
    -+}
    -+
     +my $default_label = '';
    -+if ( defined $Default && length $Default ) {
    -+    $default_label = RT::Ticket->_PriorityAsString( $Default, \%map ) || '';
    -+}
    -+</%INIT>
    ++my %map = undef;
    ++
    ++use Data::Dumper;
    ++if ($PriorityStringMap) {
    ++    %map = %{$PriorityStringMap};
    ++} elsif ($QueueObj) {
    ++    my %config = RT->Config->Get('PriorityAsStringQueues');
    ++    %map = %{$config{$QueueObj->Name}};
    ++}
    ++
    ++if (%map) {
    ++    if (RT->Config->Get('PriorityAsStringOrder')) {
    ++	@order = grep {exists $map{$_}} RT->Config->Get('PriorityAsStringOrder');
    ++    } else {
    ++	@order = sort { $map{$a} <=> $map{$b} } keys %map;
    ++    }
    ++
    ++    if ( defined $Default && length $Default ) {
    ++	$default_label = RT::Ticket->_PriorityAsString( $Default, \%map ) || '';
    ++    }
    ++}
    ++
    + $Default = '' unless defined $Default;
    + </%INIT>
     
     diff --git a/share/html/Search/Elements/PickBasics b/share/html/Search/Elements/PickBasics
     --- a/share/html/Search/Elements/PickBasics
    @@ -357,37 +317,39 @@
          },
      );
      
    -+# Updating 'Path' for *Priority:
    -+#
    -+# Don't update 'Path' when %PriorityAsStringQueues is not
    -+# configured. SelectPriority hands off to SelectPriorityAsString when
    -+# %PriorityAsString is configured.
    -+#
    -+# Display the number input unless all queues specified use
    -+# %PriorityAsStringQueues.
    -+my %as_string = RT->Config->Get('PriorityAsStringQueues');
    -+
    -+if ( %queues and %as_string and scalar(keys %queues) == grep {$as_string{$_}} keys %queues ) {
    -+    # Additionally, all queues in PriorityAsStringQueues must use the _same_
    -+    # values for each name; if "High" is mapped to 10 in one queue and 100
    -+    # in another, we can't use names
    -+    my %values;
    -+    for my $q (keys %queues) {
    -+        for my $priority (keys %{$as_string{$q}}) {
    -+            return if exists $values{$priority} and $as_string{$q}{$priority} != $values{$priority};
    -+            $values{$priority} = $as_string{$q}{$priority};
    -+        }
    -+    }
    -+
    -+    # Swap out the /Elements/SelectPriority for /Elements/SelectPriorityAsString
    -+    my ($priority) = grep {$_->{Name} eq "Priority"} @lines;
    -+    $priority->{Value}{Path} = "/Elements/SelectPriorityAsString";
    -+    $priority->{Value}{Arguments}{Mapping} = \%values;
    ++my %priority_strings = RT->Config->Get('PriorityAsStringQueues');
    ++if ( !RT->Config->Get('NumericalPriority') ) {
    ++    my ($priority_dropdown) = grep {$_->{Name} eq "Priority"} @lines;
    ++    my %priority_map = ( '-' => '' );
    ++    for my $queue (keys %queues) {
    ++	for my $priority (keys %{$priority_strings{$queue}}) {
    ++	    $priority_map{ keys %queues > 1 ? "$queue: $priority" : "$priority" } = $priority_strings{$queue}{$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
    ++++ b/share/html/Ticket/Create.html
    +@@
    + <td><& /Elements/SelectPriority,
    +     Name => "InitialPriority",
    +     Default => $ARGS{InitialPriority} ? $ARGS{InitialPriority} : $QueueObj->DefaultValue('InitialPriority'),
    ++    QueueObj => $QueueObj,
    + &></td></tr>
    + <tr><td class="label"><&|/l&>Final Priority</&>:</td>
    + <td><& /Elements/SelectPriority,
    +     Name => "FinalPriority",
    +     Default => $ARGS{FinalPriority} ? $ARGS{FinalPriority} : $QueueObj->DefaultValue('FinalPriority'),
    ++    QueueObj => $QueueObj,
    + &></td></tr>
    + <tr><td class="label"><&|/l&>Time Estimated</&>:</td>
    + <td>
     
     diff --git a/share/html/Ticket/Elements/EditBasics b/share/html/Ticket/Elements/EditBasics
     --- a/share/html/Ticket/Elements/EditBasics
    @@ -396,33 +358,24 @@
          $QueueObj ||= $TicketObj->QueueObj;
      }
      
    -+my %queue_priority_strings = RT->Config->Get('PriorityAsStringQueues');
    -+
    -+# Leave it as-is if all queues use PriorityAsString; the overridden
    -+# /Elements/SelectPriority catches this case and always shows the
    -+# drop-down
    -+#return unless keys %as_string;
    -+
    -+# Only applies if the ticket is in a PriorityAsString queue
    -+#return unless $TicketObj and $as_string{$TicketObj->QueueObj->Name};
    ++#my %queue_priority_strings = RT->Config->Get('PriorityAsStringQueues');
    ++#
    ++## Leave it as-is if all queues use PriorityAsString; the overridden
    ++## /Elements/SelectPriority catches this case and always shows the
    ++## drop-down
    ++##return unless keys %as_string;
    ++#
    ++## Only applies if the ticket is in a PriorityAsString queue
    ++##return unless $TicketObj and $as_string{$TicketObj->QueueObj->Name};
     +
      unless ( @fields ) {
          my $subject = $defaults{'Subject'} || $TicketObj->Subject;
          @fields = (
     @@
    -                 (my $field = $_) =~ s/ //g;
    -                 {
    -                     name => $_,
    --                    comp => '/Elements/SelectPriority',
    -+                    comp => $TicketObj->PriorityIsString
    -+                        ? '/Elements/SelectPriorityAsString'
    -+                        : '/Elements/SelectPriority',
                          args => {
                              Name => $field,
                              Default => $defaults{$field} || $TicketObj->$field,
    -+                        Mapping => $TicketObj->PriorityIsString
    -+                            ? $queue_priority_strings{$TicketObj->QueueObj->Name}
    -+                            : undef,
    ++			QueueObj => $QueueObj,
                          }
                      }
                  } ('Priority', 'Final Priority')
    @@ -434,10 +387,9 @@
      %# those contributions and any derivatives thereof.
      %#
      %# END BPS TAGGED BLOCK }}}
    -+%# if (keys %queues and not $queues{$Ticket->QueueObj->Name}) {
    -+% if ( $Ticket->PriorityIsString ) {
    -+% my $current = $Ticket->PriorityAsString || '';
    -+% my $final = $Ticket->FinalPriorityAsString || '';
    ++% if ( !RT->Config->Get('NumericalPriority') ) {
    ++%   my $current = $Ticket->PriorityAsString || '';
    ++%   my $final = $Ticket->FinalPriorityAsString || '';
     +<span class="ticket-info-priority-<% $CSSClass->(lc($current)) %>"><% loc($current) %></span>/\
     +<span class="ticket-info-final-priority-<% $CSSClass->(lc($final)) %>"><% loc($final) %></span>
     +% } else {



More information about the rt-commit mailing list