Product.pm 4.62 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# -*- 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 <wurblzap@gmail.com>
16
#                 Mads Bondo Dydensborg <mbd@dbc.dk>
17 18 19 20 21 22

package Bugzilla::WebService::Product;

use strict;
use base qw(Bugzilla::WebService);
use Bugzilla::Product;
23 24
use Bugzilla::User;

25 26 27 28 29 30
##################################################
# Add aliases here for method name compatibility #
##################################################

BEGIN { *get_products = \&get }

31 32 33 34 35 36 37 38 39 40 41 42
# 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 {
43
    return {ids => [map {$_->id} @{Bugzilla->user->get_accessible_products}]}; 
44
}
45

46
# Get a list of actual products, based on list of ids
47
sub get {
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    my ($self, $params) = @_;
    
    # 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   => $_,
65 66 67
               id          => $self->type('int', $_->id),
               name        => $self->type('string', $_->name),
               description => $self->type('string', $_->description),
68 69 70 71
             }
        } @requested_accessible;

    return { products => \@products };
72 73 74
}

1;
75 76 77 78 79

__END__

=head1 NAME

80
Bugzilla::Webservice::Product - The Product API
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

=head1 DESCRIPTION

This part of the Bugzilla API allows you to list the available Products and
get information about them.

=head1 METHODS

See L<Bugzilla::WebService> for a description of what B<STABLE>, B<UNSTABLE>,
and B<EXPERIMENTAL> mean, and for more information about error codes.

=head2 List Products

=over

=item C<get_selectable_products> B<UNSTABLE>

98 99 100
=over

=item B<Description>
101

102
Returns a list of the ids of the products the user can search on.
103

104 105 106 107 108 109 110 111 112 113
=item B<Params> (none)

=item B<Returns>    

A hash containing one item, C<ids>, that contains an array of product
ids.

=item B<Errors> (none)

=back
114 115 116

=item C<get_enterable_products> B<UNSTABLE>

117 118 119 120 121 122 123 124 125 126
=over

=item B<Description>

Returns a list of the ids of the products the user can enter bugs
against.

=item B<Params> (none)

=item B<Returns>
127

128 129
A hash containing one item, C<ids>, that contains an array of product
ids.
130

131 132 133
=item B<Errors> (none)

=back
134 135 136

=item C<get_accessible_products> B<UNSTABLE>

137 138 139
=over

=item B<Description>
140

141 142
Returns a list of the ids of the products the user can search or enter
bugs against.
143

144 145 146 147 148 149 150 151 152 153 154
=item B<Params> (none)

=item B<Returns>

A hash containing one item, C<ids>, that contains an array of product
ids.

=item B<Errors> (none)

=back

155
=item C<get> B<UNSTABLE>
156 157 158 159 160 161 162

=over

=item B<Description>

Returns a list of information about the products passed to it.

163 164
Note: Can also be called as "get_products" for compatibilty with Bugzilla 3.0 API.

165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
=item B<Params>

A hash containing one item, C<ids>, that is an array of product ids. 

=item B<Returns> 

A hash containing one item, C<products>, that is an array of
hashes. Each hash describes a product, and has the following items:
C<id>, C<name>, C<description>, and C<internals>. The C<id> item is
the id of the product. The C<name> item is the name of the
product. The C<description> is the description of the
product. Finally, the C<internals> 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<Errors> (none)

=back
187 188 189

=back