From: Kohei Yoshino Date: Thu, 31 Jan 2019 00:57:33 +0000 (-0500) Subject: Bug 1523317 - Exclude Graveyard products from QuickSearch results X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=840a3cc185b401900185fb3248c6ceca9af7b1d9;p=thirdparty%2Fbugzilla.git Bug 1523317 - Exclude Graveyard products from QuickSearch results --- diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm index 18335b907..d4ee572b3 100644 --- a/Bugzilla/Hook.pm +++ b/Bugzilla/Hook.pm @@ -1417,6 +1417,41 @@ want it to map to. You can modify existing mappings or add new ones. =back +=head2 quicksearch_run + +This hook allows you to alter the QuickSearch params, so you can, for example, +include specific bug status or exclude specific products in search results +by default. + +Params: + +=over + +=item C - The current C object. The search params can be altered +using C<< $cgi->param(field, value) >>. + +=item C - A boolean indicating whether the status and/or +resolution is specified in the search query entered by user. + +=item C - A boolean indicating whether the classification, +product and/or component is specified in the search query entered by user. + +=back + +=head2 quicksearch_test + +This hook allows you to alter the QuickSearch params in the test. This has to +correspond with the C hook described above. + +Params: + +=over + +=item C - A hash of the test options containing C, which has to be +altered in the same way as C. + +=back + =head2 sanitycheck_check This hook allows for extra sanity checks to be added, for use by diff --git a/Bugzilla/Search/Quicksearch.pm b/Bugzilla/Search/Quicksearch.pm index f2bb83e2e..3df71f29c 100644 --- a/Bugzilla/Search/Quicksearch.pm +++ b/Bugzilla/Search/Quicksearch.pm @@ -127,7 +127,7 @@ use constant COMPONENT_EXCEPTIONS => ( ); # Quicksearch-wide globals for boolean charts. -our ($chart, $and, $or, $fulltext, $bug_status_set, $ELASTIC); +our ($chart, $and, $or, $fulltext, $bug_status_set, $bug_product_set, $ELASTIC); sub quicksearch { my ($searchstring) = (@_); @@ -253,6 +253,16 @@ sub quicksearch { $cgi->param('bug_status', BUG_STATE_OPEN); } + # Provide a hook to allow modifying the params + Bugzilla::Hook::process( + 'quicksearch_run', + { + 'cgi' => $cgi, + 'bug_status_set' => $bug_status_set, + 'bug_product_set' => $bug_product_set, + } + ); + # Inform user about any unknown fields if (scalar(@unknownFields) || scalar(keys %ambiguous_fields)) { ThrowUserError( @@ -477,6 +487,9 @@ sub _handle_field_names { if ($translated eq 'bug_status' || $translated eq 'resolution') { $bug_status_set = 1; } + if ($translated =~ /^(?:classification|product|component)$/) { + $bug_product_set = 1; + } foreach my $value (@values) { next unless defined $value; my $operator diff --git a/extensions/BMO/Extension.pm b/extensions/BMO/Extension.pm index d19d9e4db..efddc7385 100644 --- a/extensions/BMO/Extension.pm +++ b/extensions/BMO/Extension.pm @@ -873,6 +873,27 @@ sub quicksearch_map { } } +sub quicksearch_run { + my ($self, $args) = @_; + my ($cgi, $bug_product_set) = @$args{qw(cgi bug_product_set)}; + + # Exclude Graveyard products by default + unless ($bug_product_set) { + $cgi->param('f1', 'classification'); + $cgi->param('o1', 'notequals'); + $cgi->param('v1', 'Graveyard'); + } +} + +sub quicksearch_test { + my ($self, $args) = @_; + my $opt = $args->{'opt'}; + + $opt->{params}->{'f1'} = 'classification'; + $opt->{params}->{'o1'} = 'notequals'; + $opt->{params}->{'v1'} = 'Graveyard'; +} + sub object_columns { my ($self, $args) = @_; return unless $args->{class}->isa('Bugzilla::Product'); diff --git a/extensions/TrackingFlags/Extension.pm b/extensions/TrackingFlags/Extension.pm index 22c07f955..58a889e98 100644 --- a/extensions/TrackingFlags/Extension.pm +++ b/extensions/TrackingFlags/Extension.pm @@ -353,7 +353,7 @@ sub buglist_column_joins { # if there are elements in the tracking_flags array, then they have been # removed from the query, so we mustn't generate joins - return if scalar @{$args->{search}->{tracking_flags}}; + return if scalar @{$args->{search}->{tracking_flags} || []}; my $column_joins = $args->{'column_joins'}; my @tracking_flags = Bugzilla::Extension::TrackingFlags::Flag->get_all; diff --git a/t/quicksearch.t b/t/quicksearch.t index 0c244aa54..e79b476eb 100644 --- a/t/quicksearch.t +++ b/t/quicksearch.t @@ -13,6 +13,7 @@ use Bugzilla::Test::MockDB; use Bugzilla::Test::MockParams (password_complexity => 'no_constraints'); use Bugzilla; use Bugzilla::Constants; +use Bugzilla::Hook; BEGIN { Bugzilla->extensions } use Test2::V0; use Test2::Tools::Mock qw(mock mock_accessor); @@ -122,6 +123,10 @@ sub test_quicksearch { } } + # Provide a hook to allow modifying the params. This has to correspond with + # the `quicksearch_run` hook + Bugzilla::Hook::process('quicksearch_test', { 'opt' => \%opt }); + is($vars, $opt{params}, "test params: $opt{input}"); if (my $sql = $opt{sql_like}) { my $search = Bugzilla::Search->new(params => $vars);