process_bug.cgi 23.6 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->{'use_keywords'} = 1 if Bugzilla::Keyword::keyword_count();
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 145
# do a match on the fields if applicable

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

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

161 162 163 164
######################################################################
# End Data/Security Validation
######################################################################

165
print $cgi->header() unless Bugzilla->usage_mode == USAGE_MODE_EMAIL;
166

167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
# 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;
192
}
193

194 195
$vars->{'title_tag'} = "bug_processed";

196
# Set up the vars for navigational <link> elements
197
my @bug_list;
198
if ($cgi->cookie("BUGLIST")) {
199
    @bug_list = split(/:/, $cgi->cookie("BUGLIST"));
200 201 202
    $vars->{'bug_list'} = \@bug_list;
}

203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
my ($action, $next_bug);
if (defined $cgi->param('id')) {
    $action = Bugzilla->user->settings->{'post_bug_submit_action'}->{'value'};

    if ($action eq 'next_bug') {
        my $cur = lsearch(\@bug_list, $cgi->param('id'));
        if ($cur >= 0 && $cur < $#bug_list) {
            $next_bug = $bug_list[$cur + 1];
            # No need to check whether the user can see the bug or not.
            # All we want is its ID. An error will be thrown later
            # if the user cannot see it.
            $vars->{'bug'} = {bug_id => $next_bug};
        }
    }
    # Include both action = 'same_bug' and 'nothing'.
    else {
        $vars->{'bug'} = {bug_id => $cgi->param('id')};
    }
}
else {
    # param('id') is not defined when changing multiple bugs at once.
    $action = 'nothing';
}

227 228 229 230 231 232
# 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 });
233
    }
234
}
235

236 237 238 239 240 241 242 243 244 245
my $product_change;
foreach my $bug (@bug_objects) {
    my $args;
    if (should_set('product')) {
        $args->{product} = scalar $cgi->param('product');
        $args->{component} = scalar $cgi->param('component');
        $args->{version} = scalar $cgi->param('version');
        $args->{target_milestone} = scalar $cgi->param('target_milestone');
        $args->{confirm_product_change} =  scalar $cgi->param('confirm_product_change');
        $args->{other_bugs} = \@bug_objects;
246
    }
247 248

    foreach my $group (@{$bug->product_obj->groups_valid}) {
249 250 251 252
        my $gid = $group->id;
        if (should_set("bit-$gid", 1)) {
            # Check ! first to avoid having to check defined below.
            if (!$cgi->param("bit-$gid")) {
253
                push (@{$args->{remove_group}}, $gid);
254 255 256 257
            }
            # "== 1" is important because mass-change uses -1 to mean
            # "don't change this restriction"
            elsif ($cgi->param("bit-$gid") == 1) {
258
               push (@{$args->{add_group}}, $gid);
259 260
            }
        }
terry%netscape.com's avatar
terry%netscape.com committed
261
    }
262 263 264 265

    # this will be deleted later when code moves to $bug->set_all
    my $changed = $bug->set_all($args);
    $product_change ||= $changed;
terry%netscape.com's avatar
terry%netscape.com committed
266 267
}

268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
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;
    }
}

290 291 292
# 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.
293 294 295 296 297 298
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');
299
my @custom_fields = Bugzilla->active_custom_fields;
300

301 302 303 304 305 306 307
my %methods = (
    bug_severity => 'set_severity',
    rep_platform => 'set_platform',
    short_desc   => 'set_summary',
    bug_file_loc => 'set_url',
);
foreach my $b (@bug_objects) {
308 309 310 311 312 313 314
    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') });
    }
315
    foreach my $field_name (@set_fields) {
316
        if (should_set($field_name)) {
317 318 319 320 321
            my $method = $methods{$field_name};
            $method ||= "set_" . $field_name;
            $b->$method($cgi->param($field_name));
        }
    }
322 323
    $b->reset_assigned_to if $cgi->param('set_default_assignee');
    $b->reset_qa_contact  if $cgi->param('set_default_qa_contact');
324

325 326 327 328 329 330
    # 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)]);
        }
331
    }
332 333
}

334
# Certain changes can only happen on individual bugs, never on mass-changes.
335
if (defined $cgi->param('id')) {
336 337 338
    # 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')) {
339
        $first_bug->set_alias($cgi->param('alias'));
340 341 342
    }

    # reporter_accessible and cclist_accessible--these are only set if
343 344
    # the user can change them and they appear on the page.
    if (should_set('cclist_accessible', 1)) {
345
        $first_bug->set_cclist_accessible($cgi->param('cclist_accessible'))
346 347
    }
    if (should_set('reporter_accessible', 1)) {
348
        $first_bug->set_reporter_accessible($cgi->param('reporter_accessible'))
349
    }
350 351 352 353 354 355
    
    # 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;
356 357
        $first_bug->set_comment_is_private($comment_id,
                                           $cgi->param("isprivate_$comment_id"));
358 359
    }
}
360

361 362 363 364
# 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.
365
my (@cc_add, @cc_remove);
366 367 368 369
if (defined $cgi->param('newcc')
    || defined $cgi->param('addselfcc')
    || defined $cgi->param('removecc')
    || defined $cgi->param('masscc')) {
370
        
371 372 373
    # 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) = "";
374 375 376 377 378
    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'));
379 380
        }
    } else {
381
        $cc_add = join(' ',$cgi->param('newcc'));
382 383
        # We came from bug_form which uses a select box to determine what cc's
        # need to be removed...
384 385
        if (defined $cgi->param('removecc') && $cgi->param('cc')) {
            $cc_remove = join (",", $cgi->param('cc'));
386 387 388
        }
    }

