From 59a35402749a8b20db50b810ce29c1479594dced Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Thu, 10 Dec 2009 22:18:05 +0000 Subject: Bug 526158: Make email_in.pl use Bugzilla::Bug->create to create bugs instead of requiring post_bug.cgi Patch by Max Kanat-Alexander r=LpSolit, a=LpSolit --- Bugzilla/Bug.pm | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'Bugzilla/Bug.pm') diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index d55549cd6..83e95aecd 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -236,6 +236,27 @@ use constant UPDATE_COMMENT_COLUMNS => qw( # activity table. use constant MAX_LINE_LENGTH => 254; +# This maps the names of internal Bugzilla bug fields to things that would +# make sense to somebody who's not intimately familiar with the inner workings +# of Bugzilla. (These are the field names that the WebService and email_in.pl +# use.) +use constant FIELD_MAP => { + creation_time => 'creation_ts', + description => 'comment', + id => 'bug_id', + last_change_time => 'delta_ts', + platform => 'rep_platform', + severity => 'bug_severity', + status => 'bug_status', + summary => 'short_desc', + url => 'bug_file_loc', + whiteboard => 'status_whiteboard', + + # These are special values for the WebService Bug.search method. + limit => 'LIMIT', + offset => 'OFFSET', +}; + ##################################################################### sub new { @@ -557,7 +578,6 @@ sub create { return $bug; } - sub run_create_validators { my $class = shift; my $params = $class->SUPER::run_create_validators(@_); @@ -1168,6 +1188,9 @@ sub _check_cc { my ($invocant, $component, $ccs) = @_; return [map {$_->id} @{$component->initial_cc}] unless $ccs; + # Allow comma-separated input as well as arrayrefs. + $ccs = [split(/[\s,]+/, $ccs)] if !ref $ccs; + my %cc_ids; foreach my $person (@$ccs) { next unless $person; @@ -1732,6 +1755,17 @@ sub _check_freetext_field { sub _check_multi_select_field { my ($invocant, $values, $field) = @_; + + # Allow users (mostly email_in.pl) to specify multi-selects as + # comma-separated values. + if (defined $values and !ref $values) { + # We don't split on spaces because multi-select values can and often + # do have spaces in them. (Theoretically they can have commas in them + # too, but that's much less common and people should be able to work + # around it pretty cleanly, if they want to use email_in.pl.) + $values = [split(',', $values)]; + } + return [] if !$values; my @checked_values; foreach my $value (@$values) { @@ -1865,6 +1899,7 @@ sub set_component { } sub set_custom_field { my ($self, $field, $value) = @_; + if (ref $value eq 'ARRAY' && $field->type != FIELD_TYPE_MULTI_SELECT) { $value = $value->[0]; } @@ -3177,6 +3212,25 @@ sub LogActivityEntry { } } +# Convert WebService API and email_in.pl field names to internal DB field +# names. +sub map_fields { + my ($params) = @_; + + my %field_values; + foreach my $field (keys %$params) { + my $field_name = FIELD_MAP->{$field} || $field; + $field_values{$field_name} = $params->{$field}; + } + + # This protects the WebService Bug.search method. + unless (Bugzilla->user->is_timetracker) { + delete @field_values{qw(estimated_time remaining_time deadline)}; + } + + return \%field_values; +} + # CountOpenDependencies counts the number of open dependent bugs for a # list of bugs and returns a list of bug_id's and their dependency count # It takes one parameter: -- cgit v1.2.3-24-g4f1b