diff options
author | Simon Green <sgreen@redhat.com> | 2014-08-12 10:12:17 +1000 |
---|---|---|
committer | Simon Green <sgreen@redhat.com> | 2014-08-12 10:12:17 +1000 |
commit | 8b98912309870c03c4b82396647682a8d9f247b4 (patch) | |
tree | 6760a61bfb5a6db76ad6466396ba076efe594fdc | |
parent | 2863a6679fe69c46f1de515d001eb0dd696e5977 (diff) | |
download | bugs-8b98912309870c03c4b82396647682a8d9f247b4.tar bugs-8b98912309870c03c4b82396647682a8d9f247b4.tar.gz bugs-8b98912309870c03c4b82396647682a8d9f247b4.tar.bz2 bugs-8b98912309870c03c4b82396647682a8d9f247b4.tar.xz bugs-8b98912309870c03c4b82396647682a8d9f247b4.zip |
Bug 419568 - Web Service module to create a component
r=dkl, a=sgreen
-rw-r--r-- | Bugzilla/WebService.pm | 2 | ||||
-rw-r--r-- | Bugzilla/WebService/Component.pm | 148 | ||||
-rw-r--r-- | Bugzilla/WebService/Constants.pm | 6 | ||||
-rw-r--r-- | Bugzilla/WebService/Server/REST.pm | 1 | ||||
-rw-r--r-- | Bugzilla/WebService/Server/REST/Resources/Component.pm | 47 |
5 files changed, 204 insertions, 0 deletions
diff --git a/Bugzilla/WebService.pm b/Bugzilla/WebService.pm index d12d4dbac..b8404251a 100644 --- a/Bugzilla/WebService.pm +++ b/Bugzilla/WebService.pm @@ -389,6 +389,8 @@ objects. =item L<Bugzilla::WebService::FlagType> +=item L<Bugzilla::WebService::Component> + =item L<Bugzilla::WebService::Group> =item L<Bugzilla::WebService::Product> diff --git a/Bugzilla/WebService/Component.pm b/Bugzilla/WebService/Component.pm new file mode 100644 index 000000000..edf3d5b8c --- /dev/null +++ b/Bugzilla/WebService/Component.pm @@ -0,0 +1,148 @@ +# 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::Component; + +use 5.10.1; + +use strict; +use base qw(Bugzilla::WebService); + +use Bugzilla::Component; +use Bugzilla::Constants; +use Bugzilla::Error; +use Bugzilla::WebService::Constants; +use Bugzilla::WebService::Util qw(translate params_to_objects validate); + +use constant MAPPED_FIELDS => { + default_assignee => 'initialowner', + default_qa_contact => 'initialqacontact', + default_cc => 'initial_cc', + is_open => 'isactive', +}; + +sub create { + my ($self, $params) = @_; + + my $user = Bugzilla->login(LOGIN_REQUIRED); + + $user->in_group('editcomponents') + || scalar @{ $user->get_products_by_permission('editcomponents') } + || ThrowUserError('auth_failure', { group => 'editcomponents', + action => 'edit', + object => 'components' }); + + my $product = $user->check_can_admin_product($params->{product}); + + # Translate the fields + my $values = translate($params, MAPPED_FIELDS); + $values->{product} = $product; + + # Create the component and return the newly created id. + my $component = Bugzilla::Component->create($values); + return { id => $self->type('int', $component->id) }; +} + +1; + +__END__ + +=head1 NAME + +Bugzilla::Webservice::Component - The Component API + +=head1 DESCRIPTION + +This part of the Bugzilla API allows you to deal with the available product components. +You will be able to get information about them as well as manipulate them. + +=head1 METHODS + +See L<Bugzilla::WebService> for a description of how parameters are passed, +and what B<STABLE>, B<UNSTABLE>, and B<EXPERIMENTAL> mean. + +=head1 Component Creation and Modification + +=head2 create + +B<EXPERIMENTAL> + +=over + +=item B<Description> + +This allows you to create a new component in Bugzilla. + +=item B<Params> + +Some params must be set, or an error will be thrown. These params are +marked B<Required>. + +=over + +=item C<name> + +B<Required> C<string> The name of the new component. + +=item C<product> + +B<Required> C<string> The name of the product that the component must be +added to. This product must already exist, and the user have the necessary +permissions to edit components for it. + +=item C<description> + +B<Required> C<string> The description of the new component. + +=item C<default_assignee> + +B<Required> C<string> The login name of the default assignee of the component. + +=item C<default_cc> + +C<array> An array of strings with each element representing one login name of the default CC list. + +=item C<default_qa_contact> + +C<string> The login name of the default QA contact for the component. + +=item C<is_open> + +C<boolean> 1 if you want to enable the component for bug creations. 0 otherwise. Default is 1. + +=back + +=item B<Returns> + +A hash with one key: C<id>. This will represent the ID of the newly-added +component. + +=item B<Errors> + +=over + +=item 304 (Authorization Failure) + +You are not authorized to create a new component. + +=item 1200 (Component already exists) + +The name that you specified for the new component already exists in the +specified product. + +=back + +=item B<History> + +=over + +=item Added in Bugzilla B<5.0>. + +=back + +=back + diff --git a/Bugzilla/WebService/Constants.pm b/Bugzilla/WebService/Constants.pm index 2fa1bdc28..b6dead40d 100644 --- a/Bugzilla/WebService/Constants.pm +++ b/Bugzilla/WebService/Constants.pm @@ -203,6 +203,11 @@ use constant WS_ERROR_CODE => { flag_type_sortkey_invalid => 1104, flag_type_not_editable => 1105, + # Component errors are 1200-1300 + component_already_exists => 1200, + component_is_last => 1201, + component_has_bugs => 1202, + # Errors thrown by the WebService itself. The ones that are negative # conform to http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php xmlrpc_invalid_value => -32600, @@ -282,6 +287,7 @@ sub WS_DISPATCH { 'Bugzilla' => 'Bugzilla::WebService::Bugzilla', 'Bug' => 'Bugzilla::WebService::Bug', 'Classification' => 'Bugzilla::WebService::Classification', + 'Component' => 'Bugzilla::WebService::Component', 'FlagType' => 'Bugzilla::WebService::FlagType', 'Group' => 'Bugzilla::WebService::Group', 'Product' => 'Bugzilla::WebService::Product', diff --git a/Bugzilla/WebService/Server/REST.pm b/Bugzilla/WebService/Server/REST.pm index 2f1b80c45..bd1b500a5 100644 --- a/Bugzilla/WebService/Server/REST.pm +++ b/Bugzilla/WebService/Server/REST.pm @@ -23,6 +23,7 @@ use Bugzilla::WebService::Util qw(taint_data fix_credentials); use Bugzilla::WebService::Server::REST::Resources::Bug; use Bugzilla::WebService::Server::REST::Resources::Bugzilla; use Bugzilla::WebService::Server::REST::Resources::Classification; +use Bugzilla::WebService::Server::REST::Resources::Component; use Bugzilla::WebService::Server::REST::Resources::FlagType; use Bugzilla::WebService::Server::REST::Resources::Group; use Bugzilla::WebService::Server::REST::Resources::Product; diff --git a/Bugzilla/WebService/Server/REST/Resources/Component.pm b/Bugzilla/WebService/Server/REST/Resources/Component.pm new file mode 100644 index 000000000..8c047d409 --- /dev/null +++ b/Bugzilla/WebService/Server/REST/Resources/Component.pm @@ -0,0 +1,47 @@ +# 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::Component; + +use 5.10.1; +use strict; + +use Bugzilla::WebService::Constants; +use Bugzilla::WebService::Component; + +use Bugzilla::Error; + +BEGIN { + *Bugzilla::WebService::Component::rest_resources = \&_rest_resources; +}; + +sub _rest_resources { + my $rest_resources = [ + qr{^/component$}, { + POST => { + method => 'create', + success_code => STATUS_CREATED + } + }, + ]; + return $rest_resources; +} + +1; + +__END__ + +=head1 NAME + +Bugzilla::Webservice::Server::REST::Resources::Component - The Component REST API + +=head1 DESCRIPTION + +This part of the Bugzilla REST API allows you create Components. + +See L<Bugzilla::WebService::Component> for more details on how to use this +part of the REST API. |