###############################
sub check_product {
- my ($product_name) = @_;
+ my ($product_name, $check_can_access) = @_;
- unless ($product_name) {
- ThrowUserError('product_not_specified');
- }
+ $product_name || ThrowUserError('product_not_specified');
my $product = new Bugzilla::Product({name => $product_name});
- unless ($product) {
- ThrowUserError('product_doesnt_exist',
- {'product' => $product_name});
+ if (!$product) {
+ if ($check_can_access) {
+ ThrowUserError('product_access_denied', { product => $product_name });
+ }
+ else {
+ ThrowUserError('product_doesnt_exist', { product => $product_name });
+ }
}
+
+ if ($check_can_access && !Bugzilla->user->can_access_product($product->name)) {
+ ThrowUserError('product_access_denied', { product => $product_name });
+ }
+
return $product;
}
This function is not exported, so must be called like
C<Bugzilla::Product::preload($products)>.
-=item C<check_product($product_name)>
+=item C<check_product($product_name, $check_can_access)>
Description: Checks if the product name was passed in and if is a valid
product.
Params: $product_name - String with a product name.
+ $check_can_access - (optional) If set to true, the function
+ will also make sure that the user can access the product.
Returns: Bugzilla::Product object.
# Make sure all products are valid.
foreach my $p (@query_products) {
- Bugzilla::Product::check_product($p);
+ # The second argument is set to true so that an error
+ # is thrown if the product is not accessible by the user.
+ Bugzilla::Product::check_product($p, 1);
}
# Small backwards-compatibility hack, dated 2002-04-10.
# Filter results by exact product or component.
if (defined $cgi->param('product') && $cgi->param('product') ne "") {
- my $product = Bugzilla::Product::check_product(scalar $cgi->param('product'));
+ # The second argument is set to true so that an error is thrown
+ # if the product is not accessible by the user.
+ my $product = Bugzilla::Product::check_product(scalar $cgi->param('product'), 1);
push(@criteria, "bugs.product_id = " . $product->id);
push(@excluded_columns, 'product') unless $cgi->param('do_union');
if (defined $cgi->param('component') && $cgi->param('component') ne "") {