[Rt-commit] rt branch, 4.4/config-option-search-results-navigation-links, created. rt-4.4.4-127-g83260d193c
Craig Kaiser
craig at bestpractical.com
Fri Aug 28 13:17:46 EDT 2020
The branch, 4.4/config-option-search-results-navigation-links has been created
at 83260d193ccf6a1460598ce5164842f85d958d75 (commit)
- Log -----------------------------------------------------------------
commit 4ea15a92c3e10a3807fbfa766369410573f3e67b
Author: craig kaiser <craig at bestpractical.com>
Date: Tue Jun 23 10:17:15 2020 -0400
Add config option to disable search results navigation links
Generating these links requires running the RT::Tickets->_BuildItemMap
method for the current tickets search. which results in the loading of
the ticket display page taking slightly longer.
diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 44e8ce56d1..9865a5dfe0 100644
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1506,6 +1506,17 @@ ticket display page automatically.
Set($SearchResultsAutoRedirect, 0);
+
+=item C<$ShowSearchNavigation>
+
+Option to build the search navigation options in the RT menu ( First, Last, Prev, Next ).
+This feature requires the re-running of the current search in order to accuratly create
+the menu links, disabling it can speed up ticket load time.
+
+=cut
+
+Set($ShowSearchNavigation, 1);
+
=back
diff --git a/share/html/Elements/Tabs b/share/html/Elements/Tabs
index f6233c33fa..03cce37d08 100644
--- a/share/html/Elements/Tabs
+++ b/share/html/Elements/Tabs
@@ -861,31 +861,33 @@ my $build_main_nav = sub {
path => "/Articles/Article/ExtractIntoClass.html?Ticket=".$obj->id,
) if $session{CurrentUser}->HasRight( Right => 'ShowArticlesMenu', Object => RT->System );
- if ( defined $session{"tickets"} ) {
- # we have to update session data if we get new ItemMap
- my $updatesession = 1 unless ( $session{"tickets"}->{'item_map'} );
+ if ( RT::Config->Get( 'ShowSearchNavigation' ) ) {
+ if ( defined $session{"tickets"} ) {
+ # we have to update session data if we get new ItemMap
+ my $updatesession = 1 unless ( $session{"tickets"}->{'item_map'} );
- my $item_map = $session{"tickets"}->ItemMap;
+ my $item_map = $session{"tickets"}->ItemMap;
- if ($updatesession) {
- $session{"tickets"}->PrepForSerialization();
- }
+ if ($updatesession) {
+ $session{"tickets"}->PrepForSerialization();
+ }
- my $search = Menu()->child('search')->child('tickets');
- # Don't display prev links if we're on the first ticket
- if ( $item_map->{$id}->{prev} ) {
- $search->child( first =>
- title => '<< ' . loc('First'), class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{first});
- $search->child( prev =>
- title => '< ' . loc('Prev'), class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{$id}->{prev});
- }
- # Don't display next links if we're on the last ticket
- if ( $item_map->{$id}->{next} ) {
- $search->child( next =>
- title => loc('Next') . ' >', class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{$id}->{next});
- if ( $item_map->{last} ) {
- $search->child( last =>
- title => loc('Last') . ' >>', class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{last});
+ my $search = Menu()->child('search')->child('tickets');
+ # Don't display prev links if we're on the first ticket
+ if ( $item_map->{$id}->{prev} ) {
+ $search->child( first =>
+ title => '<< ' . loc('First'), class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{first});
+ $search->child( prev =>
+ title => '< ' . loc('Prev'), class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{$id}->{prev});
+ }
+ # Don't display next links if we're on the last ticket
+ if ( $item_map->{$id}->{next} ) {
+ $search->child( next =>
+ title => loc('Next') . ' >', class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{$id}->{next});
+ if ( $item_map->{last} ) {
+ $search->child( last =>
+ title => loc('Last') . ' >>', class => "nav", path => "/Ticket/Display.html?id=" . $item_map->{last});
+ }
}
}
}
diff --git a/share/html/Ticket/Display.html b/share/html/Ticket/Display.html
index 2681a38313..1f3284c3e6 100644
--- a/share/html/Ticket/Display.html
+++ b/share/html/Ticket/Display.html
@@ -240,7 +240,7 @@ my $attachments = $TicketObj->Attachments;
my $attachment_content = $TicketObj->TextAttachments;
my %link_rel;
-if (defined $session{'tickets'} and ($ARGS{'Query'} or $session{'CurrentSearchHash'}->{'Query'})) {
+if (RT::Config->Get( 'ShowSearchNavigation' ) && defined $session{'tickets'} and ($ARGS{'Query'} or $session{'CurrentSearchHash'}->{'Query'})) {
my $item_map = $session{'tickets'}->ItemMap;
$link_rel{first} = "/Ticket/Display.html?id=" . $item_map->{first} if $item_map->{$TicketObj->Id}{prev};
$link_rel{prev} = "/Ticket/Display.html?id=" . $item_map->{$TicketObj->Id}{prev} if $item_map->{$TicketObj->Id}{prev};
commit b34034b3531d4af6c2b6ac6147133064e7d33703
Author: craig kaiser <craig at bestpractical.com>
Date: Tue Jun 23 11:11:36 2020 -0400
Add tests for 'ShowSearchNavigation' config option
diff --git a/t/web/search_linkdisplay.t b/t/web/search_linkdisplay.t
index 8d18f547ad..d0a6d7ef3d 100644
--- a/t/web/search_linkdisplay.t
+++ b/t/web/search_linkdisplay.t
@@ -59,4 +59,25 @@ $ref = $m->find_link( url_regex => qr!/Article/Display.html! );
ok( $ref, "found article link" );
is( $ref->text, $article->URIObj->Resolver->AsString, $article->URIObj->Resolver->AsString . " is displayed" );
+
+# Get a search that returns multiple tickets
+$m->get_ok("/Search/Results.html?Format=id,RefersTo;Query=id>0");
+
+ok $m->goto_ticket( $ticket->Id ), 'opened diplay page of ticket # '.$ticket->Id;
+my $t_link = $m->find_link( id => "search-tickets-next" )->url;
+is ($t_link, "/Ticket/Display.html?id=".$ticket2->Id, 'link to the next ticket in current search found');
+
+diag "Set ShowSearchNavigation to false and confirm we do not load navigation links.";
+{
+ RT::Test->stop_server;
+ RT->Config->Set( 'ShowSearchNavigation' => 0 );
+ ($baseurl, $m) = RT::Test->started_ok;
+
+ # Get a search that returns multiple tickets
+ $m->get_ok("/Search/Results.html?Format=id,RefersTo;Query=id>0");
+
+ ok $m->goto_ticket( $ticket->Id ), 'opened diplay page of ticket # '.$ticket->Id;
+ $t_link = $m->find_link( id => "search-tickets-next" );
+ is($t_link, undef, "Search navigation results are not rendered");
+}
done_testing;
commit a3a4b83756e73763cd7277753070c2d4a4c13ce4
Author: craig kaiser <craig at bestpractical.com>
Date: Fri Aug 28 12:34:53 2020 -0400
Allow ShowSearchResultsNavInMenu to be user level overridable
diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 431a12ca22..5a874dc823 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -1222,6 +1222,16 @@ our %META;
ServiceAgreements => {
Type => 'HASH',
},
+
+ ShowSearchNavigation => {
+ Section => 'Ticket display',
+ Overridable => 1,
+ Widget => '/Widgets/Form/Boolean',
+ WidgetArguments => {
+ Description => 'Build search results navigation menu items', # loc
+ Hints => '( First, Last, Prev, Next )'
+ }
+ }
);
my %OPTIONS = ();
my @LOADED_CONFIGS = ();
diff --git a/share/html/Elements/Tabs b/share/html/Elements/Tabs
index 03cce37d08..106e38fe08 100644
--- a/share/html/Elements/Tabs
+++ b/share/html/Elements/Tabs
@@ -861,7 +861,7 @@ my $build_main_nav = sub {
path => "/Articles/Article/ExtractIntoClass.html?Ticket=".$obj->id,
) if $session{CurrentUser}->HasRight( Right => 'ShowArticlesMenu', Object => RT->System );
- if ( RT::Config->Get( 'ShowSearchNavigation' ) ) {
+ if ( RT::Config->Get( 'ShowSearchNavigation', $session{'CurrentUser'} ) ) {
if ( defined $session{"tickets"} ) {
# we have to update session data if we get new ItemMap
my $updatesession = 1 unless ( $session{"tickets"}->{'item_map'} );
diff --git a/share/html/Ticket/Display.html b/share/html/Ticket/Display.html
index 1f3284c3e6..bf64200bf0 100644
--- a/share/html/Ticket/Display.html
+++ b/share/html/Ticket/Display.html
@@ -240,7 +240,7 @@ my $attachments = $TicketObj->Attachments;
my $attachment_content = $TicketObj->TextAttachments;
my %link_rel;
-if (RT::Config->Get( 'ShowSearchNavigation' ) && defined $session{'tickets'} and ($ARGS{'Query'} or $session{'CurrentSearchHash'}->{'Query'})) {
+if (RT::Config->Get( 'ShowSearchNavigation', $session{'CurrentUser'} ) && defined $session{'tickets'} and ($ARGS{'Query'} or $session{'CurrentSearchHash'}->{'Query'})) {
my $item_map = $session{'tickets'}->ItemMap;
$link_rel{first} = "/Ticket/Display.html?id=" . $item_map->{first} if $item_map->{$TicketObj->Id}{prev};
$link_rel{prev} = "/Ticket/Display.html?id=" . $item_map->{$TicketObj->Id}{prev} if $item_map->{$TicketObj->Id}{prev};
commit 83260d193ccf6a1460598ce5164842f85d958d75
Author: craig kaiser <craig at bestpractical.com>
Date: Fri Aug 28 12:57:17 2020 -0400
Add tests for setting user pref of 'ShowSearchNavigation'
diff --git a/t/web/search_linkdisplay.t b/t/web/search_linkdisplay.t
index d0a6d7ef3d..3bb3ea312e 100644
--- a/t/web/search_linkdisplay.t
+++ b/t/web/search_linkdisplay.t
@@ -80,4 +80,28 @@ diag "Set ShowSearchNavigation to false and confirm we do not load navigation li
$t_link = $m->find_link( id => "search-tickets-next" );
is($t_link, undef, "Search navigation results are not rendered");
}
+
+diag "Override ShowSearchNavigation at user pref level.";
+{
+ ok( $m->login( 'root', 'password' ), 'logged in as root' );
+
+ my $root = RT::User->new(RT->SystemUser);
+ $root->Load( 'root' );
+ ok ( $root->Id, "Loaded root user" );
+
+ $root->SetPreferences( $RT::System => { %{ $root->Preferences( $RT::System ) || {}}, ShowSearchNavigation => 1 });
+
+ is( RT::Config->Get( 'ShowSearchNavigation', $root ), 1, "User pref for ShowSearchNavigation successfully set.");
+
+ $m->get_ok("/Search/Results.html?Format=id,RefersTo;Query=id>0");
+
+ ok $m->goto_ticket( $ticket->Id ), 'opened diplay page of ticket # '.$ticket->Id;
+ my $t_link = $m->find_link( id => "search-tickets-next" )->url;
+ is ($t_link, "/Ticket/Display.html?id=".$ticket2->Id, 'link to the next ticket in current search found');
+
+
+ $root->SetPreferences( $RT::System => { %{ $root->Preferences( $RT::System ) || {}}, ShowSearchNavigation => 0 });
+ is( RT::Config->Get( 'ShowSearchNavigation', $root ), 0, "User pref for ShowSearchNavigation successfully set.");
+}
+
done_testing;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list