From 5ac852e9e87f39e22b6e09b371efad0d8c71b7cc Mon Sep 17 00:00:00 2001 From: Jim Brandt Date: Thu, 18 Apr 2024 10:07:18 -0400 Subject: [PATCH] Don't add Unlimited automatically in Rows per page Adding Unlimited automatically prevented admins from removing that option if desired. Update the option to use the configuration as provided, updating the label for 0 to Unlimited if present. --- docs/UPGRADING-5.0 | 12 ++++++++++++ etc/RT_Config.pm.in | 4 ++-- lib/RT/Config.pm | 5 +++-- share/html/Elements/SelectResultsPerPage | 10 ++++++++-- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/docs/UPGRADING-5.0 b/docs/UPGRADING-5.0 index 36b3115a29b..a97eb7b33e3 100644 --- a/docs/UPGRADING-5.0 +++ b/docs/UPGRADING-5.0 @@ -682,6 +682,18 @@ compatible version of DBD::mysql. If you install a newer version of DBD::mysql by mistake, you can uninstall it or manually force install a version older than 5.001. +=item Unlimited Option in SearchResultsPerPage Configuration + +RT 5.0.4 added C<@SearchResultsPerPage> as a configuration option to allow admins to +control the options presented in the "Rows per page" dropdown in the Query Builder. +When it was added, the "Unlimited" option was automatically added to the list of options +configured. This prevented admins from removing the "Unlimited" option from the +list, so this has been updated in RT 5.0.6 to use the configured options only with +no other options added automatically. + +If you previously set a custom C<@SearchResultsPerPage> and you want to keep the +"Unlimited" option, update your configuration and add "0" to your list. + =back =cut diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in index 39a37a8ebd7..cd370603e22 100644 --- a/etc/RT_Config.pm.in +++ b/etc/RT_Config.pm.in @@ -2427,11 +2427,11 @@ Set( $DefaultSearchResultRowsPerPage, 50 ); =item C<@SearchResultsPerPage> Defines the options in the Rows per page dropdown on the query builder. -The "Unlimited" option, which is 0, is included automatically. +Include "0" to provide the "Unlimited" option. =cut -Set(@SearchResultsPerPage, qw(10 25 50 100)); +Set(@SearchResultsPerPage, qw(0 10 25 50 100)); =item C<$UserTicketDataResultFormat> diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm index e670f3ca451..781a22586d3 100644 --- a/lib/RT/Config.pm +++ b/lib/RT/Config.pm @@ -2119,11 +2119,12 @@ our %META; Callback => sub { my @values = RT->Config->Get('SearchResultsPerPage'); my %labels = ( - 0 => "Unlimited", # loc map { $_ => $_ } @values, ); - unshift @values, 0; + if ( exists $labels{'0'} ) { + $labels{'0'} = 'Unlimited'; + } return { Values => \@values, ValuesLabel => \%labels }; }, diff --git a/share/html/Elements/SelectResultsPerPage b/share/html/Elements/SelectResultsPerPage index 076d0552642..6956c977a58 100644 --- a/share/html/Elements/SelectResultsPerPage +++ b/share/html/Elements/SelectResultsPerPage @@ -57,8 +57,14 @@ <%INIT> my @values = RT->Config->Get('SearchResultsPerPage'); -my @labels = (loc('Unlimited'), @values); -unshift @values, 0; +my @labels = @values; + +# Convert the label for 0 to 'Unlimited', if provided +for ( my $rows = 0; $rows < scalar(@values); $rows++ ) { + if ( $values[$rows] == 0 ) { + $labels[$rows] = loc('Unlimited'); + } +} $Default //= RT->Config->Get('DefaultSearchResultRowsPerPage') // 50; unless ( $Default =~ /^\d+$/ ) {