process_bug.cgi 24 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
use Bugzilla::Token;
63

64 65
use Storable qw(dclone);

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

68
my $cgi = Bugzilla->cgi;
69
my $dbh = Bugzilla->dbh;
70
my $template = Bugzilla->template;
71
my $vars = {};
72

73 74 75 76
######################################################################
# Subroutines
######################################################################

77 78 79 80 81 82 83 84 85 86 87 88 89 90
# 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;
}

91
# Tells us whether or not a field should be changed by process_bug.
92
sub should_set {
93
    # check_defined is used for fields where there's another field
94 95 96 97
    # 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) = @_;
98
    my $cgi = Bugzilla->cgi;
99 100
    if ( defined $cgi->param($field) 
         || ($check_defined && defined $cgi->param("defined_$field")) )
101 102 103 104 105 106
    {
        return 1;
    }
    return 0;
}

107 108 109 110
######################################################################
# Begin Data/Security Validation
######################################################################

111 112
# Create a list of objects for all bugs being modified in this request.
my @bug_objects;
113
if (defined $cgi->param('id')) {
114 115 116
  my $bug = Bugzilla::Bug->check(scalar $cgi->param('id'));
  $cgi->param('id', $bug->id);
  push(@bug_objects, $bug);
117
} else {
118
    foreach my $i ($cgi->param()) {
119
        if ($i =~ /^id_([1-9][0-9]*)/) {
120
            my $id = $1;
121
            push(@bug_objects, Bugzilla::Bug->check($id));
122
        }
123 124 125
    }
}

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

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

131 132 133 134
# 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!
135 136
        # Skip ones we've already deleted (such as "defined_$name").
        next if !defined $cgi->param($name);
137 138
        if ($cgi->param($name) eq $cgi->param('dontchange')) {
            $cgi->delete($name);
139
            $cgi->delete("defined_$name");
140 141
        }
    }
142 143
}

144
# do a match on the fields if applicable
145
Bugzilla::User::match_field({
146 147 148 149 150
    'qa_contact'                => { 'type' => 'single' },
    'newcc'                     => { 'type' => 'multi'  },
    'masscc'                    => { 'type' => 'multi'  },
    'assigned_to'               => { 'type' => 'single' },
});
151

152
print $cgi->header() unless Bugzilla->usage_mode == USAGE_MODE_EMAIL;
153

154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
# 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.
171
    $vars->{'comments'} = $first_bug->comments({ order => "oldest_to_newest" });
172
    $vars->{'bug'} = $first_bug;
173 174
    # The token contains the old delta_ts. We need a new one.
    $cgi->param('token', issue_hash_token([$first_bug->id, $first_bug->delta_ts]));
175 176 177 178 179
    
    # 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;
180
}
181

182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
# We couldn't do this check earlier as we first had to validate bug IDs
# and display the mid-air collision page if delta_ts changed.
# If we do a mass-change, we use session tokens.
my $token = $cgi->param('token');

if ($cgi->param('id')) {
    check_hash_token($token, [$first_bug->id, $first_bug->delta_ts]);
}
else {
    check_token_data($token, 'buglist_mass_change', 'query.cgi');
}

######################################################################
# End Data/Security Validation
######################################################################

198 199
$vars->{'title_tag'} = "bug_processed";

200
my $action;
201 202 203 204
if (defined $cgi->param('id')) {
    $action = Bugzilla->user->settings->{'post_bug_submit_action'}->{'value'};

    if ($action eq 'next_bug') {
205 206 207 208
        my @bug_list;
        if ($cgi->cookie("BUGLIST")) {
            @bug_list = split(/:/, $cgi->cookie("BUGLIST"));
        }
209 210
        my $cur = lsearch(\@bug_list, $cgi->param('id'));
        if ($cur >= 0 && $cur < $#bug_list) {
211 212 213 214 215 216 217
            my $next_bug_id = $bug_list[$cur + 1];
            detaint_natural($next_bug_id);
            if ($next_bug_id and $user->can_see_bug($next_bug_id)) {
                # We create an object here so that send_results can use it
                # when displaying the header.
                $vars->{'bug'} = new Bugzilla::Bug($next_bug_id);
            }
218 219 220 221
        }
    }
    # Include both action = 'same_bug' and 'nothing'.
    else {
222
        $vars->{'bug'} = $first_bug;
223 224 225 226 227 228 229
    }
}
else {
    # param('id') is not defined when changing multiple bugs at once.
    $action = 'nothing';
}

