From 9c26c01867ca3e2af1e70c051140eea59c68c500 Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Tue, 7 Mar 2017 17:47:36 -0500 Subject: Bug 1307485 - Add code to run a subset of buglist.cgi search queries against the ES backend --- Bugzilla/WebService/Constants.pm | 1 + Bugzilla/WebService/Elastic.pm | 59 ++++++++++++++++++++++ Bugzilla/WebService/Server/REST.pm | 1 + .../WebService/Server/REST/Resources/Elastic.pm | 30 +++++++++++ 4 files changed, 91 insertions(+) create mode 100644 Bugzilla/WebService/Elastic.pm create mode 100644 Bugzilla/WebService/Server/REST/Resources/Elastic.pm (limited to 'Bugzilla/WebService') 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 +# Max Kanat-Alexander +# Mads Bondo Dydensborg +# Noura Elhawary + +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; -- cgit v1.2.3-24-g4f1b