#!/usr/bonsaitools/bin/perl -wT
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# 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.
#
# The Original Code is the Bugzilla Bug Tracking System.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): Terry Weissman
When marking a bug as a duplicate, the reporter of the
duplicate is normally added to the CC list of the original.
The permissions on bug #$original (the original) are currently set
such that the reporter would not normally be able to see it.
Adding the reporter to the CC list of bug #$original
$reporter_access allow him/her access to view this bug.
Do you wish to do this?
Cancel and Return to the Query Page
|;
# End the page and stop processing.
PutFooter();
exit;
}
}
# Checks that the user is allowed to change the given field. Actually, right
# now, the rules are pretty simple, and don't look at the field itself very
# much, but that could be enhanced.
my $lastbugid = 0;
my $ownerid;
my $reporterid;
my $qacontactid;
sub CheckCanChangeField {
my ($f, $bugid, $oldvalue, $newvalue) = (@_);
if ($f eq "assigned_to" || $f eq "reporter" || $f eq "qa_contact") {
if ($oldvalue =~ /^\d+$/) {
if ($oldvalue == 0) {
$oldvalue = "";
} else {
$oldvalue = DBID_to_name($oldvalue);
}
}
}
if ($oldvalue eq $newvalue) {
return 1;
}
if (trim($oldvalue) eq trim($newvalue)) {
return 1;
}
if ($f =~ /^longdesc/) {
return 1;
}
if ($f eq "resolution") { # always OK this. if they really can't,
return 1; # it'll flag it when "status" is checked.
}
if ($UserInEditGroupSet < 0) {
$UserInEditGroupSet = UserInGroup("editbugs");
}
if ($UserInEditGroupSet) {
return 1;
}
if ($lastbugid != $bugid) {
SendSQL("SELECT reporter, assigned_to, qa_contact FROM bugs " .
"WHERE bug_id = $bugid");
($reporterid, $ownerid, $qacontactid) = (FetchSQLData());
}
# Let reporter change bug status, even if they can't edit bugs.
# If reporter can't re-open their bug they will just file a duplicate.
# While we're at it, let them close their own bugs as well.
if ( ($f eq "bug_status") && ($whoid eq $reporterid) ) {
return 1;
}
if ($f eq "bug_status" && $newvalue ne $::unconfirmedstate &&
IsOpenedState($newvalue)) {
# Hmm. They are trying to set this bug to some opened state
# that isn't the UNCONFIRMED state. Are they in the right
# group? Or, has it ever been confirmed? If not, then this
# isn't legal.
if ($UserInCanConfirmGroupSet < 0) {
$UserInCanConfirmGroupSet = UserInGroup("canconfirm");
}
if ($UserInCanConfirmGroupSet) {
return 1;
}
SendSQL("SELECT everconfirmed FROM bugs WHERE bug_id = $bugid");
my $everconfirmed = FetchOneColumn();
if ($everconfirmed) {
return 1;
}
} elsif ($reporterid eq $whoid || $ownerid eq $whoid ||
$qacontactid eq $whoid) {
return 1;
}
SendSQL("UNLOCK TABLES");
$oldvalue = value_quote($oldvalue);
$newvalue = value_quote($newvalue);
print PuntTryAgain(qq{
Only the owner or submitter of the bug, or a sufficiently
empowered user, may make that change to the $f field.
});
PutFooter();
exit();
}
# Confirm that the reporter of the current bug can access the bug we are duping to.
sub DuplicateUserConfirm {
# if we've already been through here, then exit
if (defined $::FORM{'confirm_add_duplicate'}) {
return;
}
my $dupe = trim($::FORM{'id'});
my $original = trim($::FORM{'dup_id'});
SendSQL("SELECT reporter FROM bugs WHERE bug_id = " . SqlQuote($dupe));
my $reporter = FetchOneColumn();
SendSQL("SELECT profiles.groupset FROM profiles WHERE profiles.userid =".SqlQuote($reporter));
my $reportergroupset = FetchOneColumn();
if (CanSeeBug($original, $reporter, $reportergroupset)) {
$::FORM{'confirm_add_duplicate'} = "1";
return;
}
SendSQL("SELECT cclist_accessible FROM bugs WHERE bug_id = $original");
my $cclist_accessible = FetchOneColumn();
# Once in this part of the subroutine, the user has not been auto-validated
# and the duper has not chosen whether or not to add to CC list, so let's
# ask the duper what he/she wants to do.
# First, will the user gain access to this bug immediately by being CC'd?
my $reporter_access = $cclist_accessible ? "will immediately" : "might, in the future,";
print "Content-type: text/html\n\n";
PutHeader("Duplicate Warning");
print "Old value: $oldvalue New value: $newvalue
" .
html_quote($keyword) . "
. " .
"The legal keyword names are " . "" . "listed here."); } if (!$keywordseen{$i}) { push(@keywordlist, $i); $keywordseen{$i} = 1; } } } my $keywordaction = $::FORM{'keywordaction'} || "makeexact"; if ($::comma eq "" && 0 == @keywordlist && $keywordaction ne "makeexact" && defined $::FORM{'masscc'} && ! $::FORM{'masscc'} ) { if (!defined $::FORM{'comment'} || $::FORM{'comment'} =~ /^\s*$/) { PuntTryAgain("Um, you apparently did not change anything on the " . "selected bugs."); } } my $basequery = $::query; my $delta_ts; sub SnapShotBug { my ($id) = (@_); SendSQL("select delta_ts, " . join(',', @::log_columns) . " from bugs where bug_id = $id"); my @row = FetchSQLData(); $delta_ts = shift @row; return @row; } sub SnapShotDeps { my ($i, $target, $me) = (@_); SendSQL("select $target from dependencies where $me = $i order by $target"); my @list; while (MoreSQLData()) { push(@list, FetchOneColumn()); } return join(',', @list); } my $timestamp; my $bug_changed; sub FindWrapPoint { my ($string, $startpos) = @_; if (!$string) { return 0 } if (length($string) < $startpos) { return length($string) } my $wrappoint = rindex($string, ",", $startpos); # look for comma if ($wrappoint < 0) { # can't find comma $wrappoint = rindex($string, " ", $startpos); # look for space if ($wrappoint < 0) { # can't find space $wrappoint = rindex($string, "-", $startpos); # look for hyphen if ($wrappoint < 0) { # can't find hyphen $wrappoint = $startpos; # just truncate it } else { $wrappoint++; # leave hyphen on the left side } } } return $wrappoint; } sub LogActivityEntry { my ($i,$col,$removed,$added) = @_; # in the case of CCs, deps, and keywords, there's a possibility that someone # might try to add or remove a lot of them at once, which might take more # space than the activity table allows. We'll solve this by splitting it # into multiple entries if it's too long. while ($removed || $added) { my ($removestr, $addstr) = ($removed, $added); if (length($removestr) > 254) { my $commaposition = FindWrapPoint($removed, 254); $removestr = substr($removed,0,$commaposition); $removed = substr($removed,$commaposition); $removed =~ s/^[,\s]+//; # remove any comma or space } else { $removed = ""; # no more entries } if (length($addstr) > 254) { my $commaposition = FindWrapPoint($added, 254); $addstr = substr($added,0,$commaposition); $added = substr($added,$commaposition); $added =~ s/^[,\s]+//; # remove any comma or space } else { $added = ""; # no more entries } $addstr = SqlQuote($addstr); $removestr = SqlQuote($removestr); my $fieldid = GetFieldID($col); SendSQL("INSERT INTO bugs_activity " . "(bug_id,who,bug_when,fieldid,removed,added) VALUES " . "($i,$whoid," . SqlQuote($timestamp) . ",$fieldid,$removestr,$addstr)"); $bug_changed = 1; } } sub LogDependencyActivity { my ($i, $oldstr, $target, $me) = (@_); my $newstr = SnapShotDeps($i, $target, $me); if ($oldstr ne $newstr) { # Figure out what's really different... my ($removed, $added) = DiffStrings($oldstr, $newstr); LogActivityEntry($i,$target,$removed,$added); # update timestamp on target bug so midairs will be triggered SendSQL("UPDATE bugs SET delta_ts=NOW() WHERE bug_id=$i"); return 1; } return 0; } # this loop iterates once for each bug to be processed (eg when this script # is called with multiple bugs selected from buglist.cgi instead of # show_bug.cgi). # foreach my $id (@idlist) { my %dependencychanged; $bug_changed = 0; my $write = "WRITE"; # Might want to make a param to control # whether we do LOW_PRIORITY ... SendSQL("LOCK TABLES bugs $write, bugs_activity $write, cc $write, " . "cc AS selectVisible_cc $write, " . "profiles $write, dependencies $write, votes $write, " . "keywords $write, longdescs $write, fielddefs $write, " . "keyworddefs READ, groups READ, attachments READ, products READ"); my @oldvalues = SnapShotBug($id); my %oldhash; my $i = 0; foreach my $col (@::log_columns) { $oldhash{$col} = $oldvalues[$i]; if (exists $::FORM{$col}) { CheckCanChangeField($col, $id, $oldvalues[$i], $::FORM{$col}); } $i++; } if ($requiremilestone) { my $value = $::FORM{'target_milestone'}; if (!defined $value || $value eq $::dontchange) { $value = $oldhash{'target_milestone'}; } SendSQL("SELECT defaultmilestone FROM products WHERE product = " . SqlQuote($oldhash{'product'})); if ($value eq FetchOneColumn()) { SendSQL("UNLOCK TABLES"); PuntTryAgain("You must determine a target milestone for bug $id " . "if you are going to accept it. (Part of " . "accepting a bug is giving an estimate of when it " . "will be fixed.)"); } } if (defined $::FORM{'delta_ts'} && $::FORM{'delta_ts'} ne $delta_ts) { print "
"; use vars qw($template $vars); ($vars->{'operations'}, $vars->{'incomplete_data'}) = GetBugActivity($::FORM{'id'}, $::FORM{'delta_ts'}); $template->process("show/activity.html.tmpl", $vars) || DisplayError("Template process failed: " . $template->error()) && exit; my $comments = GetComments($id); my $longchanged = 0; if (scalar(@$comments) > $::FORM{'longdesclength'}) { $longchanged = 1; print "
Added comments:
"; $vars->{'start_at'} = $::FORM{'longdesclength'}; $vars->{'comments'} = $comments; $vars->{'quoteUrls'} = \"eUrls; $template->process("show/comments.tmpl", $vars) || DisplayError("Template process failed: " . $template->error()) && exit; print "\n"; } SendSQL("unlock tables"); print "You have the following choices:
" .
"The following bug(s) would appear on both the \"depends on\" " .
"and \"blocks\" parts of the dependency tree if these changes " .
"are committed: $both
" .
"This would create a circular dependency, which is not allowed.");
}
}
my $tmp = $me;
$me = $target;
$target = $tmp;
}
}
if (@::legal_keywords) {
# There are three kinds of "keywordsaction": makeexact, add, delete.
# For makeexact, we delete everything, and then add our things.
# For add, we delete things we're adding (to make sure we don't
# end up having them twice), and then we add them.
# For delete, we just delete things on the list.
my $changed = 0;
if ($keywordaction eq "makeexact") {
SendSQL("DELETE FROM keywords WHERE bug_id = $id");
$changed = 1;
}
foreach my $keyword (@keywordlist) {
if ($keywordaction ne "makeexact") {
SendSQL("DELETE FROM keywords
WHERE bug_id = $id AND keywordid = $keyword");
$changed = 1;
}
if ($keywordaction ne "delete") {
SendSQL("INSERT INTO keywords
(bug_id, keywordid) VALUES ($id, $keyword)");
$changed = 1;
}
}
if ($changed) {
SendSQL("SELECT keyworddefs.name
FROM keyworddefs, keywords
WHERE keywords.bug_id = $id
AND keyworddefs.id = keywords.keywordid
ORDER BY keyworddefs.name");
my @list;
while (MoreSQLData()) {
push(@list, FetchOneColumn());
}
SendSQL("UPDATE bugs SET keywords = " .
SqlQuote(join(', ', @list)) .
" WHERE bug_id = $id");
}
}
my $query = "$basequery\nwhere bug_id = $id";
# print "
$query\n"; if ($::comma ne "") { SendSQL($query); } SendSQL("select now()"); $timestamp = FetchOneColumn(); if (defined $::FORM{'comment'}) { AppendComment($id, $::COOKIE{'Bugzilla_login'}, $::FORM{'comment'}); } my $removedCcString = ""; if (defined $::FORM{newcc} || defined $::FORM{removecc} || defined $::FORM{masscc}) { # Get the current CC list for this bug my %oncc; SendSQL("SELECT who FROM cc WHERE bug_id = $id"); while (MoreSQLData()) { $oncc{FetchOneColumn()} = 1; } my (@added, @removed) = (); foreach my $pid (keys %cc_add) { # If this person isn't already on the cc list, add them if (! $oncc{$pid}) { SendSQL("INSERT INTO cc (bug_id, who) VALUES ($id, $pid)"); push (@added, $cc_add{$pid}); $oncc{$pid} = 1; } } foreach my $pid (keys %cc_remove) { # If the person is on the cc list, remove them if ($oncc{$pid}) { SendSQL("DELETE FROM cc WHERE bug_id = $id AND who = $pid"); push (@removed, $cc_remove{$pid}); $oncc{$pid} = 0; } } # Save off the removedCcString so it can be fed to processmail $removedCcString = join (",", @removed); # If any changes were found, record it in the activity log if (scalar(@removed) || scalar(@added)) { my $removed = join(", ", @removed); my $added = join(", ", @added); LogActivityEntry($id,"cc",$removed,$added); } } if (defined $::FORM{'dependson'}) { my $me = "blocked"; my $target = "dependson"; for (1..2) { SendSQL("select $target from dependencies where $me = $id order by $target"); my %snapshot; my @oldlist; while (MoreSQLData()) { push(@oldlist, FetchOneColumn()); } my @newlist = sort {$a <=> $b} @{$deps{$target}}; @dependencychanged{@oldlist} = 1; @dependencychanged{@newlist} = 1; while (0 < @oldlist || 0 < @newlist) { if (@oldlist == 0 || (@newlist > 0 && $oldlist[0] > $newlist[0])) { $snapshot{$newlist[0]} = SnapShotDeps($newlist[0], $me, $target); shift @newlist; } elsif (@newlist == 0 || (@oldlist > 0 && $newlist[0] > $oldlist[0])) { $snapshot{$oldlist[0]} = SnapShotDeps($oldlist[0], $me, $target); shift @oldlist; } else { if ($oldlist[0] != $newlist[0]) { die "Error in list comparing code"; } shift @oldlist; shift @newlist; } } my @keys = keys(%snapshot); if (@keys) { my $oldsnap = SnapShotDeps($id, $target, $me); SendSQL("delete from dependencies where $me = $id"); foreach my $i (@{$deps{$target}}) { SendSQL("insert into dependencies ($me, $target) values ($id, $i)"); } foreach my $k (@keys) { LogDependencyActivity($k, $snapshot{$k}, $me, $target); } LogDependencyActivity($id, $oldsnap, $target, $me); } my $tmp = $me; $me = $target; $target = $tmp; } } # When a bug changes products and the old or new product is associated # with a bug group, it may be necessary to remove the bug from the old # group or add it to the new one. There are a very specific series of # conditions under which these activities take place, more information # about which can be found in comments within the conditionals below. if ( # the "usebuggroups" parameter is on, indicating that products # are associated with groups of the same name; Param('usebuggroups') # the user has changed the product to which the bug belongs; && defined $::FORM{'product'} && $::FORM{'product'} ne $::dontchange && $::FORM{'product'} ne $oldhash{'product'} ) { if ( # the user wants to add the bug to the new product's group; ($::FORM{'addtonewgroup'} eq 'yes' || ($::FORM{'addtonewgroup'} eq 'yesifinold' && GroupNameToBit($oldhash{'product'}) & $oldhash{'groupset'})) # the new product is associated with a group; && GroupExists($::FORM{'product'}) # the bug is not already in the group; (This can happen when the user # goes to the "edit multiple bugs" form with a list of bugs at least # one of which is in the new group. In this situation, the user can # simultaneously change the bugs to a new product and move the bugs # into that product's group, which happens earlier in this script # and thus is already done. If we didn't check for this, then this # situation would cause us to add the bug to the group twice, which # would result in the bug being added to a totally different group.) && !BugInGroup($id, $::FORM{'product'}) # the user is a member of the associated group, indicating they # are authorized to add bugs to that group, *or* the "usebuggroupsentry" # parameter is off, indicating that users can add bugs to a product # regardless of whether or not they belong to its associated group; && (UserInGroup($::FORM{'product'}) || !Param('usebuggroupsentry')) # the associated group is active, indicating it can accept new bugs; && GroupIsActive(GroupNameToBit($::FORM{'product'})) ) { # Add the bug to the group associated with its new product. my $groupbit = GroupNameToBit($::FORM{'product'}); SendSQL("UPDATE bugs SET groupset = groupset + $groupbit WHERE bug_id = $id"); } if ( # the old product is associated with a group; GroupExists($oldhash{'product'}) # the bug is a member of that group; && BugInGroup($id, $oldhash{'product'}) ) { # Remove the bug from the group associated with its old product. my $groupbit = GroupNameToBit($oldhash{'product'}); SendSQL("UPDATE bugs SET groupset = groupset - $groupbit WHERE bug_id = $id"); } print qq||; } # get a snapshot of the newly set values out of the database, # and then generate any necessary bug activity entries by seeing # what has changed since before we wrote out the new values. # my @newvalues = SnapShotBug($id); # for passing to processmail to ensure that when someone is removed # from one of these fields, they get notified of that fact (if desired) # my $origOwner = ""; my $origQaContact = ""; foreach my $c (@::log_columns) { my $col = $c; # We modify it, don't want to modify array # values in place. my $old = shift @oldvalues; my $new = shift @newvalues; if (!defined $old) { $old = ""; } if (!defined $new) { $new = ""; } if ($old ne $new) { # save off the old value for passing to processmail so the old # owner can be notified # if ($col eq 'assigned_to') { $old = ($old) ? DBID_to_name($old) : ""; $new = ($new) ? DBID_to_name($new) : ""; $origOwner = $old; } # ditto for the old qa contact # if ($col eq 'qa_contact') { $old = ($old) ? DBID_to_name($old) : ""; $new = ($new) ? DBID_to_name($new) : ""; $origQaContact = $old; } # If this is the keyword field, only record the changes, not everything. if ($col eq 'keywords') { ($old, $new) = DiffStrings($old, $new); } if ($col eq 'product') { RemoveVotes($id, 0, "This bug has been moved to a different product"); } LogActivityEntry($id,$col,$old,$new); } } if ($bug_changed) { SendSQL("UPDATE bugs SET delta_ts = " . SqlQuote($timestamp) . " WHERE bug_id = $id"); } print "
Changes to bug $id submitted\n"; SendSQL("unlock tables"); my @ARGLIST = (); if ( $removedCcString ne "" ) { push @ARGLIST, ("-forcecc", $removedCcString); } if ( $origOwner ne "" ) { push @ARGLIST, ("-forceowner", $origOwner); } if ( $origQaContact ne "") { push @ARGLIST, ( "-forceqacontact", $origQaContact); } push @ARGLIST, ($id, $::COOKIE{'Bugzilla_login'}); system ("./processmail",@ARGLIST); print " | Back To BUG# $id |
Duplicate notation added to bug $duplicate\n"; system("./processmail", $duplicate, $::COOKIE{'Bugzilla_login'}); print " | Go To BUG# $duplicate |
Checking for dependency changes on bug $k\n"; system("./processmail", $k, $::COOKIE{'Bugzilla_login'}); print " | Go To BUG# $k |
The next bug in your list is bug "); print("$next_bug:
\n"); $::FORM{'id'} = $next_bug; show_bug("header is already done"); exit; } else { # Need this until the navigation_header() fn. goes away totally. undef $::next_bug; } } } navigation_header(); PutFooter();