230 231 232 233 234 235
# 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 });
236
    }
237
}
238

239 240 241 242 243 244 245 246 247 248 249 250 251
# 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')) {
    foreach my $b (@bug_objects) {
        my $changed = $b->set_product(scalar $cgi->param('product'),
            { component        => scalar $cgi->param('component'),
              version          => scalar $cgi->param('version'),
              target_milestone => scalar $cgi->param('target_milestone'),
              change_confirmed => scalar $cgi->param('confirm_product_change'),
              other_bugs => \@bug_objects,
            });
        $product_change ||= $changed;
252
    }
253
}
254

255 256 257 258
# 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}) {
259 260 261 262
        my $gid = $group->id;
        if (should_set("bit-$gid", 1)) {
            # Check ! first to avoid having to check defined below.
            if (!$cgi->param("bit-$gid")) {
263
                $b->remove_group($gid);
264 265 266 267
            }
            # "== 1" is important because mass-change uses -1 to mean
            # "don't change this restriction"
            elsif ($cgi->param("bit-$gid") == 1) {
268
                $b->add_group($gid);
269 270
            }
        }
terry%netscape.com's avatar
terry%netscape.com committed
271 272 273
    }
}

274 275 276 277 278 279
# Flags should be set AFTER the bug has been moved into another product/component.
if ($cgi->param('id')) {
    my ($flags, $new_flags) = Bugzilla::Flag->extract_flags_from_cgi($first_bug, undef, $vars);
    $first_bug->set_flags($flags, $new_flags);
}

280 281 282 283 284 285
if ($cgi->param('id') && (defined $cgi->param('dependson')
                          || defined $cgi->param('blocked')) )
{
    $first_bug->set_dependencies(scalar $cgi->param('dependson'),
                                 scalar $cgi->param('blocked'));
}
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
elsif (should_set('dependson') || should_set('blocked')) {
    foreach my $bug (@bug_objects) {
        my %temp_deps;
        foreach my $type (qw(dependson blocked)) {
            $temp_deps{$type} = { map { $_ => 1 } @{$bug->$type} };
            if (should_set($type) && $cgi->param($type . '_action') =~ /^(add|remove)$/) {
                foreach my $id (split(/[,\s]+/, $cgi->param($type))) {
                    if ($cgi->param($type . '_action') eq 'remove') {
                        delete $temp_deps{$type}{$id};
                    }
                    else {
                        $temp_deps{$type}{$id} = 1;
                    }
                }
            }
        }
        $bug->set_dependencies([ keys %{$temp_deps{'dependson'}} ], [ keys %{$temp_deps{'blocked'}} ]);
    }
304 305 306 307 308 309 310 311 312 313 314 315
}

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;
    }
}

316 317 318
# 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.
319 320 321 322 323 324
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');
325
my @custom_fields = Bugzilla->active_custom_fields;
326

327 328 329 330 331 332 333
my %methods = (
    bug_severity => 'set_severity',
    rep_platform => 'set_platform',
    short_desc   => 'set_summary',
    bug_file_loc => 'set_url',
);
foreach my $b (@bug_objects) {
334 335 336 337 338 339 340
    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') });
    }
341
    foreach my $field_name (@set_fields) {
342
        if (should_set($field_name)) {
343 344 345 346 347
            my $method = $methods{$field_name};
            $method ||= "set_" . $field_name;
            $b->$method($cgi->param($field_name));
        }
    }
348 349
    $b->reset_assigned_to if $cgi->param('set_default_assignee');
    $b->reset_qa_contact  if $cgi->param('set_default_qa_contact');
350

351 352 353 354 355 356 357 358
    if (should_set('see_also')) {
        my @see_also = split(',', $cgi->param('see_also'));
        $b->add_see_also($_) foreach @see_also;
    }
    if (should_set('remove_see_also')) {
        $b->remove_see_also($_) foreach $cgi->param('remove_see_also')
    }

