Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 10 additions & 24 deletions Bugzilla/WebService/Constants.pm → Bugzilla/API/V1/Constants.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

package Bugzilla::WebService::Constants;
package Bugzilla::API::V1::Constants;

use 5.10.1;
use strict;
Expand All @@ -16,14 +16,10 @@ use base qw(Exporter);
our @EXPORT = qw(
WS_ERROR_CODE

STATUS_OK
STATUS_CREATED
STATUS_ACCEPTED
STATUS_NO_CONTENT
STATUS_MULTIPLE_CHOICES
STATUS_BAD_REQUEST
STATUS_NOT_AUTHORIZED
STATUS_NOT_FOUND
STATUS_GONE
STATUS_REQUEST_TOO_LARGE
REST_STATUS_CODE_MAP

ERROR_UNKNOWN_FATAL
Expand All @@ -37,9 +33,8 @@ our @EXPORT = qw(
# fatal errors should have a number below 0.
#
# This hash should generally contain any error that could be thrown
# by the WebService interface. If it's extremely unlikely that the
# error could be thrown (like some CodeErrors), it doesn't have to
# be listed here.
# by the API. If it's extremely unlikely that the error could be thrown
# (like some CodeErrors), it doesn't have to be listed here.
#
# "Transient" means "If you resubmit that request with different data,
# it may work."
Expand Down Expand Up @@ -231,24 +226,17 @@ use constant WS_ERROR_CODE => {
# Job queue errors 1400-1500
jobqueue_status_error => 1400,

# Errors thrown by the WebService itself. The ones that are negative
# conform to http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
# Errors thrown by the API layer itself.
unknown_method => -32601,
rest_invalid_resource => 32614,
};

# RESTful webservices use the HTTP status code
# to describe whether a call was successful or
# to describe the type of error that occurred.
use constant STATUS_OK => 200;
use constant STATUS_CREATED => 201;
use constant STATUS_ACCEPTED => 202;
use constant STATUS_NO_CONTENT => 204;
use constant STATUS_MULTIPLE_CHOICES => 300;
use constant STATUS_BAD_REQUEST => 400;
use constant STATUS_NOT_AUTHORIZED => 401;
use constant STATUS_NOT_FOUND => 404;
use constant STATUS_GONE => 410;
use constant STATUS_BAD_REQUEST => 400;
use constant STATUS_NOT_AUTHORIZED => 401;
use constant STATUS_NOT_FOUND => 404;
use constant STATUS_REQUEST_TOO_LARGE => 413;

# The integer value is the error code above returned by
Expand Down Expand Up @@ -285,12 +273,10 @@ sub REST_STATUS_CODE_MAP {
return $status_code_map;
}

# These are the fallback defaults for errors not in ERROR_CODE.
# These are the fallback defaults for errors not in WS_ERROR_CODE.
use constant ERROR_UNKNOWN_FATAL => -32000;
use constant ERROR_UNKNOWN_TRANSIENT => 32000;

use constant ERROR_GENERAL => 999;

# Custom HTTP headers that can be used for API authentication rather than
# passing as URL parameters. This is useful if you do not want sensitive
# information to show up in webserver log files.
Expand Down
10 changes: 5 additions & 5 deletions Bugzilla/API/V1/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use Bugzilla;
use Bugzilla::Error;
use Bugzilla::Logging;
use Bugzilla::Util qw(datetime_from email_filter truncate_string);
use Bugzilla::WebService::Constants;
use Bugzilla::WebService::Wants;
use Bugzilla::API::V1::Constants;
use Bugzilla::API::V1::Wants;

use MIME::Base64 qw(encode_base64);
use PerlX::Maybe qw(maybe);
Expand Down Expand Up @@ -379,12 +379,12 @@ sub datetime_format_inbound {
}

# The include_fields/exclude_fields of the request as a
# Bugzilla::WebService::Wants object, built once per request.
# Bugzilla::API::V1::Wants object, built once per request.
sub wants_object {
my $cache = Bugzilla->request_cache;
return $cache->{filter_wants_object} //= do {
my $params = Bugzilla->input_params;
Bugzilla::WebService::Wants->new(
Bugzilla::API::V1::Wants->new(
cache => $cache->{filter_wants} ||= {},
maybe include_fields => $params->{include_fields},
maybe exclude_fields => $params->{exclude_fields},
Expand Down Expand Up @@ -746,5 +746,5 @@ can't be parsed.

=head2 wants_object

Returns a L<Bugzilla::WebService::Wants> object for the C<include_fields> and
Returns a L<Bugzilla::API::V1::Wants> object for the C<include_fields> and
C<exclude_fields> of the current request, built once per request.
2 changes: 1 addition & 1 deletion Bugzilla/WebService/Wants.pm → Bugzilla/API/V1/Wants.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

package Bugzilla::WebService::Wants;
package Bugzilla::API::V1::Wants;
use 5.10.1;
use Moo;
use MooX::StrictConstructor;
Expand Down
2 changes: 1 addition & 1 deletion Bugzilla/App/Plugin/Error.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use Mojo::Base 'Mojolicious::Plugin';

use Bugzilla::Constants;
use Bugzilla::Logging;
use Bugzilla::WebService::Constants;
use Bugzilla::API::V1::Constants;

my $EXCEPTION_HELPER;

Expand Down
1 change: 0 additions & 1 deletion Bugzilla/Auth/Login/CGI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use constant user_can_create_account => 1;
use constant auth_method => 'CGI';

use Bugzilla::Constants;
use Bugzilla::WebService::Constants;
use Bugzilla::Util;
use Bugzilla::Error;
use Bugzilla::Token;
Expand Down
6 changes: 3 additions & 3 deletions Bugzilla/Hook.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1734,7 +1734,7 @@ Params:
=item C<error_map>

A hash that maps the names of errors (like C<invalid_param>) to numbers.
See L<Bugzilla::WebService::Constants/WS_ERROR_CODE> for an example.
See L<Bugzilla::API::V1::Constants/WS_ERROR_CODE> for an example.

=back

Expand All @@ -1743,9 +1743,9 @@ See L<Bugzilla::WebService::Constants/WS_ERROR_CODE> for an example.
This hook allows an extension to change the status codes returned by
specific webservice errors. The valid internal error codes that Bugzilla
generates, and the status codes they map to by default, are defined in the
C<WS_ERROR_CODE> constant in C<Bugzilla::WebService::Constants>. When
C<WS_ERROR_CODE> constant in C<Bugzilla::API::V1::Constants>. When
remapping an error, you may wish to use an existing status code constant.
Such constants are also in C<Bugzilla::WebService::Constants> and start
Such constants are also in C<Bugzilla::API::V1::Constants> and start
with C<STATUS_*> such as C<STATUS_BAD_REQUEST>.

Params:
Expand Down
2 changes: 1 addition & 1 deletion extensions/Example/Extension.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use Bugzilla::User::Setting;
use Bugzilla::Util qw(diff_arrays html_quote);
use Bugzilla::Status qw(is_open_state);
use Bugzilla::Install::Filesystem;
use Bugzilla::WebService::Constants;
use Bugzilla::API::V1::Constants;

# This is extensions/Example/lib/Util.pm. I can load this here in my
# Extension.pm only because I have a Config.pm.
Expand Down
4 changes: 2 additions & 2 deletions t/012throwables.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use warnings;
use lib qw(. lib local/lib/perl5 t);

use Bugzilla::Constants;
use Bugzilla::WebService::Constants;
use Bugzilla::API::V1::Constants;

use File::Spec;
use Support::Files;
Expand Down Expand Up @@ -169,7 +169,7 @@ foreach my $err_name (keys %{WS_ERROR_CODE()}) {
{
Register(\%test_modules, 'WS_ERROR_CODE',
"Error tag '$err_name' is used in WS_ERROR_CODE in"
. " Bugzilla/WebService/Constants.pm"
. " Bugzilla/API/V1/Constants.pm"
. " but not defined in any template, and not used in any code.");
}
}
Expand Down
16 changes: 8 additions & 8 deletions t/wants.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ use warnings;
use lib qw( . lib local/lib/perl5 );

use Test2::V0;
use ok 'Bugzilla::WebService::Wants';
use ok 'Bugzilla::API::V1::Wants';

my $empty = Bugzilla::WebService::Wants->new(cache => {});
my $empty = Bugzilla::API::V1::Wants->new(cache => {});
ok($empty->is_empty, "it is empty");
ok(!$empty->is_specific, "no include/exclude is not specific");

my $non_empty_i
= Bugzilla::WebService::Wants->new(include_fields => ['foo'], cache => {});
= Bugzilla::API::V1::Wants->new(include_fields => ['foo'], cache => {});
ok(!($non_empty_i->is_empty), "it is not empty with includes");

my $non_empty_e
= Bugzilla::WebService::Wants->new(exclude_fields => ['foo'], cache => {});
= Bugzilla::API::V1::Wants->new(exclude_fields => ['foo'], cache => {});
ok(!($non_empty_e->is_empty), "it is not empty with excludes");

my $wants = Bugzilla::WebService::Wants->new(
my $wants = Bugzilla::API::V1::Wants->new(
exclude_fields => ['_extra'],
include_fields => ['_custom', '_default'],
cache => {}
Expand All @@ -36,15 +36,15 @@ ok(!$wants->match('triage_owner_id', ['extra']), 'triage owner is extra');
ok($wants->exclude_type->{extra}, "extra is excluded");
ok($wants->include_type->{custom}, "custom is included");

$wants = Bugzilla::WebService::Wants->new(
$wants = Bugzilla::API::V1::Wants->new(
exclude_fields => ['_custom'],
include_fields => ['cf_test'],
cache => {},
);

ok($wants->match('cf_test', ['default', 'custom']), "excludes are more specific");

$wants = Bugzilla::WebService::Wants->new(
$wants = Bugzilla::API::V1::Wants->new(
exclude_fields => ['_default'],
include_fields => ['cf_test'],
cache => {},
Expand All @@ -55,7 +55,7 @@ ok($wants->match('cf_test', ['default', 'custom']), "excludes are more specific"

is([ $wants->includes ], ['cf_test']);

$wants = Bugzilla::WebService::Wants->new(
$wants = Bugzilla::API::V1::Wants->new(
exclude_fields => ['cf_evil'],
include_fields => ['cf_test'],
cache => {},
Expand Down