summaryrefslogtreecommitdiffstats
path: root/Bugzilla/WebService
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2017-03-07 23:47:36 +0100
committerDylan William Hardison <dylan@hardison.net>2017-05-24 20:24:54 +0200
commit50fc9d77128db4f8565265047166c6ef61bac5c5 (patch)
treeeadc23eeaca476412e36c63161f5a2e4ab96aabd /Bugzilla/WebService
parent0ea91b298e8fc1c439f42c9288247e9223ce552e (diff)
downloadbugzilla-50fc9d77128db4f8565265047166c6ef61bac5c5.tar.gz
bugzilla-50fc9d77128db4f8565265047166c6ef61bac5c5.tar.xz
Bug 1307485 - Add code to run a subset of buglist.cgi search queries against the ES backend
Diffstat (limited to 'Bugzilla/WebService')
-rw-r--r--Bugzilla/WebService/Constants.pm1
-rw-r--r--Bugzilla/WebService/Elastic.pm59
-rw-r--r--Bugzilla/WebService/Server/REST.pm1
-rw-r--r--Bugzilla/WebService/Server/REST/Resources/Elastic.pm30
4 files changed, 91 insertions, 0 deletions
diff --git a/Bugzilla/WebService/Constants.pm b/Bugzilla/WebService/Constants.pm
index bf3a93fd5..1399513c5 100644
--- a/Bugzilla/WebService/Constants.pm
+++ b/Bugzilla/WebService/Constants.pm
@@ -290,6 +290,7 @@ sub WS_DISPATCH {
'Product' => 'Bugzilla::WebService::Product',
'Group' => 'Bugzilla::WebService::Group',
'BugUserLastVisit' => 'Bugzilla::WebService::BugUserLastVisit',
+ 'Elastic' => 'Bugzilla::WebService::Elastic',
%hook_dispatch
};
return $dispatch;
diff --git a/Bugzilla/WebService/Elastic.pm b/Bugzilla/WebService/Elastic.pm
new file mode 100644
index 000000000..3a33a1dba
--- /dev/null
+++ b/Bugzilla/WebService/Elastic.pm
@@ -0,0 +1,59 @@
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# The Original Code is the Bugzilla Bug Tracking System.
+#
+# Contributor(s): Marc Schumann <wurblzap@gmail.com>
+# Max Kanat-Alexander <mkanat@bugzilla.org>
+# Mads Bondo Dydensborg <mbd@dbc.dk>
+# Noura Elhawary <nelhawar@redhat.com>
+
+package Bugzilla::WebService::Elastic;
+
+use 5.10.1;
+use strict;
+use warnings;
+use base qw(Bugzilla::WebService);
+
+use Bugzilla;
+use Bugzilla::Constants;
+use Bugzilla::Error;
+use Bugzilla::WebService::Util qw(validate);
+use Bugzilla::Util qw(trim detaint_natural trick_taint);
+
+use constant READ_ONLY => qw( suggest_users );
+use constant PUBLIC_METHODS => qw( suggest_users );
+
+sub suggest_users {
+ my ($self, $params) = @_;
+
+ Bugzilla->switch_to_shadow_db();
+
+ ThrowCodeError('params_required', { function => 'Elastic.suggest_users', params => ['match'] })
+ unless defined $params->{match};
+
+ ThrowUserError('user_access_by_match_denied')
+ unless Bugzilla->user->id;
+
+ trick_taint($params->{match});
+ my $results = Bugzilla->elastic->suggest_users($params->{match} . "");
+ my @users = map {
+ {
+ real_name => $self->type(string => $_->{real_name}),
+ name => $self->type(email => $_->{name}),
+ }
+ } @$results;
+
+ return { users => \@users };
+}
+
+1; \ No newline at end of file
diff --git a/Bugzilla/WebService/Server/REST.pm b/Bugzilla/WebService/Server/REST.pm
index d9381b2c8..6e1944061 100644
--- a/Bugzilla/WebService/Server/REST.pm
+++ b/Bugzilla/WebService/Server/REST.pm
@@ -29,6 +29,7 @@ use Bugzilla::WebService::Server::REST::Resources::Group;
use Bugzilla::WebService::Server::REST::Resources::Product;
use Bugzilla::WebService::Server::REST::Resources::User;
use Bugzilla::WebService::Server::REST::Resources::BugUserLastVisit;
+use Bugzilla::WebService::Server::REST::Resources::Elastic;
use List::MoreUtils qw(uniq);
use Scalar::Util qw(blessed reftype);
diff --git a/Bugzilla/WebService/Server/REST/Resources/Elastic.pm b/Bugzilla/WebService/Server/REST/Resources/Elastic.pm
new file mode 100644
index 000000000..2f7c1eaa4
--- /dev/null
+++ b/Bugzilla/WebService/Server/REST/Resources/Elastic.pm
@@ -0,0 +1,30 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+
+package Bugzilla::WebService::Server::REST::Resources::Elastic;
+
+use 5.10.1;
+use strict;
+use warnings;
+
+use Bugzilla::WebService::Constants;
+use Bugzilla::WebService::Elastic;
+
+BEGIN {
+ *Bugzilla::WebService::Elastic::rest_resources = \&_rest_resources;
+};
+
+sub _rest_resources {
+ my $rest_resources = [
+ qr{^/elastic/suggest_users$}, {
+ GET => { method => 'suggest_users' },
+ },
+ ];
+ return $rest_resources;
+}
+
+1;