389 390 391 392 393 394 395 396
    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;
397
    $b->add_cc($_) foreach @cc_add;
398 399 400 401 402 403 404 405 406
    # 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();
    }
407 408
}

409 410
my $move_action = $cgi->param('action') || '';
if ($move_action eq Bugzilla->params->{'move-button-text'}) {
411 412 413 414 415
    Bugzilla->params->{'move-enabled'} || ThrowUserError("move_bugs_disabled");

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

416
    $dbh->bz_start_transaction();
417 418 419

    # First update all moved bugs.
    foreach my $bug (@bug_objects) {
420
        $bug->add_comment('', { type => CMT_MOVED_TO, extra_data => $user->login });
421
    }
422 423 424
    # Don't export the new status and resolution. We want the current ones.
    local $Storable::forgive_me = 1;
    my $bugs = dclone(\@bug_objects);
425 426

    my $new_status = Bugzilla->params->{'duplicate_or_move_bug_status'};
427
    foreach my $bug (@bug_objects) {
428
        $bug->set_status($new_status, {resolution => 'MOVED', moving => 1});
429
    }
430
    $_->update() foreach @bug_objects;
431
    $dbh->bz_commit_transaction();
432 433

    # Now send emails.
434
    foreach my $bug (@bug_objects) {
435
        $vars->{'mailrecipients'} = { 'changer' => $user->login };
436
        $vars->{'id'} = $bug->id;
437
        $vars->{'type'} = "move";
438
        send_results($bug->id, $vars);
439
    }
440 441 442 443 444 445 446
    # 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";
447 448
    $msg .= "Subject: Moving bug(s) " . join(', ', map($_->id, @bug_objects))
            . "\n\n";
449 450 451 452 453 454

    my @fieldlist = (Bugzilla::Bug->fields, 'group', 'long_desc',
                     'attachment', 'attachmentdata');
    my %displayfields;
    foreach (@fieldlist) {
        $displayfields{$_} = 1;
455
    }
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472

    $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;
473
}
474

475

476 477 478 479 480
# 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');
481 482
}

483 484 485 486
# 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) {
487 488 489 490 491 492 493 494 495 496 497 498 499
    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'));
500 501 502
    }
}

503 504 505 506
##############################
# Do Actual Database Updates #
##############################
foreach my $bug (@bug_objects) {
507
    $dbh->bz_start_transaction();
508

509
    my $timestamp = $dbh->selectrow_array(q{SELECT NOW()});
510
    my $changes = $bug->update($timestamp);
511 512 513 514 515 516 517 518

    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)) {
519
            $notify_deps{$_} = 1 foreach (@{$bug->blocked});
520 521 522 523 524 525 526 527 528
        }
        
        # 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'});
        }
    }
529

530 531 532 533 534 535 536 537 538 539 540
    # 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{''};
541

542 543
    # @msgs will store emails which have to be sent to voters, if any.
    my @msgs;
544 545 546
    if ($changes->{'product'}) {
        # If some votes have been removed, RemoveVotes() returns
        # a list of messages to send to voters.
547 548
        # We delay the sending of these messages till changes are committed.
        @msgs = RemoveVotes($bug->id, 0, 'votes_bug_moved');
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, $vars);
554

555
    $dbh->bz_commit_transaction();
556

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

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

566 567 568
    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] : '';
569
    $vars->{'mailrecipients'} = {
570
        cc        => [split(/[\s,]+/, $old_cc)],
571 572
        owner     => $old_own,
        qacontact => $old_qa,
573
        changer   => Bugzilla->user->login };
574

575
    $vars->{'id'} = $bug->id;
576
    $vars->{'type'} = "bug";
577 578 579
    
    # Let the user know the bug was changed and who did and didn't
    # receive email about the change.
580
    send_results($bug->id, $vars);
581
 
582 583 584 585
    # 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) {
586
        $vars->{'mailrecipients'} = { 'changer' => Bugzilla->user->login }; 
587

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

596 597 598 599 600
    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";
601

602 603 604 605 606
        # 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);
607
    }
terry%netscape.com's avatar
terry%netscape.com committed
608 609
}

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

617 618 619 620
if (Bugzilla->usage_mode == USAGE_MODE_EMAIL) {
    # Do nothing.
}
elsif ($action eq 'next_bug') {
621 622
    if ($next_bug) {
        if (detaint_natural($next_bug) && Bugzilla->user->can_see_bug($next_bug)) {
623
            my $bug = new Bugzilla::Bug($next_bug);
624
            ThrowCodeError("bug_error", { bug => $bug }) if $bug->error;
625

626 627
            $vars->{'bugs'} = [$bug];
            $vars->{'nextbug'} = $bug->bug_id;
628

629 630 631 632 633
            $template->process("bug/show.html.tmpl", $vars)
              || ThrowTemplateError($template->error());

            exit;
        }
634
    }
635
} elsif ($action eq 'same_bug') {
636
    if (Bugzilla->user->can_see_bug($cgi->param('id'))) {
637
        my $bug = new Bugzilla::Bug($cgi->param('id'));
638
        ThrowCodeError("bug_error", { bug => $bug }) if $bug->error;
639

640
        $vars->{'bugs'} = [$bug];
641

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

645 646
        exit;
    }
647 648
} elsif ($action ne 'nothing') {
    ThrowCodeError("invalid_post_bug_submit_action");
terry%netscape.com's avatar
terry%netscape.com committed
649
}
650

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