From 80a71e47fc676b5a8f741db714395a733ca41d8a Mon Sep 17 00:00:00 2001 From: Xavier L'Hour Date: Mon, 30 Nov 2026 17:18:14 +0100 Subject: [PATCH 1/2] Bug 2099197 - Move Bugzilla::WebService::Constants and Bugzilla::WebService::Wants to Bugzilla::API::V1 - Rename the packages and update their callers, tests and POD - Drop the import of the constants in Bugzilla::Auth::Login::CGI, which uses none of them - Remove the constants nothing uses anymore: STATUS_OK, STATUS_CREATED, STATUS_ACCEPTED, STATUS_NO_CONTENT, STATUS_MULTIPLE_CHOICES, STATUS_GONE and ERROR_GENERAL --- Bugzilla/{WebService => API/V1}/Constants.pm | 22 ++++---------------- Bugzilla/API/V1/Util.pm | 10 ++++----- Bugzilla/{WebService => API/V1}/Wants.pm | 2 +- Bugzilla/App/Plugin/Error.pm | 2 +- Bugzilla/Auth/Login/CGI.pm | 1 - Bugzilla/Hook.pm | 6 +++--- extensions/Example/Extension.pm | 2 +- t/012throwables.t | 4 ++-- t/wants.t | 16 +++++++------- 9 files changed, 25 insertions(+), 40 deletions(-) rename Bugzilla/{WebService => API/V1}/Constants.pm (93%) rename Bugzilla/{WebService => API/V1}/Wants.pm (98%) diff --git a/Bugzilla/WebService/Constants.pm b/Bugzilla/API/V1/Constants.pm similarity index 93% rename from Bugzilla/WebService/Constants.pm rename to Bugzilla/API/V1/Constants.pm index a7e44df2ac..cc47c3aa15 100644 --- a/Bugzilla/WebService/Constants.pm +++ b/Bugzilla/API/V1/Constants.pm @@ -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; @@ -16,14 +16,8 @@ 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_FOUND - STATUS_GONE REST_STATUS_CODE_MAP ERROR_UNKNOWN_FATAL @@ -240,15 +234,9 @@ use constant WS_ERROR_CODE => { # 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 @@ -289,8 +277,6 @@ sub REST_STATUS_CODE_MAP { 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. diff --git a/Bugzilla/API/V1/Util.pm b/Bugzilla/API/V1/Util.pm index d81fabb89c..a350068b2b 100644 --- a/Bugzilla/API/V1/Util.pm +++ b/Bugzilla/API/V1/Util.pm @@ -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); @@ -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}, @@ -746,5 +746,5 @@ can't be parsed. =head2 wants_object -Returns a L object for the C and +Returns a L object for the C and C of the current request, built once per request. diff --git a/Bugzilla/WebService/Wants.pm b/Bugzilla/API/V1/Wants.pm similarity index 98% rename from Bugzilla/WebService/Wants.pm rename to Bugzilla/API/V1/Wants.pm index 08d62253de..5f3856c246 100644 --- a/Bugzilla/WebService/Wants.pm +++ b/Bugzilla/API/V1/Wants.pm @@ -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; diff --git a/Bugzilla/App/Plugin/Error.pm b/Bugzilla/App/Plugin/Error.pm index 03b7ab778f..774aa9c1da 100644 --- a/Bugzilla/App/Plugin/Error.pm +++ b/Bugzilla/App/Plugin/Error.pm @@ -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; diff --git a/Bugzilla/Auth/Login/CGI.pm b/Bugzilla/Auth/Login/CGI.pm index 3cf6b89414..b4e6113639 100644 --- a/Bugzilla/Auth/Login/CGI.pm +++ b/Bugzilla/Auth/Login/CGI.pm @@ -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; diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm index b9dc2b1e5c..3d3d54b1e6 100644 --- a/Bugzilla/Hook.pm +++ b/Bugzilla/Hook.pm @@ -1734,7 +1734,7 @@ Params: =item C A hash that maps the names of errors (like C) to numbers. -See L for an example. +See L for an example. =back @@ -1743,9 +1743,9 @@ See L 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 constant in C. When +C constant in C. When remapping an error, you may wish to use an existing status code constant. -Such constants are also in C and start +Such constants are also in C and start with C such as C. Params: diff --git a/extensions/Example/Extension.pm b/extensions/Example/Extension.pm index 200030cb26..4711650ff7 100644 --- a/extensions/Example/Extension.pm +++ b/extensions/Example/Extension.pm @@ -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. diff --git a/t/012throwables.t b/t/012throwables.t index 4a5d9e0a58..006ba8b029 100644 --- a/t/012throwables.t +++ b/t/012throwables.t @@ -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; @@ -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."); } } diff --git a/t/wants.t b/t/wants.t index 3413e8d99f..52fdec3b5c 100644 --- a/t/wants.t +++ b/t/wants.t @@ -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 => {} @@ -36,7 +36,7 @@ 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 => {}, @@ -44,7 +44,7 @@ $wants = Bugzilla::WebService::Wants->new( 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 => {}, @@ -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 => {}, From f0db98161d724c95feedb2542e4bbf370d6d4212 Mon Sep 17 00:00:00 2001 From: Xavier L'Hour Date: Mon, 30 Nov 2026 19:27:45 +0100 Subject: [PATCH 2/2] Bug 2099197 - Export the remaining STATUS_* constants and update stale comments - Export STATUS_NOT_AUTHORIZED and STATUS_REQUEST_TOO_LARGE: the webservice_status_code_map hook documentation tells extensions to use the STATUS_* constants - Stop mentioning the WebService interface and XML-RPC fault codes, and refer to WS_ERROR_CODE by its name --- Bugzilla/API/V1/Constants.pm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Bugzilla/API/V1/Constants.pm b/Bugzilla/API/V1/Constants.pm index cc47c3aa15..25902c3324 100644 --- a/Bugzilla/API/V1/Constants.pm +++ b/Bugzilla/API/V1/Constants.pm @@ -17,7 +17,9 @@ our @EXPORT = qw( WS_ERROR_CODE STATUS_BAD_REQUEST + STATUS_NOT_AUTHORIZED STATUS_NOT_FOUND + STATUS_REQUEST_TOO_LARGE REST_STATUS_CODE_MAP ERROR_UNKNOWN_FATAL @@ -31,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." @@ -225,8 +226,7 @@ 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, }; @@ -273,7 +273,7 @@ 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;