From 2ecd676f8e8154f6364a3a158013250695ed9251 Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Wed, 12 Oct 2005 09:08:54 +0000 Subject: Bug 306325: Move CanEnterProduct() and CanEnterProductOrWarn() out of globals.pl - Patch by Frédéric Buclin r=joel r=wicked a=justdave MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- globals.pl | 92 -------------------------------------------------------------- 1 file changed, 92 deletions(-) (limited to 'globals.pl') diff --git a/globals.pl b/globals.pl index 4d21b088b..07d12a984 100644 --- a/globals.pl +++ b/globals.pl @@ -411,98 +411,6 @@ sub IsInClassification { } } -# This function determines whether or not a user can enter -# bugs into the named product. -sub CanEnterProduct { - my ($productname, $verbose) = @_; - my $dbh = Bugzilla->dbh; - - return unless defined($productname); - trick_taint($productname); - - # First check whether or not the user has access to that product. - my $query = "SELECT group_id IS NULL " . - "FROM products " . - "LEFT JOIN group_control_map " . - "ON group_control_map.product_id = products.id " . - "AND group_control_map.entry != 0 "; - if (%{Bugzilla->user->groups}) { - $query .= "AND group_id NOT IN(" . - join(',', values(%{Bugzilla->user->groups})) . ") "; - } - $query .= "WHERE products.name = ? " . - $dbh->sql_limit(1); - - my $has_access = $dbh->selectrow_array($query, undef, $productname); - if (!$has_access) { - # Do we require the exact reason why we cannot enter - # bugs into that product? Returning -1 explicitely - # means the user has no access to the product or the - # product does not exist. - return (defined($verbose)) ? -1 : 0; - } - - # Check if the product is open for new bugs and has - # at least one component and has at least one version. - my ($allow_new_bugs, $has_version) = - $dbh->selectrow_array('SELECT CASE WHEN disallownew = 0 THEN 1 ELSE 0 END, ' . - 'versions.value IS NOT NULL ' . - 'FROM products INNER JOIN components ' . - 'ON components.product_id = products.id ' . - 'LEFT JOIN versions ' . - 'ON versions.product_id = products.id ' . - 'WHERE products.name = ? ' . - $dbh->sql_limit(1), undef, $productname); - - - if (defined $verbose) { - # Return (undef, undef) if the product has no components, - # Return (?, 0) if the product has no versions, - # Return (0, ?) if the product is closed for new bug entry, - # Return (1, 1) if the user can enter bugs into the product, - return ($allow_new_bugs, $has_version); - } else { - # Return undef if the product has no components - # Return 0 if the product has no versions, or is closed for bug entry - # Return 1 if the user can enter bugs into the product - return ($allow_new_bugs && $has_version); - } -} - -# Call CanEnterProduct() and display an error message -# if the user cannot enter bugs into that product. -sub CanEnterProductOrWarn { - my ($product) = @_; - - if (!defined($product)) { - ThrowUserError("no_products"); - } - my ($allow_new_bugs, $has_version) = CanEnterProduct($product, 1); - trick_taint($product); - - if (!defined $allow_new_bugs) { - ThrowUserError("missing_component", { product => $product }); - } elsif (!$allow_new_bugs) { - ThrowUserError("product_disabled", { product => $product}); - } elsif ($allow_new_bugs < 0) { - ThrowUserError("entry_access_denied", { product => $product}); - } elsif (!$has_version) { - ThrowUserError("missing_version", { product => $product }); - } - return 1; -} - -sub GetEnterableProducts { - my @products; - # XXX rewrite into pure SQL instead of relying on legal_products? - foreach my $p (@::legal_product) { - if (CanEnterProduct($p)) { - push @products, $p; - } - } - return (@products); -} - sub ValidatePassword { # Determines whether or not a password is valid (i.e. meets Bugzilla's # requirements for length and content). -- cgit v1.2.3-24-g4f1b