Commit d8f36cac authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 337054: Remove get_component_id() and get_component_name() from globals.pl -…

Bug 337054: Remove get_component_id() and get_component_name() from globals.pl - Patch by Frédéric Buclin <LpSolit@gmail.com> r=mkanat a=myk
parent 598ce63e
...@@ -38,6 +38,7 @@ use Bugzilla::Constants; ...@@ -38,6 +38,7 @@ use Bugzilla::Constants;
use Bugzilla::Config qw(:DEFAULT $datadir); use Bugzilla::Config qw(:DEFAULT $datadir);
use Bugzilla::Util; use Bugzilla::Util;
use Bugzilla::Bug; use Bugzilla::Bug;
use Bugzilla::Component;
use Date::Parse; use Date::Parse;
use Date::Format; use Date::Format;
...@@ -141,7 +142,8 @@ sub ProcessOneBug { ...@@ -141,7 +142,8 @@ sub ProcessOneBug {
undef, $id)}; undef, $id)};
$values{product} = &::get_product_name($values{product_id}); $values{product} = &::get_product_name($values{product_id});
$values{component} = &::get_component_name($values{component_id}); my $component = new Bugzilla::Component($values{component_id});
$values{component} = $component->name;
my ($start, $end) = ($values{start}, $values{end}); my ($start, $end) = ($values{start}, $values{end});
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
# #
# You need to work with bug_email.pl the MIME::Parser installed. # You need to work with bug_email.pl the MIME::Parser installed.
# #
# $Id: bug_email.pl,v 1.34 2006/05/14 19:12:13 lpsolit%gmail.com Exp $ # $Id: bug_email.pl,v 1.35 2006/05/29 17:24:54 lpsolit%gmail.com Exp $
############################################################### ###############################################################
# 02/12/2000 (SML) # 02/12/2000 (SML)
...@@ -96,6 +96,8 @@ use lib "../"; ...@@ -96,6 +96,8 @@ use lib "../";
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::BugMail; use Bugzilla::BugMail;
use Bugzilla::User; use Bugzilla::User;
use Bugzilla::Product;
use Bugzilla::Component;
my @mailerrors = (); # Buffer for Errors in the mail my @mailerrors = (); # Buffer for Errors in the mail
my @mailwarnings = (); # Buffer for Warnings found in the mail my @mailwarnings = (); # Buffer for Warnings found in the mail
...@@ -202,34 +204,6 @@ sub CheckPermissions { ...@@ -202,34 +204,6 @@ sub CheckPermissions {
} }
############################################################### ###############################################################
# Check if product is valid.
sub CheckProduct {
my $Product = shift;
my $dbh = Bugzilla->dbh;
my $prod_name = $dbh->selectrow_array(q{SELECT name
FROM products
WHERE name = ?}, undef, $Product);
return $prod_name || "";
}
###############################################################
# Check if component is valid for product.
sub CheckComponent {
my $Product = shift;
my $Component = shift;
my $dbh = Bugzilla->dbh;
my $comp_name = $dbh->selectrow_array(q{SELECT components.name
FROM components
INNER JOIN products
ON components.product_id = products.id
WHERE products.name= ?
AND components.name= ?},
undef, $Product, $Component);
return $comp_name || "";
}
###############################################################
# Check if component is valid for product. # Check if component is valid for product.
sub CheckVersion { sub CheckVersion {
my $Product = shift; my $Product = shift;
...@@ -812,10 +786,14 @@ if (Param("useqacontact")) { ...@@ -812,10 +786,14 @@ if (Param("useqacontact")) {
# depends on the product ! # depends on the product !
# => first check product ! # => first check product !
# Product # Product
my $product;
my $all_products; my $all_products;
# set to the default product. If the default product is empty, this has no effect # set to the default product. If the default product is empty, this has no effect
my $Product = $DEFAULT_PRODUCT; my $Product = $DEFAULT_PRODUCT;
$Product = CheckProduct( $Control{'product'} ) if( defined( $Control{ 'product'} )); if (defined($Control{ 'product'})) {
$product = new Bugzilla::Product({'name' => $Control{'product'}});
$Product = $product ? $product->name : "";
}
if ( $Product eq "" ) { if ( $Product eq "" ) {
my $Text = "You didn't send a value for the required key \@product !\n\n"; my $Text = "You didn't send a value for the required key \@product !\n\n";
...@@ -843,12 +821,15 @@ $Control{'product'} = $Product; ...@@ -843,12 +821,15 @@ $Control{'product'} = $Product;
# #
# set to the default component. If the default component is empty, this has no effect # set to the default component. If the default component is empty, this has no effect
my $component;
my $Component = $DEFAULT_COMPONENT; my $Component = $DEFAULT_COMPONENT;
if( defined( $Control{'component' } )) { if (defined($Control{'component'})) {
$Component = CheckComponent( $Control{'product'}, $Control{'component'} ); $component = new Bugzilla::Component({'product_id' => $product->id,
'name' => $Control{'component'}});
$Component = $component ? $component->name : "";
} }
if ( $Component eq "" ) { if ( $Component eq "" ) {
my $Text = "You did not send a value for the required key \@component!\n\n"; my $Text = "You did not send a value for the required key \@component!\n\n";
...@@ -1091,10 +1072,9 @@ END ...@@ -1091,10 +1072,9 @@ END
if( $field eq "groupset" ) { if( $field eq "groupset" ) {
push (@values, $Control{$field}); push (@values, $Control{$field});
} elsif ( $field eq 'product' ) { } elsif ( $field eq 'product' ) {
push (@values, get_product_id($Control{$field})); push (@values, $product->id);
} elsif ( $field eq 'component' ) { } elsif ( $field eq 'component' ) {
push (@values, get_component_id(get_product_id($Control{'product'}), push (@values, $component->id);
$Control{$field}));
} else { } else {
push (@values, $Control{$field}); push (@values, $Control{$field});
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
# Rights Reserved. # Rights Reserved.
# #
# Contributor(s): Myk Melez <myk@mozilla.org> # Contributor(s): Myk Melez <myk@mozilla.org>
# Frédéric Buclin <LpSolit@gmail.com>
################################################################################ ################################################################################
# Script Initialization # Script Initialization
...@@ -39,6 +40,7 @@ use Bugzilla::FlagType; ...@@ -39,6 +40,7 @@ use Bugzilla::FlagType;
use Bugzilla::Group; use Bugzilla::Group;
use Bugzilla::Util; use Bugzilla::Util;
use Bugzilla::Product; use Bugzilla::Product;
use Bugzilla::Component;
my $template = Bugzilla->template; my $template = Bugzilla->template;
my $vars = {}; my $vars = {};
...@@ -51,8 +53,6 @@ $user->in_group('editcomponents') ...@@ -51,8 +53,6 @@ $user->in_group('editcomponents')
object => "flagtypes"}); object => "flagtypes"});
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
my $product_id;
my $component_id;
################################################################################ ################################################################################
# Main Body Execution # Main Body Execution
...@@ -190,15 +190,17 @@ sub processCategoryChange { ...@@ -190,15 +190,17 @@ sub processCategoryChange {
my @inclusions = $cgi->param('inclusions'); my @inclusions = $cgi->param('inclusions');
my @exclusions = $cgi->param('exclusions'); my @exclusions = $cgi->param('exclusions');
if ($categoryAction eq 'include') { if ($categoryAction eq 'include') {
validateProduct(); my $product = validateProduct(scalar $cgi->param('product'));
validateComponent(); my $component = validateComponent($product, scalar $cgi->param('component'));
my $category = ($product_id || 0) . ":" . ($component_id || 0); my $category = ($product ? $product->id : 0) . ":" .
($component ? $component->id : 0);
push(@inclusions, $category) unless grep($_ eq $category, @inclusions); push(@inclusions, $category) unless grep($_ eq $category, @inclusions);
} }
elsif ($categoryAction eq 'exclude') { elsif ($categoryAction eq 'exclude') {
validateProduct(); my $product = validateProduct(scalar $cgi->param('product'));
validateComponent(); my $component = validateComponent($product, scalar $cgi->param('component'));
my $category = ($product_id || 0) . ":" . ($component_id || 0); my $category = ($product ? $product->id : 0) . ":" .
($component ? $component->id : 0);
push(@exclusions, $category) unless grep($_ eq $category, @exclusions); push(@exclusions, $category) unless grep($_ eq $category, @exclusions);
} }
elsif ($categoryAction eq 'removeInclusion') { elsif ($categoryAction eq 'removeInclusion') {
...@@ -249,11 +251,16 @@ sub processCategoryChange { ...@@ -249,11 +251,16 @@ sub processCategoryChange {
sub clusion_array_to_hash { sub clusion_array_to_hash {
my $array = shift; my $array = shift;
my %hash; my %hash;
my %components;
foreach my $ids (@$array) { foreach my $ids (@$array) {
trick_taint($ids); trick_taint($ids);
my ($product_id, $component_id) = split(":", $ids); my ($product_id, $component_id) = split(":", $ids);
my $product_name = get_product_name($product_id) || "__Any__"; my $product_name = get_product_name($product_id) || "__Any__";
my $component_name = get_component_name($component_id) || "__Any__"; my $component_name = "__Any__";
if ($component_id) {
$components{$component_id} ||= new Bugzilla::Component($component_id);
$component_name = $components{$component_id}->name;
}
$hash{"$product_name:$component_name"} = $ids; $hash{"$product_name:$component_name"} = $ids;
} }
return %hash; return %hash;
...@@ -531,27 +538,22 @@ sub validateCCList { ...@@ -531,27 +538,22 @@ sub validateCCList {
} }
sub validateProduct { sub validateProduct {
return if !$cgi->param('product'); my $product_name = shift;
return unless $product_name;
$product_id = get_product_id($cgi->param('product'));
my $product = Bugzilla::Product::check_product($product_name);
defined($product_id) return $product;
|| ThrowCodeError("flag_type_product_nonexistent",
{ product => $cgi->param('product') });
} }
sub validateComponent { sub validateComponent {
return if !$cgi->param('component'); my ($product, $component_name) = @_;
return unless $component_name;
$product_id
($product && $product->id)
|| ThrowCodeError("flag_type_component_without_product"); || ThrowCodeError("flag_type_component_without_product");
$component_id = get_component_id($product_id, $cgi->param('component'));
defined($component_id) my $component = Bugzilla::Component::check_component($product, $component_name);
|| ThrowCodeError("flag_type_component_nonexistent", return $component;
{ product => $cgi->param('product'),
name => $cgi->param('component') });
} }
sub validateSortKey { sub validateSortKey {
......
...@@ -218,28 +218,6 @@ sub get_product_name { ...@@ -218,28 +218,6 @@ sub get_product_name {
return $prod; return $prod;
} }
sub get_component_id {
my ($prod_id, $comp) = @_;
return undef unless ($prod_id && ($prod_id =~ /^\d+$/));
PushGlobalSQLState();
SendSQL("SELECT id FROM components " .
"WHERE product_id = $prod_id AND name = " . SqlQuote($comp));
my ($comp_id) = FetchSQLData();
PopGlobalSQLState();
return $comp_id;
}
sub get_component_name {
my ($comp_id) = @_;
die "non-numeric comp_id '$comp_id' passed to get_component_name"
unless ($comp_id =~ /^\d+$/);
PushGlobalSQLState();
SendSQL("SELECT name FROM components WHERE id = $comp_id");
my ($comp) = FetchSQLData();
PopGlobalSQLState();
return $comp;
}
# Returns a list of all the legal values for a field that has a # Returns a list of all the legal values for a field that has a
# list of legal values, like rep_platform or resolution. # list of legal values, like rep_platform or resolution.
sub get_legal_field_values { sub get_legal_field_values {
......
...@@ -95,16 +95,14 @@ ValidateComment($comment); ...@@ -95,16 +95,14 @@ ValidateComment($comment);
# Check that the product exists and that the user # Check that the product exists and that the user
# is allowed to enter bugs into this product. # is allowed to enter bugs into this product.
my $product = $cgi->param('product'); $user->can_enter_product(scalar $cgi->param('product'), 1);
$user->can_enter_product($product, 1);
my $prod_obj = new Bugzilla::Product({name => $product}); my $product = Bugzilla::Product::check_product(scalar $cgi->param('product'));
my $product_id = $prod_obj->id;
# Set cookies # Set cookies
if (defined $cgi->param('product')) { if (defined $cgi->param('product')) {
if (defined $cgi->param('version')) { if (defined $cgi->param('version')) {
$cgi->send_cookie(-name => "VERSION-$product", $cgi->send_cookie(-name => "VERSION-" . $product->name,
-value => $cgi->param('version'), -value => $cgi->param('version'),
-expires => "Fri, 01-Jan-2038 00:00:00 GMT"); -expires => "Fri, 01-Jan-2038 00:00:00 GMT");
} }
...@@ -123,9 +121,8 @@ if (defined $cgi->param('maketemplate')) { ...@@ -123,9 +121,8 @@ if (defined $cgi->param('maketemplate')) {
umask 0; umask 0;
# Some sanity checking # Some sanity checking
my $component_id = get_component_id($product_id, $cgi->param('component') || ThrowUserError("require_component");
scalar($cgi->param('component'))); my $component = Bugzilla::Component::check_component($product, scalar $cgi->param('component'));
$component_id || ThrowUserError("require_component");
# Set the parameter to itself, but cleaned up # Set the parameter to itself, but cleaned up
$cgi->param('short_desc', clean_text($cgi->param('short_desc'))); $cgi->param('short_desc', clean_text($cgi->param('short_desc')));
...@@ -151,7 +148,7 @@ if (!UserInGroup("editbugs") || $cgi->param('assigned_to') eq "") { ...@@ -151,7 +148,7 @@ if (!UserInGroup("editbugs") || $cgi->param('assigned_to') eq "") {
my $initialowner = $dbh->selectrow_array(q{SELECT initialowner my $initialowner = $dbh->selectrow_array(q{SELECT initialowner
FROM components FROM components
WHERE id = ?}, WHERE id = ?},
undef, $component_id); undef, $component->id);
$cgi->param(-name => 'assigned_to', -value => $initialowner); $cgi->param(-name => 'assigned_to', -value => $initialowner);
} else { } else {
$cgi->param(-name => 'assigned_to', $cgi->param(-name => 'assigned_to',
...@@ -180,7 +177,7 @@ if (Param("useqacontact")) { ...@@ -180,7 +177,7 @@ if (Param("useqacontact")) {
($qa_contact) = $dbh->selectrow_array(q{SELECT initialqacontact ($qa_contact) = $dbh->selectrow_array(q{SELECT initialqacontact
FROM components FROM components
WHERE id = ?}, WHERE id = ?},
undef, $component_id); undef, $component->id);
} else { } else {
$qa_contact = login_to_id(trim($cgi->param('qa_contact')), THROW_ERROR); $qa_contact = login_to_id(trim($cgi->param('qa_contact')), THROW_ERROR);
} }
...@@ -202,20 +199,18 @@ if (UserInGroup("editbugs") || UserInGroup("canconfirm")) { ...@@ -202,20 +199,18 @@ if (UserInGroup("editbugs") || UserInGroup("canconfirm")) {
my $votestoconfirm = $dbh->selectrow_array(q{SELECT votestoconfirm my $votestoconfirm = $dbh->selectrow_array(q{SELECT votestoconfirm
FROM products FROM products
WHERE id = ?}, WHERE id = ?},
undef, $product_id); undef, $product->id);
if (!$votestoconfirm) { if (!$votestoconfirm) {
$cgi->param(-name => 'bug_status', -value => "NEW"); $cgi->param(-name => 'bug_status', -value => "NEW");
} }
} }
trick_taint($product);
if (!defined $cgi->param('target_milestone')) { if (!defined $cgi->param('target_milestone')) {
my $defaultmilestone = $dbh->selectrow_array(q{SELECT defaultmilestone my $defaultmilestone = $dbh->selectrow_array(q{SELECT defaultmilestone
FROM products FROM products
WHERE name = ?}, WHERE name = ?},
undef, $product); undef, $product->name);
$cgi->param(-name => 'target_milestone', -value => $defaultmilestone); $cgi->param(-name => 'target_milestone', -value => $defaultmilestone);
} }
...@@ -226,19 +221,15 @@ if (!Param('letsubmitterchoosepriority')) { ...@@ -226,19 +221,15 @@ if (!Param('letsubmitterchoosepriority')) {
GetVersionTable(); GetVersionTable();
# Some more sanity checking # Some more sanity checking
check_field('product', scalar $cgi->param('product'),
[map($_->name, Bugzilla::Product::get_all_products())]);
check_field('rep_platform', scalar $cgi->param('rep_platform'), \@::legal_platform); check_field('rep_platform', scalar $cgi->param('rep_platform'), \@::legal_platform);
check_field('bug_severity', scalar $cgi->param('bug_severity'), \@::legal_severity); check_field('bug_severity', scalar $cgi->param('bug_severity'), \@::legal_severity);
check_field('priority', scalar $cgi->param('priority'), \@::legal_priority); check_field('priority', scalar $cgi->param('priority'), \@::legal_priority);
check_field('op_sys', scalar $cgi->param('op_sys'), \@::legal_opsys); check_field('op_sys', scalar $cgi->param('op_sys'), \@::legal_opsys);
check_field('bug_status', scalar $cgi->param('bug_status'), ['UNCONFIRMED', 'NEW']); check_field('bug_status', scalar $cgi->param('bug_status'), ['UNCONFIRMED', 'NEW']);
check_field('version', scalar $cgi->param('version'), check_field('version', scalar $cgi->param('version'),
[map($_->name, @{$prod_obj->versions})]); [map($_->name, @{$product->versions})]);
check_field('component', scalar $cgi->param('component'),
[map($_->name, @{$prod_obj->components})]);
check_field('target_milestone', scalar $cgi->param('target_milestone'), check_field('target_milestone', scalar $cgi->param('target_milestone'),
[map($_->name, @{$prod_obj->milestones})]); [map($_->name, @{$product->milestones})]);
foreach my $field_name ('assigned_to', 'bug_file_loc', 'comment') { foreach my $field_name ('assigned_to', 'bug_file_loc', 'comment') {
defined($cgi->param($field_name)) defined($cgi->param($field_name))
...@@ -255,9 +246,9 @@ foreach my $field (@bug_fields) { ...@@ -255,9 +246,9 @@ foreach my $field (@bug_fields) {
} }
} }
$cgi->param(-name => 'product_id', -value => $product_id); $cgi->param(-name => 'product_id', -value => $product->id);
push(@used_fields, "product_id"); push(@used_fields, "product_id");
$cgi->param(-name => 'component_id', -value => $component_id); $cgi->param(-name => 'component_id', -value => $component->id);
push(@used_fields, "component_id"); push(@used_fields, "component_id");
my %ccids; my %ccids;
...@@ -304,7 +295,7 @@ if (Param("strict_isolation")) { ...@@ -304,7 +295,7 @@ if (Param("strict_isolation")) {
} }
foreach my $pid (keys %related_users) { foreach my $pid (keys %related_users) {
my $related_user = Bugzilla::User->new($pid); my $related_user = Bugzilla::User->new($pid);
if (!$related_user->can_edit_product($product_id)) { if (!$related_user->can_edit_product($product->id)) {
push (@blocked_users, $related_user->login); push (@blocked_users, $related_user->login);
} }
} }
...@@ -312,7 +303,7 @@ if (Param("strict_isolation")) { ...@@ -312,7 +303,7 @@ if (Param("strict_isolation")) {
ThrowUserError("invalid_user_group", ThrowUserError("invalid_user_group",
{'users' => \@blocked_users, {'users' => \@blocked_users,
'new' => 1, 'new' => 1,
'product' => $product 'product' => $product->name
}); });
} }
} }
...@@ -416,7 +407,7 @@ foreach my $b (grep(/^bit-\d*$/, $cgi->param())) { ...@@ -416,7 +407,7 @@ foreach my $b (grep(/^bit-\d*$/, $cgi->param())) {
my ($permit) = $user->in_group_id($v); my ($permit) = $user->in_group_id($v);
if (!$permit) { if (!$permit) {
my $othercontrol = $dbh->selectrow_array($sth_othercontrol, my $othercontrol = $dbh->selectrow_array($sth_othercontrol,
undef, ($v, $product_id)); undef, ($v, $product->id));
$permit = (($othercontrol == CONTROLMAPSHOWN) $permit = (($othercontrol == CONTROLMAPSHOWN)
|| ($othercontrol == CONTROLMAPDEFAULT)); || ($othercontrol == CONTROLMAPDEFAULT));
} }
...@@ -435,7 +426,7 @@ my $groups = $dbh->selectall_arrayref(q{ ...@@ -435,7 +426,7 @@ my $groups = $dbh->selectall_arrayref(q{
AND product_id = ? AND product_id = ?
WHERE isbuggroup != 0 WHERE isbuggroup != 0
AND isactive != 0 AND isactive != 0
ORDER BY description}, undef, $product_id); ORDER BY description}, undef, $product->id);
foreach my $group (@$groups) { foreach my $group (@$groups) {
my ($id, $groupname, $membercontrol, $othercontrol) = @$group; my ($id, $groupname, $membercontrol, $othercontrol) = @$group;
......
...@@ -57,6 +57,7 @@ use Bugzilla::User; ...@@ -57,6 +57,7 @@ use Bugzilla::User;
use Bugzilla::Util; use Bugzilla::Util;
use Bugzilla::Field; use Bugzilla::Field;
use Bugzilla::Product; use Bugzilla::Product;
use Bugzilla::Component;
use Bugzilla::Keyword; use Bugzilla::Keyword;
# Use the Flag module to modify flag data if the user set flags. # Use the Flag module to modify flag data if the user set flags.
...@@ -944,20 +945,16 @@ foreach my $field (Bugzilla->custom_field_names) { ...@@ -944,20 +945,16 @@ foreach my $field (Bugzilla->custom_field_names) {
} }
} }
my $product;
my $prod_id;
my $prod_changed; my $prod_changed;
my @newprod_ids; my @newprod_ids;
if ($cgi->param('product') ne $cgi->param('dontchange')) { if ($cgi->param('product') ne $cgi->param('dontchange')) {
$prod_id = get_product_id($cgi->param('product')); $product = Bugzilla::Product::check_product(scalar $cgi->param('product'));
$prod_id ||
ThrowUserError("invalid_product_name",
{product => $cgi->param('product')});
DoComma(); DoComma();
$::query .= "product_id = ?"; $::query .= "product_id = ?";
push(@values, $prod_id); push(@values, $product->id);
@newprod_ids = ($prod_id); @newprod_ids = ($product->id);
$prod_changed = 1; $prod_changed = 1;
} else { } else {
@newprod_ids = @{$dbh->selectcol_arrayref("SELECT DISTINCT product_id @newprod_ids = @{$dbh->selectcol_arrayref("SELECT DISTINCT product_id
...@@ -966,25 +963,23 @@ if ($cgi->param('product') ne $cgi->param('dontchange')) { ...@@ -966,25 +963,23 @@ if ($cgi->param('product') ne $cgi->param('dontchange')) {
join(',', @idlist) . join(',', @idlist) .
")")}; ")")};
if (scalar(@newprod_ids) == 1) { if (scalar(@newprod_ids) == 1) {
($prod_id) = @newprod_ids; $product = Bugzilla::Product::check_product($newprod_ids[0]);
} }
} }
my $comp_id; my $component;
if ($cgi->param('component') ne $cgi->param('dontchange')) { if ($cgi->param('component') ne $cgi->param('dontchange')) {
if (scalar(@newprod_ids) > 1) { if (scalar(@newprod_ids) > 1) {
ThrowUserError("no_component_change_for_multiple_products"); ThrowUserError("no_component_change_for_multiple_products");
} }
$comp_id = get_component_id($prod_id, $component =
$cgi->param('component')); Bugzilla::Component::check_component($product, scalar $cgi->param('component'));
$comp_id || ThrowCodeError("invalid_component",
{name => $cgi->param('component'), # This parameter is required later when checking fields the user can change.
product => $cgi->param('product')}); $cgi->param('component_id', $component->id);
$cgi->param('component_id', $comp_id);
DoComma(); DoComma();
$::query .= "component_id = ?"; $::query .= "component_id = ?";
push(@values, $comp_id); push(@values, $component->id);
} }
# If this installation uses bug aliases, and the user is changing the alias, # If this installation uses bug aliases, and the user is changing the alias,
...@@ -1447,14 +1442,14 @@ if ($prod_changed && Param("strict_isolation")) { ...@@ -1447,14 +1442,14 @@ if ($prod_changed && Param("strict_isolation")) {
my $sth_bug = $dbh->prepare("SELECT assigned_to, qa_contact my $sth_bug = $dbh->prepare("SELECT assigned_to, qa_contact
FROM bugs FROM bugs
WHERE bug_id = ?"); WHERE bug_id = ?");
my $prod_name = get_product_name($prod_id);
foreach my $id (@idlist) { foreach my $id (@idlist) {
$sth_cc->execute($id); $sth_cc->execute($id);
my @blocked_cc = (); my @blocked_cc = ();
while (my ($pid) = $sth_cc->fetchrow_array) { while (my ($pid) = $sth_cc->fetchrow_array) {
$usercache{$pid} ||= Bugzilla::User->new($pid); $usercache{$pid} ||= Bugzilla::User->new($pid);
my $cc_user = $usercache{$pid}; my $cc_user = $usercache{$pid};
if (!$cc_user->can_edit_product($prod_id)) { if (!$cc_user->can_edit_product($product->id)) {
push (@blocked_cc, $cc_user->login); push (@blocked_cc, $cc_user->login);
} }
} }
...@@ -1462,28 +1457,28 @@ if ($prod_changed && Param("strict_isolation")) { ...@@ -1462,28 +1457,28 @@ if ($prod_changed && Param("strict_isolation")) {
ThrowUserError('invalid_user_group', ThrowUserError('invalid_user_group',
{'users' => \@blocked_cc, {'users' => \@blocked_cc,
'bug_id' => $id, 'bug_id' => $id,
'product' => $prod_name}); 'product' => $product->name});
} }
$sth_bug->execute($id); $sth_bug->execute($id);
my ($assignee, $qacontact) = $sth_bug->fetchrow_array; my ($assignee, $qacontact) = $sth_bug->fetchrow_array;
if (!$assignee_checked) { if (!$assignee_checked) {
$usercache{$assignee} ||= Bugzilla::User->new($assignee); $usercache{$assignee} ||= Bugzilla::User->new($assignee);
my $assign_user = $usercache{$assignee}; my $assign_user = $usercache{$assignee};
if (!$assign_user->can_edit_product($prod_id)) { if (!$assign_user->can_edit_product($product->id)) {
ThrowUserError('invalid_user_group', ThrowUserError('invalid_user_group',
{'users' => $assign_user->login, {'users' => $assign_user->login,
'bug_id' => $id, 'bug_id' => $id,
'product' => $prod_name}); 'product' => $product->name});
} }
} }
if (!$qacontact_checked && $qacontact) { if (!$qacontact_checked && $qacontact) {
$usercache{$qacontact} ||= Bugzilla::User->new($qacontact); $usercache{$qacontact} ||= Bugzilla::User->new($qacontact);
my $qa_user = $usercache{$qacontact}; my $qa_user = $usercache{$qacontact};
if (!$qa_user->can_edit_product($prod_id)) { if (!$qa_user->can_edit_product($product->id)) {
ThrowUserError('invalid_user_group', ThrowUserError('invalid_user_group',
{'users' => $qa_user->login, {'users' => $qa_user->login,
'bug_id' => $id, 'bug_id' => $id,
'product' => $prod_name}); 'product' => $product->name});
} }
} }
} }
...@@ -1498,13 +1493,13 @@ if ($prod_changed && Param("strict_isolation")) { ...@@ -1498,13 +1493,13 @@ if ($prod_changed && Param("strict_isolation")) {
foreach my $id (@idlist) { foreach my $id (@idlist) {
my $query = $basequery; my $query = $basequery;
my @bug_values = @values; my @bug_values = @values;
my $bug_obj = new Bugzilla::Bug($id, $whoid); my $old_bug_obj = new Bugzilla::Bug($id, $whoid);
if ($cgi->param('knob') eq 'reassignbycomponent') { if ($cgi->param('knob') eq 'reassignbycomponent') {
# We have to check whether the bug is moved to another product # We have to check whether the bug is moved to another product
# and/or component before reassigning. If $comp_id is defined, # and/or component before reassigning. If $component is defined,
# use it; else use the product/component the bug is already in. # use it; else use the product/component the bug is already in.
my $new_comp_id = $comp_id || $bug_obj->{'component_id'}; my $new_comp_id = $component ? $component->id : $old_bug_obj->{'component_id'};
$assignee = $dbh->selectrow_array('SELECT initialowner $assignee = $dbh->selectrow_array('SELECT initialowner
FROM components FROM components
WHERE components.id = ?', WHERE components.id = ?',
...@@ -1540,7 +1535,7 @@ foreach my $id (@idlist) { ...@@ -1540,7 +1535,7 @@ foreach my $id (@idlist) {
"keyworddefs READ", "groups READ", "attachments READ", "keyworddefs READ", "groups READ", "attachments READ",
"group_control_map AS oldcontrolmap READ", "group_control_map AS oldcontrolmap READ",
"group_control_map AS newcontrolmap READ", "group_control_map AS newcontrolmap READ",
"group_control_map READ", "email_setting READ"); "group_control_map READ", "email_setting READ", "classifications READ");
# It may sound crazy to set %formhash for each bug as $cgi->param() # It may sound crazy to set %formhash for each bug as $cgi->param()
# will not change, but %formhash is modified below and we prefer # will not change, but %formhash is modified below and we prefer
...@@ -1585,7 +1580,7 @@ foreach my $id (@idlist) { ...@@ -1585,7 +1580,7 @@ foreach my $id (@idlist) {
my $vars; my $vars;
if ($col eq 'component_id') { if ($col eq 'component_id') {
# Display the component name # Display the component name
$vars->{'oldvalue'} = get_component_name($oldhash{$col}); $vars->{'oldvalue'} = $old_bug_obj->component;
$vars->{'newvalue'} = $cgi->param('component'); $vars->{'newvalue'} = $cgi->param('component');
$vars->{'field'} = 'component'; $vars->{'field'} = 'component';
} elsif ($col eq 'assigned_to' || $col eq 'qa_contact') { } elsif ($col eq 'assigned_to' || $col eq 'qa_contact') {
...@@ -2048,6 +2043,7 @@ foreach my $id (@idlist) { ...@@ -2048,6 +2043,7 @@ foreach my $id (@idlist) {
# and then generate any necessary bug activity entries by seeing # and then generate any necessary bug activity entries by seeing
# what has changed since before we wrote out the new values. # what has changed since before we wrote out the new values.
# #
my $new_bug_obj = new Bugzilla::Bug($id, $whoid);
my @newvalues = SnapShotBug($id); my @newvalues = SnapShotBug($id);
my %newhash; my %newhash;
$i = 0; $i = 0;
...@@ -2085,8 +2081,8 @@ foreach my $id (@idlist) { ...@@ -2085,8 +2081,8 @@ foreach my $id (@idlist) {
$col = 'product'; $col = 'product';
} }
if ($col eq 'component_id') { if ($col eq 'component_id') {
$old = get_component_name($old); $old = $old_bug_obj->component;
$new = get_component_name($new); $new = $new_bug_obj->component;
$col = 'component'; $col = 'component';
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
# Rights Reserved. # Rights Reserved.
# #
# Contributor(s): Myk Melez <myk@mozilla.org> # Contributor(s): Myk Melez <myk@mozilla.org>
# Frédéric Buclin <LpSolit@gmail.com>
################################################################################ ################################################################################
# Script Initialization # Script Initialization
...@@ -33,6 +34,8 @@ use Bugzilla; ...@@ -33,6 +34,8 @@ use Bugzilla;
use Bugzilla::Flag; use Bugzilla::Flag;
use Bugzilla::FlagType; use Bugzilla::FlagType;
use Bugzilla::User; use Bugzilla::User;
use Bugzilla::Product;
use Bugzilla::Component;
# Make sure the user is logged in. # Make sure the user is logged in.
my $user = Bugzilla->login(); my $user = Bugzilla->login();
...@@ -174,23 +177,17 @@ sub queue { ...@@ -174,23 +177,17 @@ sub queue {
# Filter results by exact product or component. # Filter results by exact product or component.
if (defined $cgi->param('product') && $cgi->param('product') ne "") { if (defined $cgi->param('product') && $cgi->param('product') ne "") {
my $product_id = get_product_id($cgi->param('product')); my $product = Bugzilla::Product::check_product(scalar $cgi->param('product'));
if ($product_id) { push(@criteria, "bugs.product_id = " . $product->id);
push(@criteria, "bugs.product_id = $product_id"); push(@excluded_columns, 'product') unless $cgi->param('do_union');
push(@excluded_columns, 'product') unless $cgi->param('do_union'); if (defined $cgi->param('component') && $cgi->param('component') ne "") {
if (defined $cgi->param('component') && $cgi->param('component') ne "") { my $component =
my $component_id = get_component_id($product_id, $cgi->param('component')); Bugzilla::Component::check_component($product, scalar $cgi->param('component'));
if ($component_id) { push(@criteria, "bugs.component_id = " . $component->id);
push(@criteria, "bugs.component_id = $component_id"); push(@excluded_columns, 'component') unless $cgi->param('do_union');
push(@excluded_columns, 'component') unless $cgi->param('do_union');
}
else { ThrowUserError("component_not_valid", { 'product' => $cgi->param('product'),
'name' => $cgi->param('component') }) }
}
} }
else { ThrowUserError("product_doesnt_exist", { 'product' => $cgi->param('product') }) }
} }
# Filter results by flag types. # Filter results by flag types.
my $form_type = $cgi->param('type'); my $form_type = $cgi->param('type');
if (defined $form_type && !grep($form_type eq $_, ("", "all"))) { if (defined $form_type && !grep($form_type eq $_, ("", "all"))) {
......
...@@ -169,12 +169,7 @@ ...@@ -169,12 +169,7 @@
[% title = "Invalid Column Name" %] [% title = "Invalid Column Name" %]
The custom sort order specified in your form submission contains an The custom sort order specified in your form submission contains an
invalid column name <em>[% fragment FILTER html %]</em>. invalid column name <em>[% fragment FILTER html %]</em>.
[% ELSIF error == "invalid_component" %]
[% title = "Invalid Component" %]
The [% name FILTER html %] component doesn't exist in the
[% product FILTER html %] product.
[% ELSIF error == "invalid_dimensions" %] [% ELSIF error == "invalid_dimensions" %]
[% title = "Invalid Dimensions" %] [% title = "Invalid Dimensions" %]
The width or height specified is not a positive integer. The width or height specified is not a positive integer.
...@@ -228,11 +223,7 @@ ...@@ -228,11 +223,7 @@
for flag ID #[% id FILTER html %] for flag ID #[% id FILTER html %]
[% END %] [% END %]
is invalid. is invalid.
[% ELSIF error == "flag_type_component_nonexistent" %]
The component <em>[% name FILTER html %]</em> does not exist
in the product <em>[% product FILTER html %]</em>.
[% ELSIF error == "flag_type_component_without_product" %] [% ELSIF error == "flag_type_component_without_product" %]
A component was selected without a product being selected. A component was selected without a product being selected.
...@@ -246,10 +237,7 @@ ...@@ -246,10 +237,7 @@
[% ELSIF error == "flag_type_nonexistent" %] [% ELSIF error == "flag_type_nonexistent" %]
There is no flag type with the ID <em>[% id FILTER html %]</em>. There is no flag type with the ID <em>[% id FILTER html %]</em>.
[% ELSIF error == "flag_type_product_nonexistent" %]
The product <em>[% product FILTER html %]</em> does not exist.
[% ELSIF error == "flag_type_target_type_invalid" %] [% ELSIF error == "flag_type_target_type_invalid" %]
The target type was neither <em>[% terms.bug %]</em> nor <em>attachment</em> The target type was neither <em>[% terms.bug %]</em> nor <em>attachment</em>
but rather <em>[% target_type FILTER html %]</em>. but rather <em>[% target_type FILTER html %]</em>.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment