Product.pm 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. # -*- Mode: perl; indent-tabs-mode: nil -*-
  2. #
  3. # The contents of this file are subject to the Mozilla Public
  4. # License Version 1.1 (the "License"); you may not use this file
  5. # except in compliance with the License. You may obtain a copy of
  6. # the License at http://www.mozilla.org/MPL/
  7. #
  8. # Software distributed under the License is distributed on an "AS
  9. # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10. # implied. See the License for the specific language governing
  11. # rights and limitations under the License.
  12. #
  13. # The Original Code is the Bugzilla Bug Tracking System.
  14. #
  15. # Contributor(s): Marc Schumann <wurblzap@gmail.com>
  16. # Mads Bondo Dydensborg <mbd@dbc.dk>
  17. package Bugzilla::WebService::Product;
  18. use strict;
  19. use base qw(Bugzilla::WebService);
  20. use Bugzilla::Product;
  21. use Bugzilla::User;
  22. import SOAP::Data qw(type);
  23. ##################################################
  24. # Add aliases here for method name compatibility #
  25. ##################################################
  26. BEGIN { *get_products = \&get }
  27. # Get the ids of the products the user can search
  28. sub get_selectable_products {
  29. return {ids => [map {$_->id} @{Bugzilla->user->get_selectable_products}]};
  30. }
  31. # Get the ids of the products the user can enter bugs against
  32. sub get_enterable_products {
  33. return {ids => [map {$_->id} @{Bugzilla->user->get_enterable_products}]};
  34. }
  35. # Get the union of the products the user can search and enter bugs against.
  36. sub get_accessible_products {
  37. return {ids => [map {$_->id} @{Bugzilla->user->get_accessible_products}]};
  38. }
  39. # Get a list of actual products, based on list of ids
  40. sub get {
  41. my ($self, $params) = @_;
  42. # Only products that are in the users accessible products,
  43. # can be allowed to be returned
  44. my $accessible_products = Bugzilla->user->get_accessible_products;
  45. # Create a hash with the ids the user wants
  46. my %ids = map { $_ => 1 } @{$params->{ids}};
  47. # Return the intersection of this, by grepping the ids from
  48. # accessible products.
  49. my @requested_accessible = grep { $ids{$_->id} } @$accessible_products;
  50. # Now create a result entry for each.
  51. my @products =
  52. map {{
  53. internals => $_,
  54. id => type('int')->value($_->id),
  55. name => type('string')->value($_->name),
  56. description => type('string')->value($_->description),
  57. }
  58. } @requested_accessible;
  59. return { products => \@products };
  60. }
  61. 1;
  62. __END__
  63. =head1 NAME
  64. Bugzilla::Webservice::Product - The Product API
  65. =head1 DESCRIPTION
  66. This part of the Bugzilla API allows you to list the available Products and
  67. get information about them.
  68. =head1 METHODS
  69. See L<Bugzilla::WebService> for a description of how parameters are passed,
  70. and what B<STABLE>, B<UNSTABLE>, and B<EXPERIMENTAL> mean.
  71. =head2 List Products
  72. =over
  73. =item C<get_selectable_products>
  74. B<EXPERIMENTAL>
  75. =over
  76. =item B<Description>
  77. Returns a list of the ids of the products the user can search on.
  78. =item B<Params> (none)
  79. =item B<Returns>
  80. A hash containing one item, C<ids>, that contains an array of product
  81. ids.
  82. =item B<Errors> (none)
  83. =back
  84. =item C<get_enterable_products>
  85. B<EXPERIMENTAL>
  86. =over
  87. =item B<Description>
  88. Returns a list of the ids of the products the user can enter bugs
  89. against.
  90. =item B<Params> (none)
  91. =item B<Returns>
  92. A hash containing one item, C<ids>, that contains an array of product
  93. ids.
  94. =item B<Errors> (none)
  95. =back
  96. =item C<get_accessible_products>
  97. B<UNSTABLE>
  98. =over
  99. =item B<Description>
  100. Returns a list of the ids of the products the user can search or enter
  101. bugs against.
  102. =item B<Params> (none)
  103. =item B<Returns>
  104. A hash containing one item, C<ids>, that contains an array of product
  105. ids.
  106. =item B<Errors> (none)
  107. =back
  108. =item C<get>
  109. B<EXPERIMENTAL>
  110. =over
  111. =item B<Description>
  112. Returns a list of information about the products passed to it.
  113. Note: Can also be called as "get_products" for compatibilty with Bugzilla 3.0 API.
  114. =item B<Params>
  115. A hash containing one item, C<ids>, that is an array of product ids.
  116. =item B<Returns>
  117. A hash containing one item, C<products>, that is an array of
  118. hashes. Each hash describes a product, and has the following items:
  119. C<id>, C<name>, C<description>, and C<internals>. The C<id> item is
  120. the id of the product. The C<name> item is the name of the
  121. product. The C<description> is the description of the
  122. product. Finally, the C<internals> is an internal representation of
  123. the product.
  124. Note, that if the user tries to access a product that is not in the
  125. list of accessible products for the user, or a product that does not
  126. exist, that is silently ignored, and no information about that product
  127. is returned.
  128. =item B<Errors> (none)
  129. =back
  130. =back