process_bug.cgi 24.4 KB
Newer Older
1
#!/usr/bin/perl -wT
2
# -*- Mode: perl; indent-tabs-mode: nil -*-
terry%netscape.com's avatar
terry%netscape.com committed
3
#
4 5 6 7 8 9 10 11 12 13
# 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.
#
terry%netscape.com's avatar
terry%netscape.com committed
14
# The Original Code is the Bugzilla Bug Tracking System.
15
#
terry%netscape.com's avatar
terry%netscape.com committed
16
# The Initial Developer of the Original Code is Netscape Communications
17 18 19 20
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
terry%netscape.com's avatar
terry%netscape.com committed
21
# Contributor(s): Terry Weissman <terry@mozilla.org>
22
#                 Dan Mosedale <dmose@mozilla.org>
23
#                 Dave Miller <justdave@syndicomm.com>
24
#                 Christopher Aillon <christopher@aillon.com>
25
#                 Myk Melez <myk@mozilla.org>
26
#                 Jeff Hedlund <jeff.hedlund@matrixsi.com>
27
#                 Frédéric Buclin <LpSolit@gmail.com>
28
#                 Lance Larsh <lance.larsh@oracle.com>
29
#                 Akamai Technologies <bugzilla-dev@akamai.com>
30
#                 Max Kanat-Alexander <mkanat@bugzilla.org>
terry%netscape.com's avatar
terry%netscape.com committed
31

32 33 34 35 36 37 38 39 40 41 42 43
# Implementation notes for this file:
#
# 1) the 'id' form parameter is validated early on, and if it is not a valid
# bugid an error will be reported, so it is OK for later code to simply check
# for a defined form 'id' value, and it can assume a valid bugid.
#
# 2) If the 'id' form parameter is not defined (after the initial validation),
# then we are processing multiple bugs, and @idlist will contain the ids.
#
# 3) If we are processing just the one id, then it is stored in @idlist for
# later processing.

44 45
use strict;

46
use lib qw(. lib);
47

48
use Bugzilla;
49
use Bugzilla::Constants;
50
use Bugzilla::Bug;
51
use Bugzilla::BugMail;
52
use Bugzilla::Mailer;
53
use Bugzilla::User;
54
use Bugzilla::Util;
55
use Bugzilla::Error;
56
use Bugzilla::Field;
57
use Bugzilla::Product;
58
use Bugzilla::Component;
59
use Bugzilla::Keyword;
60
use Bugzilla::Flag;
61
use Bugzilla::Status;
62

63 64
use Storable qw(dclone);

65
my $user = Bugzilla->login(LOGIN_REQUIRED);
66

67
my $cgi = Bugzilla->cgi;
68
my $dbh = Bugzilla->dbh;
69
my $template = Bugzilla->template;
70
my $vars = {};
71
$vars->{'valid_keywords'} = [map($_->name, Bugzilla::Keyword->get_all)];
72
$vars->{'use_keywords'} = 1 if Bugzilla::Keyword::keyword_count();
73

74 75 76 77
######################################################################
# Subroutines
######################################################################

78 79 80 81 82 83 84 85 86 87 88 89 90 91
# Used to send email when an update is done.
sub send_results {
    my ($bug_id, $vars) = @_;
    my $template = Bugzilla->template;
    if (Bugzilla->usage_mode == USAGE_MODE_EMAIL) {
         Bugzilla::BugMail::Send($bug_id, $vars->{'mailrecipients'});
    }
    else {
        $template->process("bug/process/results.html.tmpl", $vars)
            || ThrowTemplateError($template->error());
    }
    $vars->{'header_done'} = 1;
}

92 93 94
# Tells us whether or not a field should be changed by process_bug, by
# checking that it's defined and not set to dontchange.
sub should_set {
95
    # check_defined is used for fields where there's another field
96 97 98 99
    # whose name starts with "defined_" and then the field name--it's used
    # to know when we did things like empty a multi-select or deselect
    # a checkbox.
    my ($field, $check_defined) = @_;
100
    my $cgi = Bugzilla->cgi;
101 102
    if ( defined $cgi->param($field) 
         || ($check_defined && defined $cgi->param("defined_$field")) )
103 104 105 106 107 108
    {
        return 1;
    }
    return 0;
}