359 360 361 362 363 364
    # 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)]);
        }
365
    }
366 367
}

368
# Certain changes can only happen on individual bugs, never on mass-changes.
369
if (defined $cgi->param('id')) {
370 371 372
    # 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')) {
373
        $first_bug->set_alias($cgi->param('alias'));
374 375 376
    }

    # reporter_accessible and cclist_accessible--these are only set if
377 378
    # the user can change them and they appear on the page.
    if (should_set('cclist_accessible', 1)) {
379
        $first_bug->set_cclist_accessible($cgi->param('cclist_accessible'))
380 381
    }
    if (should_set('reporter_accessible', 1)) {
382
        $first_bug->set_reporter_accessible($cgi->param('reporter_accessible'))
383
    }
384 385 386 387 388 389
    
    # 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;
390 391
        $first_bug->set_comment_is_private($comment_id,
                                           $cgi->param("isprivate_$comment_id"));
392 393
    }
}
394

395 396 397 398
# 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.
399
my (@cc_add, @cc_remove);
400 401 402 403
if (defined $cgi->param('newcc')
    || defined $cgi->param('addselfcc')
    || defined $cgi->param('removecc')
    || defined $cgi->param('masscc')) {
404
        
405 406 407
    # 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) = "";
408 409 410 411 412
    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'));
413 414
        }
    } else {
415
        $cc_add = join(' ',$cgi->param('newcc'));
416 417
        # We came from bug_form which uses a select box to determine what cc's
        # need to be removed...
418 419
        if (defined $cgi->param('removecc') && $cgi->param('cc')) {
            $cc_remove = join (",", $cgi->param('cc'));
420 421 422
        }
    }

423 424 425 426 427 428 429 430
    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;
431
    $b->add_cc($_) foreach @cc_add;
432 433 434 435 436 437 438 439 440
    # 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();
    }
441 442
}

443 444
my $move_action = $cgi->param('action') || '';
if ($move_action eq Bugzilla->params->{'move-button-text'}) {
445 446 447 448 449
    Bugzilla->params->{'move-enabled'} || ThrowUserError("move_bugs_disabled");

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

450
    $dbh->bz_start_transaction();
451 452 453

    # First update all moved bugs.
    foreach my $bug (@bug_objects) {
454
        $bug->add_comment('', { type => CMT_MOVED_TO, extra_data => $user->login });
455
    }
456 457 458
    # Don't export the new status and resolution. We want the current ones.
    local $Storable::forgive_me = 1;
    my $bugs = dclone(\@bug_objects);
459 460

    my $new_status = Bugzilla->params->{'duplicate_or_move_bug_status'};
461
    foreach my $bug (@bug_objects) {
462
        $bug->set_status($new_status, {resolution => 'MOVED', moving => 1});
463
    }
464
    $_->update() foreach @bug_objects;
465
    $dbh->bz_commit_transaction();
466 467

    # Now send emails.
468
    foreach my $bug (@bug_objects) {
469
        $vars->{'mailrecipients'} = { 'changer' => $user->login };
470
        $vars->{'id'} = $bug->id;
471
        $vars->{'type'} = "move";
472
        send_results($bug->id, $vars);
473
    }
474 475 476 477 478 479 480
    # 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";
481 482
    $msg .= "Subject: Moving bug(s) " . join(', ', map($_->id, @bug_objects))
            . "\n\n";
483 484 485 486 487 488

    my @fieldlist = (Bugzilla::Bug->fields, 'group', 'long_desc',
                     'attachment', 'attachmentdata');
    my %displayfields;
    foreach (@fieldlist) {
        $displayfields{$_} = 1;
489
    }
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506

    $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;
507
}
508

509

510 511 512 513 514
# 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');
515 516
}

517 518 519 520
# 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) {
521 522 523 524 525 526 527 528 529 530 531 532 533
    if (should_set('bug_status')) {
        $b->set_status(
            scalar $cgi->param('bug_status'),
            {resolution =>  scalar $cgi->param('resolution'),
                dupe_of => scalar $cgi->param('dup_id')}
            );
    }
    elsif (should_set('resolution')) {
       $b->set_resolution(scalar $cgi->param('resolution'), 
                          {dupe_of => scalar $cgi->param('dup_id')});
    }
    elsif (should_set('dup_id')) {
        $b->set_dup_id(scalar $cgi->param('dup_id'));
534 535 536
    }
}

