From 71ef35b5330d80e8f5d4bdc99f62aea3fadb22c5 Mon Sep 17 00:00:00 2001 From: Israel Madueme Date: Tue, 10 Apr 2018 17:45:59 -0400 Subject: Bug 1421110 - Add REST API endpoint for /bug/possible_duplicates --- Bugzilla/WebService/Bug.pm | 43 +++++++++++++++++++++--- Bugzilla/WebService/Server/REST/Resources/Bug.pm | 5 +++ 2 files changed, 43 insertions(+), 5 deletions(-) (limited to 'Bugzilla/WebService') diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm index c07454d7d..feb541c2e 100644 --- a/Bugzilla/WebService/Bug.pm +++ b/Bugzilla/WebService/Bug.pm @@ -35,6 +35,8 @@ use Bugzilla::Search::Quicksearch; use List::Util qw(max); use List::MoreUtils qw(uniq); use Storable qw(dclone); +use Types::Standard -all; +use Type::Utils; ############# # Constants # @@ -656,9 +658,30 @@ sub possible_duplicates { Bugzilla->switch_to_shadow_db(); - # Undo the array-ification that validate() does, for "summary". - $params->{summary} || ThrowCodeError('param_required', - { function => 'Bug.possible_duplicates', param => 'summary' }); + state $params_type = Dict [ + id => Optional [Int], + product => Optional [ ArrayRef [Str] ], + limit => Optional [Int], + summary => Optional [Str], + include_fields => Optional [ ArrayRef [Str] ], + Bugzilla_api_token => Optional [Str] + ]; + + ThrowCodeError( 'param_invalid', { function => 'Bug.possible_duplicates', param => 'A param' } ) + if !$params_type->check($params); + + my $summary; + if ($params->{id}) { + my $bug = Bugzilla::Bug->check({ id => $params->{id}, cache => 1 }); + $summary = $bug->short_desc; + } + elsif ($params->{summary}) { + $summary = $params->{summary}; + } + else { + ThrowCodeError('param_required', + { function => 'Bug.possible_duplicates', param => 'id or summary' }); + } my @products; foreach my $name (@{ $params->{'product'} || [] }) { @@ -667,8 +690,18 @@ sub possible_duplicates { } my $possible_dupes = Bugzilla::Bug->possible_duplicates( - { summary => $params->{summary}, products => \@products, - limit => $params->{limit} }); + { + summary => $summary, + products => \@products, + limit => $params->{limit} + } + ); + + # If a bug id was used, remove the bug with the same id from the list. + if ($params->{id}) { + @$possible_dupes = grep { $_->id != $params->{id} } @$possible_dupes; + } + my @hashes = map { $self->_bug_to_hash($_, $params) } @$possible_dupes; $self->_add_update_tokens($params, $possible_dupes, \@hashes); return { bugs => \@hashes }; diff --git a/Bugzilla/WebService/Server/REST/Resources/Bug.pm b/Bugzilla/WebService/Server/REST/Resources/Bug.pm index 33cf43321..26aec011c 100644 --- a/Bugzilla/WebService/Server/REST/Resources/Bug.pm +++ b/Bugzilla/WebService/Server/REST/Resources/Bug.pm @@ -34,6 +34,11 @@ sub _rest_resources { method => 'get' } }, + qr{^/bug/possible_duplicates$}, { + GET => { + method => 'possible_duplicates' + } + }, qr{^/bug/([^/]+)$}, { GET => { method => 'get', -- cgit v1.2.3-24-g4f1b From ff60b109bcd1a83f79b45296a9bc679ad9fd1f6b Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Wed, 23 May 2018 09:10:55 -0400 Subject: Bug 1461400 - Log errors in webservices when undef values are passed to $self->type() --- Bugzilla/WebService/Server/XMLRPC.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'Bugzilla/WebService') diff --git a/Bugzilla/WebService/Server/XMLRPC.pm b/Bugzilla/WebService/Server/XMLRPC.pm index fce865e88..6bb73af01 100644 --- a/Bugzilla/WebService/Server/XMLRPC.pm +++ b/Bugzilla/WebService/Server/XMLRPC.pm @@ -11,6 +11,7 @@ use 5.10.1; use strict; use warnings; +use Bugzilla::Logging; use XMLRPC::Transport::HTTP; use Bugzilla::WebService::Server; if ($ENV{MOD_PERL}) { @@ -32,8 +33,15 @@ BEGIN { if ($type eq 'dateTime') { # This is the XML-RPC implementation, see the README in Bugzilla/WebService/. # Our "base" implementation is in Bugzilla::WebService::Server. - $value = Bugzilla::WebService::Server->datetime_format_outbound($value); - $value =~ s/-//g; + if (defined $value) { + $value = Bugzilla::WebService::Server->datetime_format_outbound($value); + $value =~ s/-//g; + } + else { + my ($pkg, $file, $line) = caller; + my $class = ref $self; + ERROR("$class->type($type, undef) called from $pkg ($file line $line)"); + } } elsif ($type eq 'email') { $type = 'string'; -- cgit v1.2.3-24-g4f1b From d5f2d8158b90a55cefe126e38132e390e9fa75f5 Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Thu, 28 Jun 2018 23:26:52 -0400 Subject: Bug 1472048 - Remove Metrics Code --- Bugzilla/WebService/Server.pm | 5 ----- 1 file changed, 5 deletions(-) (limited to 'Bugzilla/WebService') diff --git a/Bugzilla/WebService/Server.pm b/Bugzilla/WebService/Server.pm index ba9847abc..a76c4c48c 100644 --- a/Bugzilla/WebService/Server.pm +++ b/Bugzilla/WebService/Server.pm @@ -23,11 +23,6 @@ sub handle_login { # Throw error if the supplied class does not exist or the method is private ThrowCodeError('unknown_method', {method => $full_method}) if (!$class or $method =~ /^_/); - # BMO - use the class and method as the name, instead of the cgi filename - if (Bugzilla->metrics_enabled) { - Bugzilla->metrics->name("$class $method"); - } - # We never want to create a new session unless the user is calling the # login method. Setting dont_persist_session makes # Bugzilla::Auth::_handle_login_result() skip calling persist_login(). -- cgit v1.2.3-24-g4f1b