# -*- 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 # Mads Bondo Dydensborg package Bugzilla::WebService::Product; use strict; use base qw(Bugzilla::WebService); use Bugzilla::Product; use Bugzilla::User; use Bugzilla::Error; use Bugzilla::Constants; use Bugzilla::WebService::Constants; use Bugzilla::WebService::Util qw(validate); use constant READ_ONLY => qw( get get_accessible_products get_enterable_products get_selectable_products ); ################################################## # Add aliases here for method name compatibility # ################################################## BEGIN { *get_products = \&get } # Get the ids of the products the user can search sub get_selectable_products { return {ids => [map {$_->id} @{Bugzilla->user->get_selectable_products}]}; } # Get the ids of the products the user can enter bugs against sub get_enterable_products { return {ids => [map {$_->id} @{Bugzilla->user->get_enterable_products}]}; } # Get the union of the products the user can search and enter bugs against. sub get_accessible_products { return {ids => [map {$_->id} @{Bugzilla->user->get_accessible_products}]}; } # Get a list of actual products, based on list of ids sub get { my ($self, $params) = validate(@_, 'ids'); # Only products that are in the users accessible products, # can be allowed to be returned my $accessible_products = Bugzilla->user->get_accessible_products; # Create a hash with the ids the user wants my %ids = map { $_ => 1 } @{$params->{ids}}; # Return the intersection of this, by grepping the ids from # accessible products. my @requested_accessible = grep { $ids{$_->id} } @$accessible_products; # Now create a result entry for each. my @products = map {{ internals => $_, id => $self->type('int', $_->id), name => $self->type('string', $_->name), description => $self->type('string', $_->description), } } @requested_accessible; return { products => \@products }; } sub create { my ($self, $params) = @_; Bugzilla->login(LOGIN_REQUIRED); Bugzilla->user->in_group('editcomponents') || ThrowUserError("auth_failure", { group => "editcomponents", action => "add", object => "products"}); # Create product my $product = Bugzilla::Product->create({ allows_unconfirmed => $params->{has_unconfirmed}, classification => $params->{classification}, name => $params->{name}, description => $params->{description}, version => $params->{version}, defaultmilestone => $params->{default_milestone}, isactive => $params->{is_open}, create_series => $params->{create_series} }); return { id => $self->type('int', $product->id) }; } 1; __END__ =head1 NAME Bugzilla::Webservice::Product - The Product API =head1 DESCRIPTION This part of the Bugzilla API allows you to list the available Products and get information about them. =head1 METHODS See L for a description of how parameters are passed, and what B, B, and B mean. =head1 List Products =head2 get_selectable_products B =over =item B Returns a list of the ids of the products the user can search on. =item B (none) =item B A hash containing one item, C, that contains an array of product ids. =item B (none) =back =head2 get_enterable_products B =over =item B Returns a list of the ids of the products the user can enter bugs against. =item B (none) =item B A hash containing one item, C, that contains an array of product ids. =item B (none) =back =head2 get_accessible_products B =over =item B Returns a list of the ids of the products the user can search or enter bugs against. =item B (none) =item B A hash containing one item, C, that contains an array of product ids. =item B (none) =back =head2 get B =over =item B Returns a list of information about the products passed to it. Note: Can also be called as "get_products" for compatibilty with Bugzilla 3.0 API. =item B A hash containing one item, C, that is an array of product ids. =item B A hash containing one item, C, that is an array of hashes. Each hash describes a product, and has the following items: C, C, C, and C. The C item is the id of the product. The C item is the name of the product. The C is the description of the product. Finally, the C is an internal representation of the product. Note, that if the user tries to access a product that is not in the list of accessible products for the user, or a product that does not exist, that is silently ignored, and no information about that product is returned. =item B (none) =back =head1 Product Creation =head2 create B =over =item B This allows you to create a new product in Bugzilla. =item B Some params must be set, or an error will be thrown. These params are marked B. =over =item C B C The name of this product. Must be globally unique within Bugzilla. =item C B C A description for this product. Allows some simple HTML. =item C B C The default version for this product. =item C C Allow the UNCONFIRMED status to be set on bugs in this product. =item C C The name of the Classification wich contains this product. =item C C The default milestone for this product. =item C C True if the product is currently allowing bugs to be entered into it. =item C C True if you want series for New Charts to be created for this new product. =back =item B A hash with one element, id. This is the id of the newly-filed product. =item B =over =item 700 (Product blank name) You must specify a non-blank name for this product. =item 701 (Product name too long) The name specified for this product was longer than the maximum allowed length. =item 702 (Product name already exists) You specified the name of a product that already exists. (Product names must be globally unique in Bugzilla.) =item 703 (Product must have description) You must specify a description for this product. =item 704 (Product must have version) You must specify a version for this product. =item 705 (Product must define a defaut milestone) You must define a default milestone. =back =back =cut