109 110 111 112
######################################################################
# Begin Data/Security Validation
######################################################################

113 114
# Create a list of objects for all bugs being modified in this request.
my @bug_objects;
115 116 117 118 119 120 121
if (defined $cgi->param('id')) {
  my $id = $cgi->param('id');
  ValidateBugID($id);

  # Store the validated, and detainted id back in the cgi data, as
  # lots of later code will need it, and will obtain it from there
  $cgi->param('id', $id);
122
  push(@bug_objects, new Bugzilla::Bug($id));
123
} else {
124
    my @ids;
125
    foreach my $i ($cgi->param()) {
126
        if ($i =~ /^id_([1-9][0-9]*)/) {
127 128
            my $id = $1;
            ValidateBugID($id);
129
            push(@ids, $id);
130
        }
131
    }
132
    @bug_objects = @{Bugzilla::Bug->new_from_list(\@ids)};
133 134
}

135
# Make sure there are bugs to process.
136
scalar(@bug_objects) || ThrowUserError("no_bugs_chosen", {action => 'modify'});
137

138
my $first_bug = $bug_objects[0]; # Used when we're only updating a single bug.
139

140 141 142 143 144 145 146 147
# Delete any parameter set to 'dontchange'.
if (defined $cgi->param('dontchange')) {
    foreach my $name ($cgi->param) {
        next if $name eq 'dontchange'; # But don't delete dontchange itself!
        if ($cgi->param($name) eq $cgi->param('dontchange')) {
            $cgi->delete($name);
        }
    }
148 149
}

150 151
# do a match on the fields if applicable

152 153
# The order of these function calls is important, as Flag::validate
# assumes User::match_field has ensured that the values
154
# in the requestee fields are legitimate user email addresses.
155
&Bugzilla::User::match_field($cgi, {
156 157 158 159
    'qa_contact'                => { 'type' => 'single' },
    'newcc'                     => { 'type' => 'multi'  },
    'masscc'                    => { 'type' => 'multi'  },
    'assigned_to'               => { 'type' => 'single' },
160
    '^requestee(_type)?-(\d+)$' => { 'type' => 'multi'  },
161
});
162 163 164 165

# Validate flags in all cases. validate() should not detect any
# reference to flags if $cgi->param('id') is undefined.
Bugzilla::Flag::validate($cgi, $cgi->param('id'));
166

167 168 169 170
######################################################################
# End Data/Security Validation
######################################################################

171
print $cgi->header() unless Bugzilla->usage_mode == USAGE_MODE_EMAIL;
172

173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
# Check for a mid-air collision. Currently this only works when updating
# an individual bug.
if (defined $cgi->param('delta_ts')
    && $cgi->param('delta_ts') ne $first_bug->delta_ts)
{
    ($vars->{'operations'}) =
        Bugzilla::Bug::GetBugActivity($first_bug->id, undef,
                                      scalar $cgi->param('delta_ts'));

    $vars->{'title_tag'} = "mid_air";
    
    ThrowCodeError('undefined_field', { field => 'longdesclength' })
        if !defined $cgi->param('longdesclength');

    $vars->{'start_at'} = $cgi->param('longdesclength');
    # Always sort midair collision comments oldest to newest,
    # regardless of the user's personal preference.
    $vars->{'comments'} = Bugzilla::Bug::GetComments($first_bug->id,
                                                     "oldest_to_newest");
    $vars->{'bug'} = $first_bug;
    
    # Warn the user about the mid-air collision and ask them what to do.
    $template->process("bug/process/midair.html.tmpl", $vars)
      || ThrowTemplateError($template->error());
    exit;
198
}
199

200 201
$vars->{'title_tag'} = "bug_processed";

202
# Set up the vars for navigational <link> elements
203
my @bug_list;
204
if ($cgi->cookie("BUGLIST") && defined $cgi->param('id')) {
205
    @bug_list = split(/:/, $cgi->cookie("BUGLIST"));
206 207 208
    $vars->{'bug_list'} = \@bug_list;
}