537 538 539 540
##############################
# Do Actual Database Updates #
##############################
foreach my $bug (@bug_objects) {
541
    $dbh->bz_start_transaction();
542

543
    my $timestamp = $dbh->selectrow_array(q{SELECT LOCALTIMESTAMP(0)});
544
    my $changes = $bug->update($timestamp);
545 546 547 548 549 550 551 552

    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)) {
553
            $notify_deps{$_} = 1 foreach (@{$bug->blocked});
554 555 556 557 558 559
        }
        
        # 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"
560
              if Bugzilla->user->is_timetracker;
561 562
        }
    }
563

564 565 566 567 568 569 570 571 572 573 574
    # To get a list of all changed dependencies, convert the "changes" arrays
    # into a long string, then collapse that string into unique numbers in
    # a hash.
    my $all_changed_deps = join(', ', @{ $changes->{'dependson'} || [] });
    $all_changed_deps = join(', ', @{ $changes->{'blocked'} || [] },
                                   $all_changed_deps);
    my %changed_deps = map { $_ => 1 } split(', ', $all_changed_deps);
    # When clearning one field (say, blocks) and filling in the other
    # (say, dependson), an empty string can get into the hash and cause
    # an error later.
    delete $changed_deps{''};
575

576
    $dbh->bz_commit_transaction();
577

578 579 580 581
    ###############
    # Send Emails #
    ###############

582 583 584
    my $old_qa  = $changes->{'qa_contact'}  ? $changes->{'qa_contact'}->[0] : '';
    my $old_own = $changes->{'assigned_to'} ? $changes->{'assigned_to'}->[0] : '';
    my $old_cc  = $changes->{cc}            ? $changes->{cc}->[0] : '';
585
    $vars->{'mailrecipients'} = {
586
        cc        => [split(/[\s,]+/, $old_cc)],
587 588
        owner     => $old_own,
        qacontact => $old_qa,
589
        changer   => Bugzilla->user->login };
590

591
    $vars->{'id'} = $bug->id;
592
    $vars->{'type'} = "bug";
593 594 595
    
    # Let the user know the bug was changed and who did and didn't
    # receive email about the change.
596
    send_results($bug->id, $vars);
597
 
598 599 600 601
    # 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) {
602
        $vars->{'mailrecipients'} = { 'changer' => Bugzilla->user->login }; 
603

604
        $vars->{'id'} = $new_dup_id;
605 606
        $vars->{'type'} = "dupe";
        
607 608
        # Let the user know a duplication notation was added to the 
        # original bug.
609
        send_results($new_dup_id, $vars);
610 611
    }

612 613 614 615 616
    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";
617

618 619 620 621 622
        # 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);
623
    }
terry%netscape.com's avatar
terry%netscape.com committed
624 625
}

626 627 628
if (Bugzilla->usage_mode == USAGE_MODE_EMAIL) {
    # Do nothing.
}
629 630 631 632 633 634 635 636 637 638
elsif ($action eq 'next_bug' or $action eq 'same_bug') {
    my $bug = $vars->{'bug'};
    if ($bug and $user->can_see_bug($bug)) {
        if ($action eq 'same_bug') {
            # $bug->update() does not update the internal structure of
            # the bug sufficiently to display the bug with the new values.
            # (That is, if we just passed in the old Bug object, we'd get
            # a lot of old values displayed.)
            $bug = new Bugzilla::Bug($bug->id);
            $vars->{'bug'} = $bug;
639
        }
640
        $vars->{'bugs'} = [$bug];
641 642 643
        if ($action eq 'next_bug') {
            $vars->{'nextbug'} = $bug->id;
        }
644 645 646 647
        $template->process("bug/show.html.tmpl", $vars)
          || ThrowTemplateError($template->error());
        exit;
    }
648 649
} elsif ($action ne 'nothing') {
    ThrowCodeError("invalid_post_bug_submit_action");
terry%netscape.com's avatar
terry%netscape.com committed
650
}
651

652
# End the response page.
653 654 655 656 657 658 659 660
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());
}

1;