Commit 7dbcf793 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 365129: When moving a bug to another product and the target product has only…

Bug 365129: When moving a bug to another product and the target product has only one component, version or target milestone, automatically select them instead of throwing an error - Patch by Fré©ric Buclin <LpSolit@gmail.com> r=bkor a=justdave
parent 685d0e4e
...@@ -270,11 +270,6 @@ if ($cgi->cookie("BUGLIST") && defined $cgi->param('id')) { ...@@ -270,11 +270,6 @@ if ($cgi->cookie("BUGLIST") && defined $cgi->param('id')) {
$vars->{'bug_list'} = \@bug_list; $vars->{'bug_list'} = \@bug_list;
} }
foreach my $field_name ('product', 'component', 'version') {
defined($cgi->param($field_name))
|| ThrowCodeError('undefined_field', { field => $field_name });
}
# This function checks if there is a comment required for a specific # This function checks if there is a comment required for a specific
# function and tests, if the comment was given. # function and tests, if the comment was given.
# If comments are required for functions is defined by params. # If comments are required for functions is defined by params.
...@@ -314,6 +309,10 @@ if (defined $cgi->param('id')) { ...@@ -314,6 +309,10 @@ if (defined $cgi->param('id')) {
undef, $cgi->param('id')); undef, $cgi->param('id'));
} }
# At this point, the product must be defined, even if set to "dontchange".
defined($cgi->param('product'))
|| ThrowCodeError('undefined_field', { field => 'product' });
if (((defined $cgi->param('id') && $cgi->param('product') ne $oldproduct) if (((defined $cgi->param('id') && $cgi->param('product') ne $oldproduct)
|| (!$cgi->param('id') || (!$cgi->param('id')
&& $cgi->param('product') ne $cgi->param('dontchange'))) && $cgi->param('product') ne $cgi->param('dontchange')))
...@@ -361,17 +360,23 @@ if (((defined $cgi->param('id') && $cgi->param('product') ne $oldproduct) ...@@ -361,17 +360,23 @@ if (((defined $cgi->param('id') && $cgi->param('product') ne $oldproduct)
# #
my @version_names = map($_->name, @{$prod_obj->versions}); my @version_names = map($_->name, @{$prod_obj->versions});
my @component_names = map($_->name, @{$prod_obj->components}); my @component_names = map($_->name, @{$prod_obj->components});
my $vok = lsearch(\@version_names, $cgi->param('version')) >= 0; my $vok = 0;
my $cok = lsearch(\@component_names, $cgi->param('component')) >= 0; if (defined $cgi->param('version')) {
$vok = lsearch(\@version_names, $cgi->param('version')) >= 0;
}
my $cok = 0;
if (defined $cgi->param('component')) {
$cok = lsearch(\@component_names, $cgi->param('component')) >= 0;
}
my $mok = 1; # so it won't affect the 'if' statement if milestones aren't used my $mok = 1; # so it won't affect the 'if' statement if milestones aren't used
my @milestone_names = (); my @milestone_names = ();
if ( Bugzilla->params->{"usetargetmilestone"} ) { if ( Bugzilla->params->{"usetargetmilestone"} ) {
defined($cgi->param('target_milestone'))
|| ThrowCodeError('undefined_field', { field => 'target_milestone' });
@milestone_names = map($_->name, @{$prod_obj->milestones}); @milestone_names = map($_->name, @{$prod_obj->milestones});
$mok = lsearch(\@milestone_names, $cgi->param('target_milestone')) >= 0; $mok = 0;
if (defined $cgi->param('target_milestone')) {
$mok = lsearch(\@milestone_names, $cgi->param('target_milestone')) >= 0;
}
} }
# We cannot be sure if the component is the same by only checking $cok; the # We cannot be sure if the component is the same by only checking $cok; the
...@@ -413,10 +418,18 @@ if (((defined $cgi->param('id') && $cgi->param('product') ne $oldproduct) ...@@ -413,10 +418,18 @@ if (((defined $cgi->param('id') && $cgi->param('product') ne $oldproduct)
if ($vok) { if ($vok) {
$defaults{'version'} = $cgi->param('version'); $defaults{'version'} = $cgi->param('version');
} }
elsif (scalar(@version_names) == 1) {
$defaults{'version'} = $version_names[0];
}
$vars->{'components'} = \@component_names; $vars->{'components'} = \@component_names;
if ($cok) { if ($cok) {
$defaults{'component'} = $cgi->param('component'); $defaults{'component'} = $cgi->param('component');
} }
elsif (scalar(@component_names) == 1) {
$defaults{'component'} = $component_names[0];
}
if (Bugzilla->params->{"usetargetmilestone"}) { if (Bugzilla->params->{"usetargetmilestone"}) {
$vars->{'use_target_milestone'} = 1; $vars->{'use_target_milestone'} = 1;
$vars->{'milestones'} = \@milestone_names; $vars->{'milestones'} = \@milestone_names;
...@@ -426,7 +439,6 @@ if (((defined $cgi->param('id') && $cgi->param('product') ne $oldproduct) ...@@ -426,7 +439,6 @@ if (((defined $cgi->param('id') && $cgi->param('product') ne $oldproduct)
$defaults{'target_milestone'} = $dbh->selectrow_array( $defaults{'target_milestone'} = $dbh->selectrow_array(
q{SELECT defaultmilestone FROM products q{SELECT defaultmilestone FROM products
WHERE name = ?}, undef, $prod); WHERE name = ?}, undef, $prod);
;
} }
} }
else { else {
...@@ -447,6 +459,10 @@ if (((defined $cgi->param('id') && $cgi->param('product') ne $oldproduct) ...@@ -447,6 +459,10 @@ if (((defined $cgi->param('id') && $cgi->param('product') ne $oldproduct)
} }
} }
# At this point, the component must be defined, even if set to "dontchange".
defined($cgi->param('component'))
|| ThrowCodeError('undefined_field', { field => 'component' });
# Confirm that the reporter of the current bug can access the bug we are duping to. # Confirm that the reporter of the current bug can access the bug we are duping to.
sub DuplicateUserConfirm { sub DuplicateUserConfirm {
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
......
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