209 210 211 212 213 214
# For each bug, we have to check if the user can edit the bug the product
# is currently in, before we allow them to change anything.
foreach my $bug (@bug_objects) {
    if (!Bugzilla->user->can_edit_product($bug->product_obj->id) ) {
        ThrowUserError("product_edit_denied",
                      { product => $bug->product });
215
    }
216
}
217

218 219 220 221
# For security purposes, and because lots of other checks depend on it,
# we set the product first before anything else.
my $product_change; # Used only for strict_isolation checks, right now.
if (should_set('product')) {
222 223
    foreach my $b (@bug_objects) {
        my $changed = $b->set_product(scalar $cgi->param('product'),
224 225 226
            { component        => scalar $cgi->param('component'),
              version          => scalar $cgi->param('version'),
              target_milestone => scalar $cgi->param('target_milestone'),
227 228 229 230
              change_confirmed => scalar $cgi->param('confirm_product_change'),
              other_bugs => \@bug_objects,
            });
        $product_change ||= $changed;
231 232
    }
}
233
        
234 235 236 237 238 239 240 241 242 243 244 245 246 247
# strict_isolation checks mean that we should set the groups
# immediately after changing the product.
foreach my $b (@bug_objects) {
    foreach my $group (@{$b->product_obj->groups_valid}) {
        my $gid = $group->id;
        if (should_set("bit-$gid", 1)) {
            # Check ! first to avoid having to check defined below.
            if (!$cgi->param("bit-$gid")) {
                $b->remove_group($gid);
            }
            # "== 1" is important because mass-change uses -1 to mean
            # "don't change this restriction"
            elsif ($cgi->param("bit-$gid") == 1) {
                $b->add_group($gid);
248 249
            }
        }
terry%netscape.com's avatar
terry%netscape.com committed
250 251 252
    }
}

253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
if ($cgi->param('id') && (defined $cgi->param('dependson')
                          || defined $cgi->param('blocked')) )
{
    $first_bug->set_dependencies(scalar $cgi->param('dependson'),
                                 scalar $cgi->param('blocked'));
}
# Right now, you can't modify dependencies on a mass change.
else {
    $cgi->delete('dependson');
    $cgi->delete('blocked');
}

my $any_keyword_changes;
if (defined $cgi->param('keywords')) {
    foreach my $b (@bug_objects) {
        my $return =
            $b->modify_keywords(scalar $cgi->param('keywords'),
                                scalar $cgi->param('keywordaction'));
        $any_keyword_changes ||= $return;
    }
}

275 276 277
# Component, target_milestone, and version are in here just in case
# the 'product' field wasn't defined in the CGI. It doesn't hurt to set
# them twice.
278 279 280 281 282 283
my @set_fields = qw(op_sys rep_platform priority bug_severity
                    component target_milestone version
                    bug_file_loc status_whiteboard short_desc
                    deadline remaining_time estimated_time);
push(@set_fields, 'assigned_to') if !$cgi->param('set_default_assignee');
push(@set_fields, 'qa_contact')  if !$cgi->param('set_default_qa_contact');
284
my @custom_fields = Bugzilla->get_fields({custom => 1, obsolete => 0});
285

286 287 288 289 290 291 292
my %methods = (
    bug_severity => 'set_severity',
    rep_platform => 'set_platform',
    short_desc   => 'set_summary',
    bug_file_loc => 'set_url',
);
foreach my $b (@bug_objects) {
293 294 295 296 297 298 299
    if (should_set('comment') || $cgi->param('work_time')) {
        # Add a comment as needed to each bug. This is done early because
        # there are lots of things that want to check if we added a comment.
        $b->add_comment(scalar($cgi->param('comment')),
            { isprivate => scalar $cgi->param('commentprivacy'),
              work_time => scalar $cgi->param('work_time') });
    }
300
    foreach my $field_name (@set_fields) {
301
        if (should_set($field_name)) {
302 303 304 305 306
            my $method = $methods{$field_name};
            $method ||= "set_" . $field_name;
            $b->$method($cgi->param($field_name));
        }
    }
307 308
    $b->reset_assigned_to if $cgi->param('set_default_assignee');
    $b->reset_qa_contact  if $cgi->param('set_default_qa_contact');
309

310 311 312 313 314 315
    # And set custom fields.
    foreach my $field (@custom_fields) {
        my $fname = $field->name;
        if (should_set($fname, 1)) {
            $b->set_custom_field($field, [$cgi->param($fname)]);
        }
316
    }
317 318
}

319
# Certain changes can only happen on individual bugs, never on mass-changes.
320
if (defined $cgi->param('id')) {
321 322 323
    # Since aliases are unique (like bug numbers), they can only be changed
    # for one bug at a time.
    if (Bugzilla->params->{"usebugaliases"} && defined $cgi->param('alias')) {
324
        $first_bug->set_alias($cgi->param('alias'));
325 326 327
    }

    # reporter_accessible and cclist_accessible--these are only set if
328 329
    # the user can change them and they appear on the page.
    if (should_set('cclist_accessible', 1)) {
330
        $first_bug->set_cclist_accessible($cgi->param('cclist_accessible'))
331 332
    }
    if (should_set('reporter_accessible', 1)) {
333
        $first_bug->set_reporter_accessible($cgi->param('reporter_accessible'))
334
    }
335 336 337 338 339 340
    
    # You can only mark/unmark comments as private on single bugs. If
    # you're not in the insider group, this code won't do anything.
    foreach my $field (grep(/^defined_isprivate/, $cgi->param())) {
        $field =~ /(\d+)$/;
        my $comment_id = $1;
341 342
        $first_bug->set_comment_is_private($comment_id,
                                           $cgi->param("isprivate_$comment_id"));
343 344
    }
}
345

346 347 348 349
# We need to check the addresses involved in a CC change before we touch 
# any bugs. What we'll do here is formulate the CC data into two arrays of
# users involved in this CC change.  Then those arrays can be used later 
# on for the actual change.
350
my (@cc_add, @cc_remove);
351 352 353 354
if (defined $cgi->param('newcc')
    || defined $cgi->param('addselfcc')
    || defined $cgi->param('removecc')
    || defined $cgi->param('masscc')) {
355
        
356 357 358
    # If masscc is defined, then we came from buglist and need to either add or
    # remove cc's... otherwise, we came from bugform and may need to do both.
    my ($cc_add, $cc_remove) = "";
359 360 361 362 363
    if (defined $cgi->param('masscc')) {
        if ($cgi->param('ccaction') eq 'add') {
            $cc_add = join(' ',$cgi->param('masscc'));
        } elsif ($cgi->param('ccaction') eq 'remove') {
            $cc_remove = join(' ',$cgi->param('masscc'));
364 365
        }
    } else {
366
        $cc_add = join(' ',$cgi->param('newcc'));
367 368
        # We came from bug_form which uses a select box to determine what cc's
        # need to be removed...
369 370
        if (defined $cgi->param('removecc') && $cgi->param('cc')) {
            $cc_remove = join (",", $cgi->param('cc'));
371 372 373
        }
    }

374 375 376 377 378 379 380 381
    push(@cc_add, split(/[\s,]+/, $cc_add)) if $cc_add;
    push(@cc_add, Bugzilla->user) if $cgi->param('addselfcc');

    push(@cc_remove, split(/[\s,]+/, $cc_remove)) if $cc_remove;
}

foreach my $b (@bug_objects) {
    $b->remove_cc($_) foreach @cc_remove;
382
    $b->add_cc($_) foreach @cc_add;
383 384 385 386 387 388 389 390 391
    # Theoretically you could move a product without ever specifying
    # a new assignee or qa_contact, or adding/removing any CCs. So,
    # we have to check that the current assignee, qa, and CCs are still
    # valid if we've switched products, under strict_isolation. We can only
    # do that here. There ought to be some better way to do this,
    # architecturally, but I haven't come up with it.
    if ($product_change) {
        $b->_check_strict_isolation();
    }
392 393
}

394 395
my $move_action = $cgi->param('action') || '';
if ($move_action eq Bugzilla->params->{'move-button-text'}) {
396 397 398 399 400
    Bugzilla->params->{'move-enabled'} || ThrowUserError("move_bugs_disabled");

    $user->is_mover || ThrowUserError("auth_failure", {action => 'move',
                                                       object => 'bugs'});

401
    $dbh->bz_start_transaction();
402 403 404 405 406

    # First update all moved bugs.
    foreach my $bug (@bug_objects) {
        $bug->add_comment(scalar $cgi->param('comment'),
                          { type => CMT_MOVED_TO, extra_data => $user->login });
407
    }
408 409 410 411 412 413
    # Don't export the new status and resolution. We want the current ones.
    local $Storable::forgive_me = 1;
    my $bugs = dclone(\@bug_objects);
    foreach my $bug (@bug_objects) {
        my ($status, $resolution) = $bug->get_new_status_and_resolution('move');
        $bug->set_status($status);
414 415 416 417 418 419 420
        # We don't use set_resolution here because the MOVED resolution is
        # special and is normally rejected by set_resolution.
        $bug->{resolution} = $resolution;
        # That means that we need to clear dups manually. Eventually this
        # bug-moving code will all be inside Bugzilla::Bug, so it's OK
        # to call an internal function here.
        $bug->_clear_dup_id;
421
    }
422
    $_->update() foreach @bug_objects;
423
    $dbh->bz_commit_transaction();
424 425

    # Now send emails.
426
    foreach my $bug (@bug_objects) {
427
        $vars->{'mailrecipients'} = { 'changer' => $user->login };
428
        $vars->{'id'} = $bug->id;
429
        $vars->{'type'} = "move";
430
        send_results($bug->id, $vars);
431
    }
432 433 434 435 436 437 438
    # Prepare and send all data about these bugs to the new database
    my $to = Bugzilla->params->{'move-to-address'};
    $to =~ s/@/\@/;
    my $from = Bugzilla->params->{'moved-from-address'};
    $from =~ s/@/\@/;
    my $msg = "To: $to\n";
    $msg .= "From: Bugzilla <" . $from . ">\n";
439 440
    $msg .= "Subject: Moving bug(s) " . join(', ', map($_->id, @bug_objects))
            . "\n\n";
441 442 443 444 445 446

    my @fieldlist = (Bugzilla::Bug->fields, 'group', 'long_desc',
                     'attachment', 'attachmentdata');
    my %displayfields;
    foreach (@fieldlist) {
        $displayfields{$_} = 1;
447
    }
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464

    $template->process("bug/show.xml.tmpl", { bugs => $bugs,
                                              displayfields => \%displayfields,
                                            }, \$msg)
      || ThrowTemplateError($template->error());

    $msg .= "\n";
    MessageToMTA($msg);

    # End the response page.
    unless (Bugzilla->usage_mode == USAGE_MODE_EMAIL) {
        $template->process("bug/navigate.html.tmpl", $vars)
            || ThrowTemplateError($template->error());
        $template->process("global/footer.html.tmpl", $vars)
            || ThrowTemplateError($template->error());
    }
    exit;
465
}
466

467

468 469 470 471 472
# You cannot mark bugs as duplicates when changing several bugs at once
# (because currently there is no way to check for duplicate loops in that
# situation).
if (!$cgi->param('id') && $cgi->param('dup_id')) {
    ThrowUserError('dupe_not_allowed');
473 474
}

475 476 477 478 479 480
# Set the status, resolution, and dupe_of (if needed). This has to be done
# down here, because the validity of status changes depends on other fields,
# such as Target Milestone.
foreach my $b (@bug_objects) {
    if (should_set('knob')) {
        # First, get the correct resolution <select>, in case there is more
481 482
        # than one open -> closed transition allowed. Allow to fallback to
        # 'resolution' (useful when called from email_in.pl).
483 484 485 486
        my $knob = $cgi->param('knob');
        my $status = new Bugzilla::Status({name => $knob});
        my $resolution;
        if ($status) {
487 488
            $resolution = $cgi->param('resolution_knob_' . $status->id)
                          || $cgi->param('resolution');
489 490 491 492 493 494 495
        }
        else {
            $resolution = $cgi->param('resolution_knob_change_resolution');
        }
        
        # Translate the knob values into new status and resolution values.
        $b->process_knob($knob, $resolution, scalar $cgi->param('dup_id'));
496 497 498
    }
}

499 500 501 502
##############################
# Do Actual Database Updates #
##############################
foreach my $bug (@bug_objects) {
503
    $dbh->bz_start_transaction();
504

505
    my $timestamp = $dbh->selectrow_array(q{SELECT NOW()});
506
    my $changes = $bug->update($timestamp);
507 508 509 510 511 512 513 514

    my %notify_deps;
    if ($changes->{'bug_status'}) {
        my ($old_status, $new_status) = @{ $changes->{'bug_status'} };
        
        # If this bug has changed from opened to closed or vice-versa,
        # then all of the bugs we block need to be notified.
        if (is_open_state($old_status) ne is_open_state($new_status)) {
515
            $notify_deps{$_} = 1 foreach (@{$bug->blocked});
516 517 518 519 520 521 522 523 524
        }
        
        # We may have zeroed the remaining time, if we moved into a closed
        # status, so we should inform the user about that.
        if (!is_open_state($new_status) && $changes->{'remaining_time'}) {
            $vars->{'message'} = "remaining_time_zeroed"
              if Bugzilla->user->in_group(Bugzilla->params->{'timetrackinggroup'});
        }
    }
525

526
    $bug->update_keywords($timestamp);
527
    
528
    my ($cc_removed) = $bug->update_cc($timestamp);
529
    $cc_removed = [map {$_->login} @$cc_removed];
530

531
    my ($dep_changes) = $bug->update_dependencies($timestamp);
532 533 534 535 536 537 538
    
    # Convert the "changes" hash into a list of all the bug ids, then
    # convert that into a hash to eliminate duplicates. ("map {@$_}" collapses
    # an array of arrays.)
    my @all_changed_deps = map { @$_ } @{$dep_changes->{'dependson'}};
    push(@all_changed_deps, map { @$_ } @{$dep_changes->{'blocked'}});
    my %changed_deps = map { $_ => 1 } @all_changed_deps;
539

540 541
    # $msgs will store emails which have to be sent to voters, if any.
    my $msgs;
542 543 544 545 546 547
    if ($changes->{'product'}) {
        # If some votes have been removed, RemoveVotes() returns
        # a list of messages to send to voters.
        # We delay the sending of these messages till tables are unlocked.
        $msgs = RemoveVotes($bug->id, 0,
                  "This bug has been moved to a different product");
548

549
        CheckIfVotedConfirmed($bug->id, Bugzilla->user->id);
terry%netscape.com's avatar
terry%netscape.com committed
550
    }
551

552
    # Set and update flags.
553
    Bugzilla::Flag::process($bug, undef, $timestamp, $cgi, $vars);
554

555
    $dbh->bz_commit_transaction();
556

557 558 559 560
    ###############
    # Send Emails #
    ###############

561 562
    # Now is a good time to send email to voters.
    foreach my $msg (@$msgs) {
563
        MessageToMTA($msg);
564 565
    }

566 567
    my $old_qa  = $changes->{'qa_contact'} ? $changes->{'qa_contact'}->[0] : '';
    my $old_own =  $changes->{'assigned_to'} ? $changes->{'assigned_to'}->[0] : '';
568 569
    $vars->{'mailrecipients'} = {
        cc        => $cc_removed,
570 571
        owner     => $old_own,
        qacontact => $old_qa,
572
        changer   => Bugzilla->user->login };
573

574
    $vars->{'id'} = $bug->id;
575
    $vars->{'type'} = "bug";
576 577 578
    
    # Let the user know the bug was changed and who did and didn't
    # receive email about the change.
579
    send_results($bug->id, $vars);
580
 
581 582 583 584
    # If the bug was marked as a duplicate, we need to notify users on the
    # other bug of any changes to that bug.
    my $new_dup_id = $changes->{'dup_id'} ? $changes->{'dup_id'}->[1] : undef;
    if ($new_dup_id) {
585
        $vars->{'mailrecipients'} = { 'changer' => Bugzilla->user->login }; 
586

587
        $vars->{'id'} = $new_dup_id;
588 589
        $vars->{'type'} = "dupe";
        
590 591
        # Let the user know a duplication notation was added to the 
        # original bug.
592
        send_results($new_dup_id, $vars);
593 594
    }

595 596 597 598 599
    my %all_dep_changes = (%notify_deps, %changed_deps);
    foreach my $id (sort { $a <=> $b } (keys %all_dep_changes)) {
        $vars->{'mailrecipients'} = { 'changer' => Bugzilla->user->login };
        $vars->{'id'} = $id;
        $vars->{'type'} = "dep";
600

601 602 603 604 605
        # Let the user (if he is able to see the bug) know we checked to
        # see if we should email notice of this change to users with a 
        # relationship to the dependent bug and who did and didn't 
        # receive email about it.
        send_results($id, $vars);
606
    }
terry%netscape.com's avatar
terry%netscape.com committed
607 608
}

