]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1523317 - Exclude Graveyard products from QuickSearch results
authorKohei Yoshino <kohei.yoshino@gmail.com>
Thu, 31 Jan 2019 00:57:33 +0000 (19:57 -0500)
committerGitHub <noreply@github.com>
Thu, 31 Jan 2019 00:57:33 +0000 (19:57 -0500)
Bugzilla/Hook.pm
Bugzilla/Search/Quicksearch.pm
extensions/BMO/Extension.pm
extensions/TrackingFlags/Extension.pm
t/quicksearch.t

index 18335b90782528e79d3f6a761cba2a1405cf1f93..d4ee572b3a9e6a8dd50bf634a1a7da7bf75d42e2 100644 (file)
@@ -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<cgi> - The current C<cgi> object. The search params can be altered
+using C<< $cgi->param(field, value) >>.
+
+=item C<bug_status_set> - A boolean indicating whether the status and/or
+resolution is specified in the search query entered by user.
+
+=item C<bug_product_set> - 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<quicksearch_run> hook described above.
+
+Params:
+
+=over
+
+=item C<opt> - A hash of the test options containing C<params>, which has to be
+altered in the same way as C<quicksearch_run>.
+
+=back
+
 =head2 sanitycheck_check
 
 This hook allows for extra sanity checks to be added, for use by
index f2bb83e2e284b99fa8bad87f130e19a4a2b0d90f..3df71f29ca64a058a113ceca990d0a4ddb3cc3ab 100644 (file)
@@ -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
index d19d9e4db61f8b480da9e70eed7f61533d706adc..efddc738537d56c0c35fbede4193374448df3d1f 100644 (file)
@@ -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');
index 22c07f955dad06f28c9780bfd6dc46c6d0b010ea..58a889e981427e0c82197589262e038191c9290b 100644 (file)
@@ -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;
index 0c244aa540a9fe6279633a6ea36ccf6d73c32f51..e79b476ebcd849b870d8da18d414bd463c78e363 100644 (file)
@@ -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);