use base qw(Bugzilla::Object Exporter);
@Bugzilla::Bug::EXPORT = qw(
- bug_alias_to_id ValidateBugID
+ bug_alias_to_id
RemoveVotes CheckIfVotedConfirmed
LogActivityEntry
editable_bug_fields
my @bug_ids = split(/[\s,]+/, $deps_in{$type});
# Eliminate nulls.
@bug_ids = grep {$_} @bug_ids;
- # We do Validate up here to make sure all aliases are converted to IDs.
- ValidateBugID($_, $type) foreach @bug_ids;
+ # We do this up here to make sure all aliases are converted to IDs.
+ @bug_ids = map { $invocant->check($_, $type)->id } @bug_ids;
my @check_access = @bug_ids;
# When we're updating a bug, only added or removed bug_ids are
my $user = Bugzilla->user;
foreach my $modified_id (@check_access) {
- ValidateBugID($modified_id);
+ my $delta_bug = $invocant->check($modified_id);
# Under strict isolation, you can't modify a bug if you can't
# edit it, even if you can see it.
if (Bugzilla->params->{"strict_isolation"}) {
- my $delta_bug = new Bugzilla::Bug($modified_id);
if (!$user->can_edit_product($delta_bug->{'product_id'})) {
ThrowUserError("illegal_change_deps", {field => $type});
}
$dupe_of = trim($dupe_of);
$dupe_of || ThrowCodeError('undefined_field', { field => 'dup_id' });
# Make sure we can change the original bug (issue A on bug 96085)
- ValidateBugID($dupe_of, 'dup_id');
+ my $dupe_of_bug = $self->check($dupe_of, 'dup_id');
# Make sure a loop isn't created when marking this bug
# as duplicate.
# Should we add the reporter to the CC list of the new bug?
# If he can see the bug...
if ($self->reporter->can_see_bug($dupe_of)) {
- my $dupe_of_bug = new Bugzilla::Bug($dupe_of);
# We only add him if he's not the reporter of the other bug.
$self->{_add_dup_cc} = 1
if $dupe_of_bug->reporter->id != $self->reporter->id;
my $vars = {};
my $template = Bugzilla->template;
# Ask the user what they want to do about the reporter.
- $vars->{'cclist_accessible'} = $dbh->selectrow_array(
- q{SELECT cclist_accessible FROM bugs WHERE bug_id = ?},
- undef, $dupe_of);
+ $vars->{'cclist_accessible'} = $dupe_of_bug->cclist_accessible;
$vars->{'original_bug_id'} = $dupe_of;
$vars->{'duplicate_bug_id'} = $self->id;
print $cgi->header();
my @return;
foreach my $bug_id (@$ids) {
my %item;
- ValidateBugID($bug_id);
+ my $bug = Bugzilla::Bug->check($bug_id);
+ $bug_id = $bug->id;
my ($activity) = Bugzilla::Bug::GetBugActivity($bug_id);
$item{$bug_id} = [];
# alias is returned in case users passes a mixture of ids and aliases
# then they get to know which bug activity relates to which value
# they passed
- my $bug = new Bugzilla::Bug($bug_id);
if (Bugzilla->params->{'usebugaliases'}) {
$item{alias} = type('string')->value($bug->alias);
}
|| ThrowUserError("invalid_attach_id", { attach_id => $attach_id });
# Make sure the user is authorized to access this attachment's bug.
- ValidateBugID($attachment->bug_id);
- if ($attachment->isprivate && $user->id != $attachment->attacher->id && !$user->is_insider) {
+ Bugzilla::Bug->check($attachment->bug_id);
+ if ($attachment->isprivate && $user->id != $attachment->attacher->id
+ && !$user->is_insider)
+ {
ThrowUserError('auth_failure', {action => 'access',
object => 'attachment'});
}
# HTML page.
sub viewall {
# Retrieve and validate parameters
- my $bugid = $cgi->param('bugid');
- ValidateBugID($bugid);
- my $bug = new Bugzilla::Bug($bugid);
+ my $bug = Bugzilla::Bug->check(scalar $cgi->param('bugid'));
+ my $bugid = $bug->id;
my $attachments = Bugzilla::Attachment->get_attachments_by_bug($bugid);
# Display a form for entering a new attachment.
sub enter {
# Retrieve and validate parameters
- my $bugid = $cgi->param('bugid');
- ValidateBugID($bugid);
+ my $bug = Bugzilla::Bug->check(scalar $cgi->param('bugid'));
+ my $bugid = $bug->id;
validateCanChangeBug($bugid);
my $dbh = Bugzilla->dbh;
my $user = Bugzilla->user;
- my $bug = new Bugzilla::Bug($bugid, $user->id);
# Retrieve the attachments the user can edit from the database and write
# them into an array of hashes where each hash represents one attachment.
my $canEdit = "";
$dbh->bz_start_transaction;
# Retrieve and validate parameters
- my $bugid = $cgi->param('bugid');
- ValidateBugID($bugid);
+ my $bug = Bugzilla::Bug->check(scalar $cgi->param('bugid'));
+ my $bugid = $bug->id;
validateCanChangeBug($bugid);
my ($timestamp) = Bugzilla->dbh->selectrow_array("SELECT NOW()");
}
}
- my $bug = new Bugzilla::Bug($bugid);
my $attachment =
Bugzilla::Attachment->insert_attachment_for_bug(THROW_ERROR, $bug, $user,
$timestamp, $vars);
my $changes = 0;
foreach my $bug_id (split(/[\s,]+/, $cgi->param('bug_ids'))) {
next unless $bug_id;
- ValidateBugID($bug_id);
- $bug_ids{$bug_id} = $keep_bug;
+ my $bug = Bugzilla::Bug->check($bug_id);
+ $bug_ids{$bug->id} = $keep_bug;
$changes = 1;
}
ThrowUserError('no_bug_ids',
use Encode;
use Bugzilla;
-use Bugzilla::Bug qw(ValidateBugID);
+use Bugzilla::Bug;
use Bugzilla::Constants qw(USAGE_MODE_EMAIL);
use Bugzilla::Error;
use Bugzilla::Mailer;
debug_print("Updating Bug $fields{id}...");
- ValidateBugID($bug_id);
- my $bug = new Bugzilla::Bug($bug_id);
+ my $bug = Bugzilla::Bug->check($bug_id);
if ($fields{'bug_status'}) {
$fields{'knob'} = $fields{'bug_status'};
$cloned_bug_id = $cgi->param('cloned_bug_id');
if ($cloned_bug_id) {
- ValidateBugID($cloned_bug_id);
- $cloned_bug = new Bugzilla::Bug($cloned_bug_id);
+ $cloned_bug = Bugzilla::Bug->check($cloned_bug_id);
+ $cloned_bug_id = $cloned_bug->id;
}
if (scalar(@{$product->components}) == 1) {
# Create a list of objects for all bugs being modified in this request.
my @bug_objects;
if (defined $cgi->param('id')) {
- my $id = $cgi->param('id');
- ValidateBugID($id);
-
- # Store the validated, and detainted id back in the cgi data, as
- # lots of later code will need it, and will obtain it from there
- $cgi->param('id', $id);
- push(@bug_objects, new Bugzilla::Bug($id));
+ my $bug = Bugzilla::Bug->check(scalar $cgi->param('id'));
+ $cgi->param('id', $bug->id);
+ push(@bug_objects, $bug);
} else {
- my @ids;
foreach my $i ($cgi->param()) {
if ($i =~ /^id_([1-9][0-9]*)/) {
my $id = $1;
- ValidateBugID($id);
- push(@ids, $id);
+ push(@bug_objects, Bugzilla::Bug->check($id));
}
}
- @bug_objects = @{Bugzilla::Bug->new_from_list(\@ids)};
}
# Make sure there are bugs to process.
# Make sure the bug ID is a positive integer representing an existing
# bug that the user is authorized to access.
-my $bug_id = $cgi->param('id');
-ValidateBugID($bug_id);
+my $id = $cgi->param('id');
+my $bug = Bugzilla::Bug->check($id);
###############################################################################
# End Data/Security Validation
###############################################################################
($vars->{'operations'}, $vars->{'incomplete_data'}) =
- Bugzilla::Bug::GetBugActivity($bug_id);
+ Bugzilla::Bug::GetBugActivity($bug->id);
-$vars->{'bug'} = new Bugzilla::Bug($bug_id);
+$vars->{'bug'} = $bug;
print $cgi->header();
if ($single) {
my $id = $cgi->param('id');
- # Its a bit silly to do the validation twice - that functionality should
- # probably move into Bug.pm at some point
- ValidateBugID($id);
- push @bugs, new Bugzilla::Bug($id);
+ push @bugs, Bugzilla::Bug->check($id);
if (defined $cgi->param('mark')) {
foreach my $range (split ',', $cgi->param('mark')) {
if ($range =~ /^(\d+)-(\d+)$/) {
}
} else {
foreach my $i (split('[\s,]+', $cgi->param('id'))) {
- ValidateBugID($i);
- $baselist{$i} = 1;
+ my $bug = Bugzilla::Bug->check($i);
+ $baselist{$bug->id} = 1;
}
my @stack = keys(%baselist);
# Make sure the bug ID is a positive integer representing an existing
# bug that the user is authorized to access.
-my $id = $cgi->param('id') || ThrowUserError('improper_bug_id_field_value');
-ValidateBugID($id);
-my $current_bug = new Bugzilla::Bug($id);
+my $bug = Bugzilla::Bug->check(scalar $cgi->param('id'));
+my $id = $bug->id;
local our $hide_resolved = $cgi->param('hide_resolved') ? 1 : 0;
# Generate the tree of bugs that this bug depends on and a list of IDs
# appearing in the tree.
-my $dependson_tree = { $id => $current_bug };
+my $dependson_tree = { $id => $bug };
my $dependson_ids = {};
GenerateTree($id, "dependson", 1, $dependson_tree, $dependson_ids);
$vars->{'dependson_tree'} = $dependson_tree;
# Generate the tree of bugs that this bug blocks and a list of IDs
# appearing in the tree.
-my $blocked_tree = { $id => $current_bug };
+my $blocked_tree = { $id => $bug };
my $blocked_ids = {};
GenerateTree($id, "blocked", 1, $blocked_tree, $blocked_ids);
$vars->{'blocked_tree'} = $blocked_tree;
object => "timetracking_summaries"});
my @ids = split(",", $cgi->param('id'));
-map { ValidateBugID($_) } @ids;
+@ids = map { Bugzilla::Bug->check($_)->id } @ids;
scalar(@ids) || ThrowUserError('no_bugs_chosen', {action => 'view'});
my $group_by = $cgi->param('group_by') || "number";
# Make sure the bug ID is a positive integer representing an existing
# bug that the user is authorized to access.
-ValidateBugID($bug_id) if defined $bug_id;
+if (defined $bug_id) {
+ my $bug = Bugzilla::Bug->check($bug_id);
+ $bug_id = $bug->id;
+}
################################################################################
# End Data/Security Validation
}
}
- # Call ValidateBugID on each bug ID to make sure it is a positive
+ # Call check() on each bug ID to make sure it is a positive
# integer representing an existing bug that the user is authorized
# to access, and make sure the number of votes submitted is also
# a non-negative integer (a series of digits not preceded by a
# minus sign).
my %votes;
foreach my $id (@buglist) {
- ValidateBugID($id);
+ my $bug = Bugzilla::Bug->check($id);
+ $id = $bug->id;
$votes{$id} = $cgi->param($id);
detaint_natural($votes{$id})
|| ThrowUserError("votes_must_be_nonnegative");