609 610 611 612 613 614
# Determine if Patch Viewer is installed, for Diff link
# (NB: Duplicate code with show_bug.cgi.)
eval {
    require PatchReader;
    $vars->{'patchviewerinstalled'} = 1;
};
615

616
my $action;
617 618 619 620 621 622
if (defined $cgi->param('id')) {
    $action = Bugzilla->user->settings->{'post_bug_submit_action'}->{'value'};
} else {
    # param('id') is not defined when changing multiple bugs
    $action = 'nothing';
}
623

624 625 626 627
if (Bugzilla->usage_mode == USAGE_MODE_EMAIL) {
    # Do nothing.
}
elsif ($action eq 'next_bug') {
628 629 630 631 632 633 634
    my $next_bug;
    my $cur = lsearch(\@bug_list, $cgi->param("id"));
    if ($cur >= 0 && $cur < $#bug_list) {
        $next_bug = $bug_list[$cur + 1];
    }
    if ($next_bug) {
        if (detaint_natural($next_bug) && Bugzilla->user->can_see_bug($next_bug)) {
635
            my $bug = new Bugzilla::Bug($next_bug);
636
            ThrowCodeError("bug_error", { bug => $bug }) if $bug->error;
637

638 639
            $vars->{'bugs'} = [$bug];
            $vars->{'nextbug'} = $bug->bug_id;
640

641 642 643 644 645
            $template->process("bug/show.html.tmpl", $vars)
              || ThrowTemplateError($template->error());

            exit;
        }
646
    }
647
} elsif ($action eq 'same_bug') {
648
    if (Bugzilla->user->can_see_bug($cgi->param('id'))) {
649
        my $bug = new Bugzilla::Bug($cgi->param('id'));
650
        ThrowCodeError("bug_error", { bug => $bug }) if $bug->error;
651

652
        $vars->{'bugs'} = [$bug];
653

654 655
        $template->process("bug/show.html.tmpl", $vars)
          || ThrowTemplateError($template->error());
656

657 658
        exit;
    }
659 660
} elsif ($action ne 'nothing') {
    ThrowCodeError("invalid_post_bug_submit_action");
terry%netscape.com's avatar
terry%netscape.com committed
661
}
662

663
# End the response page.
664
unless (Bugzilla->usage_mode == USAGE_MODE_EMAIL) {
665 666 667
    # The user pref is 'Do nothing', so all we need is the current bug ID.
    $vars->{'bug'} = {bug_id => scalar $cgi->param('id')};

668 669 670 671 672 673 674
    $template->process("bug/navigate.html.tmpl", $vars)
        || ThrowTemplateError($template->error());
    $template->process("global/footer.html.tmpl", $vars)
        || ThrowTemplateError($template->error());
}

1;