From 5c0c85df6d698ad183a88a8794ed0212de2895c1 Mon Sep 17 00:00:00 2001
From: "myk%mozilla.org" <>
Date: Sat, 13 Apr 2002 04:01:53 +0000
Subject: Fix for bug 125660: Templatizes process_bug.cgi. Patch by Myk Melez
r=gerv,bbaetz
---
process_bug.cgi | 417 +++++++++++++++++++++-----------------------------------
1 file changed, 157 insertions(+), 260 deletions(-)
(limited to 'process_bug.cgi')
diff --git a/process_bug.cgi b/process_bug.cgi
index 561db45e7..fe9163eef 100755
--- a/process_bug.cgi
+++ b/process_bug.cgi
@@ -22,6 +22,7 @@
# Dan Mosedale
# Dave Miller
# Christopher Aillon
+# Myk Melez
use diagnostics;
use strict;
@@ -56,6 +57,8 @@ my $whoid = confirm_login();
my $requiremilestone = 0;
+use vars qw($template $vars);
+
######################################################################
# Begin Data/Security Validation
######################################################################
@@ -103,7 +106,12 @@ ValidateComment($::FORM{'comment'});
print "Content-type: text/html\n\n";
-PutHeader ("Bug processed");
+# Start displaying the response page.
+$vars->{'title'} = "Bug processed";
+$template->process("global/header", $vars)
+ || ThrowTemplateError($template->error());
+
+$vars->{'header_done'} = 1;
GetVersionTable();
@@ -135,9 +143,8 @@ sub CheckonComment( $ ) {
if( $ret ) {
if (!defined $::FORM{'comment'} || $::FORM{'comment'} =~ /^\s*$/) {
# No comment - sorry, action not allowed !
- PuntTryAgain("You have to specify a comment on this " .
- "change. Please give some words " .
- "on the reason for your change.");
+ ThrowUserError("You have to specify a comment on this change.
+ Please give some words on the reason for your change.");
} else {
$ret = 0;
}
@@ -177,106 +184,34 @@ if ((($::FORM{'id'} && $::FORM{'product'} ne $::oldproduct)
$mok = lsearch($::target_milestone{$prod}, $::FORM{'target_milestone'}) >= 0;
}
- # If anything needs to be verified, generate a form for verifying it.
+ # If the product-specific fields need to be verified, or we need to verify
+ # whether or not to add the bugs to their new product's group, display
+ # a verification form.
if (!$vok || !$cok || !$mok || (Param('usebuggroups') && !defined($::FORM{'addtonewgroup'}))) {
-
- # Start the form.
- print qq|
-
- Cancel and Return to the Query Page
- |;
-
- # End the page and stop processing.
- PutFooter();
+
+ $vars->{'verify_bug_group'} = (Param('usebuggroups')
+ && !defined($::FORM{'addtonewgroup'}));
+
+ $template->process("process/verify-new-product.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
exit;
}
}
@@ -355,18 +290,12 @@ sub CheckCanChangeField {
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.
-
-Old value: | $oldvalue |
-New value: | $newvalue |
-
-});
- PutFooter();
- exit();
+ $oldvalue = html_quote($oldvalue);
+ $newvalue = html_quote($newvalue);
+ ThrowUserError("You tried to change the $f field
+ from $oldvalue to $newvalue,
+ but only the owner or submitter of the bug, or a
+ sufficiently empowered user, may change that field.");
}
# Confirm that the reporter of the current bug can access the bug we are duping to.
@@ -390,45 +319,21 @@ sub DuplicateUserConfirm {
}
SendSQL("SELECT cclist_accessible FROM bugs WHERE bug_id = $original");
- my $cclist_accessible = FetchOneColumn();
+ $vars->{'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,";
-
+ $vars->{'form'} = \%::FORM;
+ $vars->{'original_bug_id'} = $original;
+ $vars->{'duplicate_bug_id'} = $dupe;
+
+ # Confirm whether or not to add the reporter to the cc: list
+ # of the original bug (the one this bug is being duped against).
print "Content-type: text/html\n\n";
- PutHeader("Duplicate Warning");
- print "
-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?
-
-";
- print "\n};
- PutFooter();
+ $template->process("process/confirm-dupe.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
exit;
} # end DuplicateUserConfirm()
@@ -466,11 +371,6 @@ if ($action eq Param("move-button-text")) {
}
-# the common updates to all bugs in @idlist start here
-#
-print "Update Bug " . join(" ", @idlist) . "\n";
-print "
\n";
-
$::query = "update bugs\nset";
$::comma = "";
umask(0);
@@ -686,10 +586,9 @@ SWITCH: for ($::FORM{'knob'}) {
DoComma();
if ( !defined$::FORM{'assigned_to'} ||
trim($::FORM{'assigned_to'}) eq "") {
- PuntTryAgain("You cannot reassign to a bug to nobody. Unless " .
- "you intentionally cleared out the " .
- "\"Reassign bug to\" field, " .
- Param("browserbugmessage"));
+ ThrowUserError("You cannot reassign to a bug to nobody. Unless you
+ intentionally cleared out the \"Reassign bug to\"
+ field, " . Param("browserbugmessage"));
}
my $newid = DBNameToIdAndCheck($::FORM{'assigned_to'});
$::query .= "assigned_to = $newid";
@@ -697,12 +596,12 @@ SWITCH: for ($::FORM{'knob'}) {
};
/^reassignbycomponent$/ && CheckonComment( "reassignbycomponent" ) && do {
if ($::FORM{'product'} eq $::dontchange) {
- PuntTryAgain("You must specify a product to help determine the " .
- "new owner of these bugs.");
+ ThrowUserError("You must specify a product to help determine
+ the new owner of these bugs.");
}
if ($::FORM{'component'} eq $::dontchange) {
- PuntTryAgain("You must specify a component whose owner should " .
- "get assigned these bugs.");
+ ThrowUserError("You must specify a component whose owner
+ should get assigned these bugs.");
}
if ($::FORM{'compconfirm'}) {
DoConfirm();
@@ -752,20 +651,19 @@ SWITCH: for ($::FORM{'knob'}) {
SendSQL("SELECT bug_id FROM bugs WHERE bug_id = " . SqlQuote($num));
$num = FetchOneColumn();
if (!$num) {
- PuntTryAgain("You must specify a valid bug number of which this bug " .
- "is a duplicate. The bug has not been changed.")
+ ThrowUserError("You must specify a valid bug number of which this bug
+ is a duplicate. The bug has not been changed.")
}
if (!defined($::FORM{'id'}) || $num == $::FORM{'id'}) {
- PuntTryAgain("Nice try, $::COOKIE{'Bugzilla_login'}. But it doesn't really ".
- "make sense to mark a bug as a duplicate of " .
- "itself, does it?");
+ ThrowUserError("Nice try, $::COOKIE{'Bugzilla_login'}, but it doesn't
+ really make sense to mark a bug as a duplicate of itself,
+ does it?");
}
my $checkid = trim($::FORM{'id'});
SendSQL("SELECT bug_id FROM bugs where bug_id = " . SqlQuote($checkid));
$checkid = FetchOneColumn();
if (!$checkid) {
- PuntTryAgain("The bug id $::FORM{'id'} is invalid. Please reload this bug ".
- "and try again.");
+ ThrowUserError("The bug id $::FORM{'id'} is invalid.");
}
$::FORM{'comment'} .= "\n\n*** This bug has been marked as a duplicate of $num ***";
$duplicate = $num;
@@ -773,14 +671,13 @@ SWITCH: for ($::FORM{'knob'}) {
last SWITCH;
};
# default
- print "Unknown action $::FORM{'knob'}!\n";
- PutFooter();
- exit;
+ my $escaped_knob = html_quote($::FORM{'knob'});
+ ThrowCodeError("Unknown action $escaped_knob!\n");
}
if ($#idlist < 0) {
- PuntTryAgain("You apparently didn't choose any bugs to modify.");
+ ThrowUserError("You apparently didn't choose any bugs to modify.");
}
@@ -794,11 +691,9 @@ if ($::FORM{'keywords'}) {
}
my $i = GetKeywordIdFromName($keyword);
if (!$i) {
- PuntTryAgain("Unknown keyword named " .
- html_quote($keyword) . "
. " .
- "The legal keyword names are " .
- "" .
- "listed here.");
+ ThrowUserError("Unknown keyword named " . html_quote($keyword) .
+ "
.
The legal keyword names are
+ listed here
.");
}
if (!$keywordseen{$i}) {
push(@keywordlist, $i);
@@ -814,8 +709,8 @@ if ($::comma eq ""
&& defined $::FORM{'masscc'} && ! $::FORM{'masscc'}
) {
if (!defined $::FORM{'comment'} || $::FORM{'comment'} =~ /^\s*$/) {
- PuntTryAgain("Um, you apparently did not change anything on the " .
- "selected bugs.");
+ ThrowUserError("Um, you apparently did not change anything
+ on the selected bugs.");
}
}
@@ -948,64 +843,30 @@ foreach my $id (@idlist) {
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.)");
+ ThrowUserError("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.",
+ undef,
+ "abort");
}
}
if (defined $::FORM{'delta_ts'} && $::FORM{'delta_ts'} ne $delta_ts) {
- print "
-Mid-air collision detected!
-Someone else has made changes to this bug at the same time you were trying to.
-The changes made were:
-
-";
- use vars qw($template $vars);
+ ($vars->{'operations'}) = GetBugActivity($::FORM{'id'}, $::FORM{'delta_ts'});
+
+ $vars->{'start_at'} = $::FORM{'longdesclength'};
+ $vars->{'comments'} = GetComments($id);
- ($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: \n};
- PutFooter();
+ $vars->{'form'} = \%::FORM;
+
+ $vars->{'bug_id'} = $id;
+ $vars->{'quoteUrls'} = \"eUrls;
+
+ SendSQL("UNLOCK TABLES");
+
+ # Warn the user about the mid-air collision and ask them what to do.
+ $template->process("process/mid-air.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
exit;
}
@@ -1024,7 +885,7 @@ The changes made were:
my $orig = $i;
if (!detaint_natural($i)) {
- PuntTryAgain("$orig is not a legal bug number");
+ ThrowUserError("$orig is not a legal bug number", undef, "abort");
}
# Don't use CanSeeBug, since we want to keep deps to bugs a
@@ -1033,10 +894,12 @@ The changes made were:
SqlQuote($i));
my $comp = FetchOneColumn();
if ($comp ne $i) {
- PuntTryAgain("$i is not a legal bug number");
+ ThrowUserError("$i is not a legal bug number", undef, "abort");
}
if ($id eq $i) {
- PuntTryAgain("You can't make a bug blocked or dependent on itself.");
+ ThrowUserError("You can't make a bug blocked or dependent on itself.",
+ undef,
+ "abort");
}
if (!exists $seen{$i}) {
push(@{$deptree{$target}}, $i);
@@ -1078,11 +941,13 @@ The changes made were:
foreach my $i (@isect) {
$both = $both . GetBugLink($i, "#" . $i) . " ";
}
- PuntTryAgain("Dependency loop detected!" .
- "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.");
+ ThrowUserError(qq|Dependency loop detected!
+ 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.
|,
+ undef,
+ "abort");
}
}
my $tmp = $me;
@@ -1131,8 +996,6 @@ The changes made were:
}
my $query = "$basequery\nwhere bug_id = $id";
-# print "$query
\n";
-
if ($::comma ne "") {
SendSQL($query);
}
@@ -1292,7 +1155,6 @@ The changes made were:
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,
@@ -1352,8 +1214,7 @@ The changes made were:
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");
+ SendSQL("UNLOCK TABLES");
my @ARGLIST = ();
if ( $removedCcString ne "" ) {
@@ -1366,10 +1227,25 @@ The changes made were:
push @ARGLIST, ( "-forceqacontact", $origQaContact);
}
push @ARGLIST, ($id, $::COOKIE{'Bugzilla_login'});
- system ("./processmail",@ARGLIST);
-
- print " | Back To BUG# $id |
\n";
-
+
+ # Send mail to let people know the bug has been changed. Uses
+ # a special syntax of the "open" and "exec" commands to capture
+ # the output "processmail", which "system" doesn't allow
+ # (i.e. "system ('./processmail', $bugid , $::userid);"), without
+ # the insecurity of running the command through a shell via backticks
+ # (i.e. "my $mailresults = `./processmail $bugid $::userid`;").
+ $vars->{'mail'} = "";
+ open(PMAIL, "-|") or exec('./processmail', @ARGLIST);
+ $vars->{'mail'} .= $_ while ;
+ close(PMAIL);
+
+ $vars->{'id'} = $id;
+
+ # Let the user know the bug was changed and who did and didn't
+ # receive email about the change.
+ $template->process("process/results.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
+
if ($duplicate) {
# Check to see if Reporter of this bug is reporter of Dupe
SendSQL("SELECT reporter FROM bugs WHERE bug_id = " . SqlQuote($::FORM{'id'}));
@@ -1387,15 +1263,34 @@ The changes made were:
AppendComment($duplicate, $::COOKIE{'Bugzilla_login'}, "*** Bug $::FORM{'id'} has been marked as a duplicate of this bug. ***");
CheckFormFieldDefined(\%::FORM,'comment');
SendSQL("INSERT INTO duplicates VALUES ($duplicate, $::FORM{'id'})");
- print "Duplicate notation added to bug $duplicate\n";
- system("./processmail", $duplicate, $::COOKIE{'Bugzilla_login'});
- print " | Go To BUG# $duplicate |
\n";
+
+ $vars->{'mail'} = "";
+ open(PMAIL, "-|") or exec('./processmail', $duplicate, $::COOKIE{'Bugzilla_login'});
+ $vars->{'mail'} .= $_ while ;
+ close(PMAIL);
+
+ $vars->{'id'} = $duplicate;
+ $vars->{'type'} = "dupe";
+
+ # Let the user know a duplication notation was added to the original bug.
+ $template->process("process/results.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
}
foreach my $k (keys(%dependencychanged)) {
- print "Checking for dependency changes on bug $k\n";
- system("./processmail", $k, $::COOKIE{'Bugzilla_login'});
- print " | Go To BUG# $k |
\n";
+ $vars->{'mail'} = "";
+ open(PMAIL, "-|") or exec('./processmail', $k, $::COOKIE{'Bugzilla_login'});
+ $vars->{'mail'} .= $_ while ;
+ close(PMAIL);
+
+ $vars->{'id'} = $k;
+ $vars->{'type'} = "dep";
+
+ # Let the user 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.
+ $template->process("process/results.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
}
}
@@ -1403,26 +1298,28 @@ The changes made were:
# Show next bug, if it exists.
if ($::COOKIE{"BUGLIST"} && $::FORM{'id'}) {
my @bugs = split(/:/, $::COOKIE{"BUGLIST"});
+ $vars->{'bug_list'} = \@bugs;
my $cur = lsearch(\@bugs, $::FORM{"id"});
if ($cur >= 0 && $cur < $#bugs) {
my $next_bug = $bugs[$cur + 1];
if (detaint_natural($next_bug) && CanSeeBug($next_bug)) {
-
- print "
\n";
- print("The next bug in your list is bug ");
- print("$next_bug:
\n");
$::FORM{'id'} = $next_bug;
+
+ $vars->{'next_id'} = $next_bug;
+
+ # Let the user know we are about to display the next bug in their list.
+ $template->process("process/next-bug.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
show_bug("header is already done");
exit;
}
- else {
- # Need this until the navigation_header() fn. goes away totally.
- undef $::next_bug;
- }
}
}
-navigation_header();
-PutFooter();
+# End the response page.
+$template->process("show/navigate.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
+$template->process("global/footer", $vars)
+ || ThrowTemplateError($template->error());
--
cgit v1.2.3-24-g4f1b