Commit b259c4b4 authored by bbaetz%acm.org's avatar bbaetz%acm.org

Bug 199813 - Make all users of ThrowUserError pass $vars in explicitly.

r=gerv a=justdave
parent 747eb2dd
# -*- 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): Bradley Baetz <bbaetz@acm.org>
use strict;
package Bugzilla::Error;
use base qw(Exporter);
@Bugzilla::Error::EXPORT = qw(ThrowUserError);
sub ThrowUserError {
my ($error, $vars, $unlock_tables) = @_;
$vars ||= {};
$vars->{error} = $error;
# Need to do this until User.pm goes in, so that the footer is correct
$vars->{user} = $::vars->{user};
Bugzilla->dbh->do("UNLOCK TABLES") if $unlock_tables;
# XXX - mod_perl
print "Content-type: text/html\n\n" if !$::vars->{'header_done'};
my $template = Bugzilla->template;
$template->process("global/user-error.html.tmpl", $vars)
|| &::ThrowTemplateError($template->error());
exit;
}
1;
__END__
=head1 NAME
Bugzilla::Error - Error handling utilities for Bugzilla
=head1 SYNOPSIS
use Bugzilla::Error;
ThrowUserError("error_tag",
{ foo => 'bar' });
=head1 DESCRIPTION
Various places throughout the Bugzilla codebase need to report errors to the
user. The C<Throw*Error> family of functions allow this to be done in a
generic and localisable manner.
=head1 FUNCTIONS
=over 4
=item C<ThrowUserError>
This function takes an error tag as the first argument, and an optional hashref
of variables as a second argument. These are used by the
I<global/user-error.html.tmpl> template to format the error, using the passed
in variables as required.
An optional third argument may be supplied. If present (and defined), then the
error handling code will unlock the database tables. In the long term, this
argument will go away, to be replaced by transactional C<rollback> calls. There
is no timeframe for doing so, however.
=back
=head1 SEE ALSO
L<Bugzilla|Bugzilla>
...@@ -103,8 +103,8 @@ sub init { ...@@ -103,8 +103,8 @@ sub init {
my $c = trim($params->param('votes')); my $c = trim($params->param('votes'));
if ($c ne "") { if ($c ne "") {
if ($c !~ /^[0-9]*$/) { if ($c !~ /^[0-9]*$/) {
$::vars->{'value'} = $c; &::ThrowUserError("illegal_at_least_x_votes",
&::ThrowUserError("illegal_at_least_x_votes"); { value => $c });
} }
push(@specialchart, ["votes", "greaterthan", $c - 1]); push(@specialchart, ["votes", "greaterthan", $c - 1]);
} }
...@@ -207,8 +207,8 @@ sub init { ...@@ -207,8 +207,8 @@ sub init {
if (@clist) { if (@clist) {
push(@specialchart, \@clist); push(@specialchart, \@clist);
} else { } else {
$::vars->{'email'} = $email; ThrowUserError("missing_email_type",
&::ThrowUserError("missing_email_type"); { email => $email });
} }
} }
...@@ -217,8 +217,8 @@ sub init { ...@@ -217,8 +217,8 @@ sub init {
my $c = trim($params->param('changedin')); my $c = trim($params->param('changedin'));
if ($c ne "") { if ($c ne "") {
if ($c !~ /^[0-9]*$/) { if ($c !~ /^[0-9]*$/) {
$::vars->{'value'} = $c; &::ThrowUserError("illegal_changed_in_last_x_days",
&::ThrowUserError("illegal_changed_in_last_x_days"); { value => $c });
} }
push(@specialchart, ["changedin", push(@specialchart, ["changedin",
"lessthan", $c + 1]); "lessthan", $c + 1]);
...@@ -558,8 +558,8 @@ sub init { ...@@ -558,8 +558,8 @@ sub init {
push(@list, "$table.keywordid = $id"); push(@list, "$table.keywordid = $id");
} }
else { else {
$::vars->{'keyword'} = $v; ThrowUserError("unknown_keyword",
&::ThrowUserError("unknown_keyword"); { keyword => $v });
} }
} }
my $haveawordterm; my $haveawordterm;
...@@ -992,8 +992,7 @@ sub SqlifyDate { ...@@ -992,8 +992,7 @@ sub SqlifyDate {
} }
my $date = str2time($str); my $date = str2time($str);
if (!defined($date)) { if (!defined($date)) {
$::vars->{'date'} = $str; &::ThrowUserError("illegal_date", { date => $str });
&::ThrowUserError("illegal_date");
} }
return time2str("%Y-%m-%d %H:%M:%S", $date); return time2str("%Y-%m-%d %H:%M:%S", $date);
} }
......
...@@ -35,6 +35,7 @@ use lib "."; ...@@ -35,6 +35,7 @@ use lib ".";
use Bugzilla::Util; use Bugzilla::Util;
use Bugzilla::Config; use Bugzilla::Config;
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Error;
# Shut up misguided -w warnings about "used only once". For some reason, # Shut up misguided -w warnings about "used only once". For some reason,
# "use vars" chokes on me when I try it here. # "use vars" chokes on me when I try it here.
...@@ -252,8 +253,7 @@ sub CheckEmailSyntax { ...@@ -252,8 +253,7 @@ sub CheckEmailSyntax {
my ($addr) = (@_); my ($addr) = (@_);
my $match = Param('emailregexp'); my $match = Param('emailregexp');
if ($addr !~ /$match/ || $addr =~ /[\\\(\)<>&,;:"\[\] \t\r\n]/) { if ($addr !~ /$match/ || $addr =~ /[\\\(\)<>&,;:"\[\] \t\r\n]/) {
$vars->{'addr'} = $addr; ThrowUserError("illegal_email_address", { addr => $addr });
ThrowUserError("illegal_email_address");
} }
} }
...@@ -327,24 +327,6 @@ sub ThrowCodeError { ...@@ -327,24 +327,6 @@ sub ThrowCodeError {
exit; exit;
} }
# For errors made by the user.
sub ThrowUserError {
($vars->{'error'}, my $extra_vars, my $unlock_tables) = (@_);
SendSQL("UNLOCK TABLES") if $unlock_tables;
# Copy the extra_vars into the vars hash
foreach my $var (keys %$extra_vars) {
$vars->{$var} = $extra_vars->{$var};
}
print "Content-type: text/html\n\n" if !$vars->{'header_done'};
$template->process("global/user-error.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
exit;
}
# This function should only be called if a template->process() fails. # This function should only be called if a template->process() fails.
# It tries another template first, because often one template being # It tries another template first, because often one template being
# broken or missing doesn't mean that they all are. But it falls back on # broken or missing doesn't mean that they all are. But it falls back on
......
...@@ -171,7 +171,8 @@ sub validateCanEdit ...@@ -171,7 +171,8 @@ sub validateCanEdit
"attach_id = $attach_id AND submitter_id = $::userid"); "attach_id = $attach_id AND submitter_id = $::userid");
FetchSQLData() FetchSQLData()
|| ThrowUserError("illegal_attachment_edit"); || ThrowUserError("illegal_attachment_edit",
{ attach_id => $attach_id });
} }
sub validateCanChangeAttachment sub validateCanChangeAttachment
...@@ -183,7 +184,8 @@ sub validateCanChangeAttachment ...@@ -183,7 +184,8 @@ sub validateCanChangeAttachment
AND bugs.bug_id = attachments.bug_id"); AND bugs.bug_id = attachments.bug_id");
my $productid = FetchOneColumn(); my $productid = FetchOneColumn();
CanEditProductId($productid) CanEditProductId($productid)
|| ThrowUserError("illegal_attachment_edit"); || ThrowUserError("illegal_attachment_edit",
{ attach_id => $attachid });
} }
sub validateCanChangeBug sub validateCanChangeBug
...@@ -194,7 +196,8 @@ sub validateCanChangeBug ...@@ -194,7 +196,8 @@ sub validateCanChangeBug
WHERE bug_id = $bugid"); WHERE bug_id = $bugid");
my $productid = FetchOneColumn(); my $productid = FetchOneColumn();
CanEditProductId($productid) CanEditProductId($productid)
|| ThrowUserError("illegal_attachment_edit"); || ThrowUserError("illegal_attachment_edit_bug",
{ bug_id => $bugid });
} }
sub validateDescription sub validateDescription
...@@ -249,8 +252,8 @@ sub validateContentType ...@@ -249,8 +252,8 @@ sub validateContentType
if ( $::FORM{'contenttype'} !~ /^(application|audio|image|message|model|multipart|text|video)\/.+$/ ) if ( $::FORM{'contenttype'} !~ /^(application|audio|image|message|model|multipart|text|video)\/.+$/ )
{ {
$vars->{'contenttype'} = $::FORM{'contenttype'}; ThrowUserError("invalid_content_type",
ThrowUserError("invalid_content_type"); { contenttype => $::FORM{'contenttype'} });
} }
} }
...@@ -292,11 +295,11 @@ sub validateData ...@@ -292,11 +295,11 @@ sub validateData
# Make sure the attachment does not exceed the maximum permitted size # Make sure the attachment does not exceed the maximum permitted size
my $len = length($data); my $len = length($data);
if ($maxsize && $len > $maxsize) { if ($maxsize && $len > $maxsize) {
$vars->{'filesize'} = sprintf("%.0f", $len/1024); my $vars = { filesize => sprintf("%.0f", $len/1024) };
if ( $::FORM{'ispatch'} ) { if ( $::FORM{'ispatch'} ) {
ThrowUserError("patch_too_large"); ThrowUserError("patch_too_large", $vars);
} else { } else {
ThrowUserError("file_too_large"); ThrowUserError("file_too_large", $vars);
} }
} }
...@@ -328,6 +331,9 @@ sub validateObsolete ...@@ -328,6 +331,9 @@ sub validateObsolete
# Make sure the attachment id is valid and the user has permissions to view # Make sure the attachment id is valid and the user has permissions to view
# the bug to which it is attached. # the bug to which it is attached.
foreach my $attachid (@{$::MFORM{'obsolete'}}) { foreach my $attachid (@{$::MFORM{'obsolete'}}) {
# my $vars after ThrowCodeError is updated to not use the global
# vars hash
$vars->{'attach_id'} = $attachid; $vars->{'attach_id'} = $attachid;
detaint_natural($attachid) detaint_natural($attachid)
...@@ -338,7 +344,7 @@ sub validateObsolete ...@@ -338,7 +344,7 @@ sub validateObsolete
# Make sure the attachment exists in the database. # Make sure the attachment exists in the database.
MoreSQLData() MoreSQLData()
|| ThrowUserError("invalid_attach_id"); || ThrowUserError("invalid_attach_id", $vars);
my ($bugid, $isobsolete, $description) = FetchSQLData(); my ($bugid, $isobsolete, $description) = FetchSQLData();
...@@ -663,8 +669,8 @@ sub update ...@@ -663,8 +669,8 @@ sub update
my $bugid = FetchSQLData(); my $bugid = FetchSQLData();
unless ($bugid) unless ($bugid)
{ {
$vars->{'bug_id'} = $bugid; ThrowUserError("invalid_bug_id",
ThrowUserError("invalid_bug_id"); { bug_id => $bugid });
} }
# Lock database tables in preparation for updating the attachment. # Lock database tables in preparation for updating the attachment.
......
...@@ -83,8 +83,8 @@ my $product = $::FORM{'product'}; ...@@ -83,8 +83,8 @@ my $product = $::FORM{'product'};
my $product_id = get_product_id($product); my $product_id = get_product_id($product);
if (!$product_id) { if (!$product_id) {
$::vars->{'product'} = $product; ThrowUserError("invalid_product_name",
ThrowUserError("invalid_product_name"); { product => $product });
} }
# Make sure the user is authorized to access this product. # Make sure the user is authorized to access this product.
......
...@@ -83,8 +83,8 @@ my $product_id; ...@@ -83,8 +83,8 @@ my $product_id;
if ($product) { if ($product) {
$product_id = get_product_id($product); $product_id = get_product_id($product);
if (!$product_id) { if (!$product_id) {
$vars->{'product'} = $product; ThrowUserError("invalid_product_name",
ThrowUserError("invalid_product_name"); { product => $product });
} }
} }
...@@ -109,17 +109,17 @@ if (!tie(%dbmcount, 'AnyDBM_File', "data/duplicates/dupes$today", ...@@ -109,17 +109,17 @@ if (!tie(%dbmcount, 'AnyDBM_File', "data/duplicates/dupes$today",
if ($!{ENOENT}) { if ($!{ENOENT}) {
if (!tie(%dbmcount, 'AnyDBM_File', "data/duplicates/dupes$yesterday", if (!tie(%dbmcount, 'AnyDBM_File', "data/duplicates/dupes$yesterday",
O_RDONLY, 0644)) { O_RDONLY, 0644)) {
$vars->{'today'} = $today; my $vars = { today => $today };
if ($!{ENOENT}) { if ($!{ENOENT}) {
ThrowUserError("no_dupe_stats"); ThrowUserError("no_dupe_stats", $vars);
} else { } else {
$vars->{'error_msg'} = $!; $vars->{'error_msg'} = $!;
ThrowUserError("no_dupe_stats_error_yesterday"); ThrowUserError("no_dupe_stats_error_yesterday", $vars);
} }
} }
} else { } else {
$vars->{'error_msg'} = $!; ThrowUserError("no_dupe_stats_error_today",
ThrowUserError("no_dupe_stats_error_today"); { error_msg => $! });
} }
} }
...@@ -146,10 +146,11 @@ if (!tie(%before, 'AnyDBM_File', "data/duplicates/dupes$whenever", ...@@ -146,10 +146,11 @@ if (!tie(%before, 'AnyDBM_File', "data/duplicates/dupes$whenever",
O_RDONLY, 0644)) { O_RDONLY, 0644)) {
# Ignore file not found errors # Ignore file not found errors
if (!$!{ENOENT}) { if (!$!{ENOENT}) {
$vars->{'error_msg'} = $!; ThrowUserError("no_dupe_stats_error_whenever",
$vars->{'changedsince'} = $changedsince; { error_msg => $!,
$vars->{'whenever'} = $whenever; changedsince => $changedsince,
ThrowUserError("no_dupe_stats_error_whenever"); whenever => $whenever,
});
} }
} else { } else {
# Calculate the deltas # Calculate the deltas
......
...@@ -127,7 +127,6 @@ sub AppendComment { ...@@ -127,7 +127,6 @@ sub AppendComment {
# zero or more digits, OR we have a period followed by one or more digits # zero or more digits, OR we have a period followed by one or more digits
if ($work_time !~ /^-?(?:\d+(?:\.\d*)?|\.\d+)$/) { if ($work_time !~ /^-?(?:\d+(?:\.\d*)?|\.\d+)$/) {
ThrowUserError("need_numeric_value"); ThrowUserError("need_numeric_value");
return;
} }
} else { $work_time = 0 }; } else { $work_time = 0 };
...@@ -863,8 +862,8 @@ sub DBNameToIdAndCheck { ...@@ -863,8 +862,8 @@ sub DBNameToIdAndCheck {
return $result; return $result;
} }
$::vars->{'name'} = $name; ThrowUserError("invalid_username",
ThrowUserError("invalid_username"); { name => $name });
} }
......
...@@ -78,8 +78,8 @@ ValidateComment($comment); ...@@ -78,8 +78,8 @@ ValidateComment($comment);
my $product = $::FORM{'product'}; my $product = $::FORM{'product'};
my $product_id = get_product_id($product); my $product_id = get_product_id($product);
if (!$product_id) { if (!$product_id) {
$vars->{'product'} = $product; ThrowUserError("invalid_product_name",
ThrowUserError("invalid_product_name"); { product => $product });
} }
# Set cookies # Set cookies
...@@ -230,8 +230,8 @@ if ($::FORM{'keywords'} && UserInGroup("editbugs")) { ...@@ -230,8 +230,8 @@ if ($::FORM{'keywords'} && UserInGroup("editbugs")) {
} }
my $i = GetKeywordIdFromName($keyword); my $i = GetKeywordIdFromName($keyword);
if (!$i) { if (!$i) {
$vars->{'keyword'} = $keyword; ThrowUserError("unknown_keyword",
ThrowUserError("unknown_keyword"); { keyword => $keyword });
} }
if (!$keywordseen{$i}) { if (!$keywordseen{$i}) {
push(@keywordlist, $i); push(@keywordlist, $i);
...@@ -301,8 +301,10 @@ if (UserInGroup("editbugs") && defined($::FORM{'dependson'})) { ...@@ -301,8 +301,10 @@ if (UserInGroup("editbugs") && defined($::FORM{'dependson'})) {
foreach my $i (@isect) { foreach my $i (@isect) {
$both = $both . GetBugLink($i, "#" . $i) . " "; $both = $both . GetBugLink($i, "#" . $i) . " ";
} }
$vars->{'both'} = $both;
ThrowUserError("dependency_loop_multi", undef, "abort"); ThrowUserError("dependency_loop_multi",
{ both => $both },
"abort");
} }
} }
my $tmp = $me; my $tmp = $me;
...@@ -337,8 +339,8 @@ if (UserInGroup(Param("timetrackinggroup")) && ...@@ -337,8 +339,8 @@ if (UserInGroup(Param("timetrackinggroup")) &&
if ($est_time =~ /^(?:\d+(?:\.\d*)?|\.\d+)$/) { if ($est_time =~ /^(?:\d+(?:\.\d*)?|\.\d+)$/) {
$sql .= SqlQuote($est_time) . "," . SqlQuote($est_time); $sql .= SqlQuote($est_time) . "," . SqlQuote($est_time);
} else { } else {
$vars->{'field'} = "estimated_time"; ThrowUserError("need_positive_number",
ThrowUserError("need_positive_number"); { field => 'estimated_time' });
} }
} else { } else {
$sql .= "0, 0"; $sql .= "0, 0";
......
...@@ -223,7 +223,12 @@ if ((($::FORM{'id'} && $::FORM{'product'} ne $::oldproduct) ...@@ -223,7 +223,12 @@ if ((($::FORM{'id'} && $::FORM{'product'} ne $::oldproduct)
$vars->{'oldvalue'} = $::oldproduct; $vars->{'oldvalue'} = $::oldproduct;
$vars->{'newvalue'} = $::FORM{'product'}; $vars->{'newvalue'} = $::FORM{'product'};
$vars->{'field'} = 'product'; $vars->{'field'} = 'product';
ThrowUserError("illegal_change", undef, "abort"); ThrowUserError("illegal_change",
{ oldvalue => $::oldproduct,
newvalue => $::FORM{'product'},
field => 'product',
},
"abort");
} }
CheckFormField(\%::FORM, 'product', \@::legal_product); CheckFormField(\%::FORM, 'product', \@::legal_product);
...@@ -689,7 +694,7 @@ if (Param("usebugaliases") && defined($::FORM{'alias'})) { ...@@ -689,7 +694,7 @@ if (Param("usebugaliases") && defined($::FORM{'alias'})) {
# Make sure the alias is unique. # Make sure the alias is unique.
my $escaped_alias = SqlQuote($alias); my $escaped_alias = SqlQuote($alias);
$vars->{'alias'} = $alias; my $vars = { alias => $alias };
SendSQL("SELECT bug_id FROM bugs WHERE alias = $escaped_alias " . SendSQL("SELECT bug_id FROM bugs WHERE alias = $escaped_alias " .
"AND bug_id != $idlist[0]"); "AND bug_id != $idlist[0]");
...@@ -697,17 +702,17 @@ if (Param("usebugaliases") && defined($::FORM{'alias'})) { ...@@ -697,17 +702,17 @@ if (Param("usebugaliases") && defined($::FORM{'alias'})) {
if ($id) { if ($id) {
$vars->{'bug_link'} = GetBugLink($id, "Bug $id"); $vars->{'bug_link'} = GetBugLink($id, "Bug $id");
ThrowUserError("alias_in_use"); ThrowUserError("alias_in_use", $vars);
} }
# Make sure the alias isn't just a number. # Make sure the alias isn't just a number.
if ($alias =~ /^\d+$/) { if ($alias =~ /^\d+$/) {
ThrowUserError("alias_is_numeric"); ThrowUserError("alias_is_numeric", $vars);
} }
# Make sure the alias has no commas or spaces. # Make sure the alias has no commas or spaces.
if ($alias =~ /[, ]/) { if ($alias =~ /[, ]/) {
ThrowUserError("alias_has_comma_or_space"); ThrowUserError("alias_has_comma_or_space", $vars);
} }
} }
...@@ -750,8 +755,8 @@ if (UserInGroup(Param('timetrackinggroup'))) { ...@@ -750,8 +755,8 @@ if (UserInGroup(Param('timetrackinggroup'))) {
DoComma(); DoComma();
$::query .= "$field = " . SqlQuote($er_time); $::query .= "$field = " . SqlQuote($er_time);
} else { } else {
$vars->{'field'} = $field; ThrowUserError("need_positive_number",
ThrowUserError("need_positive_number"); field => $field);
} }
} }
} }
...@@ -946,8 +951,8 @@ SWITCH: for ($::FORM{'knob'}) { ...@@ -946,8 +951,8 @@ SWITCH: for ($::FORM{'knob'}) {
SendSQL("SELECT bug_id FROM bugs where bug_id = " . SqlQuote($checkid)); SendSQL("SELECT bug_id FROM bugs where bug_id = " . SqlQuote($checkid));
$checkid = FetchOneColumn(); $checkid = FetchOneColumn();
if (!$checkid) { if (!$checkid) {
$vars->{'bug_id'} = $checkid; ThrowUserError("invalid_bug_id",
ThrowUserError("invalid_bug_id"); { bug_id => $checkid });
} }
$::FORM{'comment'} .= "\n\n*** This bug has been marked as a duplicate of $num ***"; $::FORM{'comment'} .= "\n\n*** This bug has been marked as a duplicate of $num ***";
$duplicate = $num; $duplicate = $num;
...@@ -975,8 +980,8 @@ if ($::FORM{'keywords'}) { ...@@ -975,8 +980,8 @@ if ($::FORM{'keywords'}) {
} }
my $i = GetKeywordIdFromName($keyword); my $i = GetKeywordIdFromName($keyword);
if (!$i) { if (!$i) {
$vars->{keyword} = $keyword; ThrowUserError("unknown_keyword",
ThrowUserError("unknown_keyword"); { keyword => $keyword });
} }
if (!$keywordseen{$i}) { if (!$keywordseen{$i}) {
push(@keywordlist, $i); push(@keywordlist, $i);
...@@ -1098,6 +1103,7 @@ foreach my $id (@idlist) { ...@@ -1098,6 +1103,7 @@ foreach my $id (@idlist) {
if (exists $::FORM{$col}) { if (exists $::FORM{$col}) {
if (!CheckCanChangeField($col, $id, $oldvalues[$i], $::FORM{$col})) { if (!CheckCanChangeField($col, $id, $oldvalues[$i], $::FORM{$col})) {
# More fun hacking... don't display component_id # More fun hacking... don't display component_id
my $vars;
if ($col eq 'component_id') { if ($col eq 'component_id') {
$vars->{'oldvalue'} = get_component_name($oldhash{'component_id'}); $vars->{'oldvalue'} = get_component_name($oldhash{'component_id'});
$vars->{'newvalue'} = $::FORM{'component'}; $vars->{'newvalue'} = $::FORM{'component'};
...@@ -1108,23 +1114,23 @@ foreach my $id (@idlist) { ...@@ -1108,23 +1114,23 @@ foreach my $id (@idlist) {
$vars->{'newvalue'} = $::FORM{$col}; $vars->{'newvalue'} = $::FORM{$col};
$vars->{'field'} = $col; $vars->{'field'} = $col;
} }
ThrowUserError("illegal_change", undef, "abort"); ThrowUserError("illegal_change", $vars, "abort");
} }
} }
$i++; $i++;
} }
$oldhash{'product'} = get_product_name($oldhash{'product_id'}); $oldhash{'product'} = get_product_name($oldhash{'product_id'});
if (!CanEditProductId($oldhash{'product_id'})) { if (!CanEditProductId($oldhash{'product_id'})) {
$vars->{'product'} = $oldhash{'product'}; ThrowUserError("product_edit_denied",
ThrowUserError("product_edit_denied"); { product => $oldhash{'product'} });
} }
if (defined $::FORM{'product'} if (defined $::FORM{'product'}
&& $::FORM{'product'} ne $::FORM{'dontchange'} && $::FORM{'product'} ne $::FORM{'dontchange'}
&& $::FORM{'product'} ne $oldhash{'product'} && $::FORM{'product'} ne $oldhash{'product'}
&& !CanEnterProduct($::FORM{'product'})) { && !CanEnterProduct($::FORM{'product'})) {
$vars->{'product'} = $::FORM{'product'}; ThrowUserError("entry_access_denied",
ThrowUserError("entry_access_denied"); { product => $::FORM{'product'} });
} }
if ($requiremilestone) { if ($requiremilestone) {
my $value = $::FORM{'target_milestone'}; my $value = $::FORM{'target_milestone'};
...@@ -1135,8 +1141,9 @@ foreach my $id (@idlist) { ...@@ -1135,8 +1141,9 @@ foreach my $id (@idlist) {
SqlQuote($oldhash{'product'})); SqlQuote($oldhash{'product'}));
if ($value eq FetchOneColumn()) { if ($value eq FetchOneColumn()) {
SendSQL("UNLOCK TABLES"); SendSQL("UNLOCK TABLES");
$vars->{'bug_id'} = $id; ThrowUserError("milestone_required",
ThrowUserError("milestone_required", undef, "abort"); { bug_id => $id },
"abort");
} }
} }
if (defined $::FORM{'delta_ts'} && $::FORM{'delta_ts'} ne $delta_ts) { if (defined $::FORM{'delta_ts'} && $::FORM{'delta_ts'} ne $delta_ts) {
...@@ -1214,8 +1221,9 @@ foreach my $id (@idlist) { ...@@ -1214,8 +1221,9 @@ foreach my $id (@idlist) {
$both = $both . GetBugLink($i, "#" . $i) . " "; $both = $both . GetBugLink($i, "#" . $i) . " ";
} }
$vars->{'both'} = $both; ThrowUserError("dependency_loop_multi",
ThrowUserError("dependency_loop_multi", undef, "abort"); { both => $both },
"abort");
} }
} }
my $tmp = $me; my $tmp = $me;
......
...@@ -34,14 +34,7 @@ ...@@ -34,14 +34,7 @@
[% DEFAULT title = "Error" %] [% DEFAULT title = "Error" %]
[% error_message = BLOCK %] [% error_message = BLOCK %]
[% IF error == "aaa_example_error_tag" %] [% IF error == "account_creation_disabled" %]
[% title = "Example Error" %]
This is an example error. The title is set above. This text is the body
of the error. It can contain arbitrary <b>HTML</b>, and also references
to any [% parameters %] which you may have set before calling
ThrowUserError.
[% ELSIF error == "account_creation_disabled" %]
[% title = "Account Creation Disabled" %] [% title = "Account Creation Disabled" %]
Account self-creation has been disabled or restricted. Account self-creation has been disabled or restricted.
<hr> <hr>
...@@ -207,7 +200,7 @@ ...@@ -207,7 +200,7 @@
[% ELSIF error == "flag_type_sortkey_invalid" %] [% ELSIF error == "flag_type_sortkey_invalid" %]
[% title = "Flag Type Sort Key Invalid" %] [% title = "Flag Type Sort Key Invalid" %]
The sort key must be an integer between 0 and 32767 inclusive. The sort key must be an integer between 0 and 32767 inclusive.
It cannot be <em>[% variables.sortkey %]</em>. It cannot be <em>[% sortkey FILTER html %]</em>.
[% ELSIF error == "illegal_at_least_x_votes" %] [% ELSIF error == "illegal_at_least_x_votes" %]
[% title = "Your Query Makes No Sense" %] [% title = "Your Query Makes No Sense" %]
...@@ -218,6 +211,10 @@ ...@@ -218,6 +211,10 @@
[% title = "Unauthorised Action" %] [% title = "Unauthorised Action" %]
You are not authorised to edit attachment [% attach_id %]. You are not authorised to edit attachment [% attach_id %].
[% ELSIF error == "illegal_attachment_edit_bug" %]
[% title = "Unauthorised Action" %]
You are not authorised to edit attachments on bug [% bug_id %].
[% ELSIF error == "illegal_attachment_is_patch" %] [% ELSIF error == "illegal_attachment_is_patch" %]
[% title = "Your Query Makes No Sense" %] [% title = "Your Query Makes No Sense" %]
The only legal values for the <em>Attachment is patch</em> field are The only legal values for the <em>Attachment is patch</em> field are
...@@ -507,18 +504,6 @@ ...@@ -507,18 +504,6 @@
[% title = "Access Denied" %] [% title = "Access Denied" %]
You do not have the permissions necessary to view reports for this product. You do not have the permissions necessary to view reports for this product.
[% ELSIF error == "requestee_too_short" %]
[% title = "Requestee Name Too Short" %]
One or two characters match too many users, so please enter at least
three characters of the name/email address of the user you want to set
the flag.
[% ELSIF error == "requestee_too_many_matches" %]
[% title = "Requestee String Matched Too Many Times" %]
The string <em>[% requestee FILTER html %]</em> matched more than
100 users. Enter more of the name to bring the number of matches
down to a reasonable amount.
[% ELSIF error == "require_component" %] [% ELSIF error == "require_component" %]
[% title = "Component Needed" %] [% title = "Component Needed" %]
You must choose a component to file this bug in. If necessary, You must choose a component to file this bug in. If necessary,
...@@ -596,11 +581,10 @@ ...@@ -596,11 +581,10 @@
The file you are trying to attach is empty! The file you are trying to attach is empty!
[% ELSE %] [% ELSE %]
[%# Cope with legacy calling convention, where "error" was the string [% title = "Error string not found" %]
# to print. The user error string <code>[% error FILTER html %]</code> was not found.
#%] Please send email to [% Param("maintainer") %] describing the steps taken
to obtain this message.
[% error %]
[% END %] [% END %]
[% END %] [% END %]
......
...@@ -231,9 +231,9 @@ sub changeEmail { ...@@ -231,9 +231,9 @@ sub changeEmail {
# The new email address should be available as this was # The new email address should be available as this was
# confirmed initially so cancel token if it is not still available # confirmed initially so cancel token if it is not still available
if (! ValidateNewUser($new_email,$old_email)) { if (! ValidateNewUser($new_email,$old_email)) {
$vars->{'email'} = $new_email; $vars->{'email'} = $new_email; # Needed for Token::Cancel's mail
Token::Cancel($::token,"account_exists"); Token::Cancel($::token,"account_exists");
ThrowUserError("account_exists"); ThrowUserError("account_exists", { email => $new_email } );
} }
# Update the user's login name in the profiles table and delete the token # Update the user's login name in the profiles table and delete the token
......
...@@ -385,7 +385,8 @@ SWITCH: for ($current_tab_name) { ...@@ -385,7 +385,8 @@ SWITCH: for ($current_tab_name) {
DoPermissions(); DoPermissions();
last SWITCH; last SWITCH;
}; };
ThrowUserError("current_tab_name"); ThrowUserError("unknown_tab",
{ current_tab_name => $current_tab_name });
} }
# Generate and return the UI (HTML page) from the appropriate template. # Generate and return the UI (HTML page) from the appropriate template.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment