summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authormkanat%bugzilla.org <>2009-12-10 23:18:05 +0100
committermkanat%bugzilla.org <>2009-12-10 23:18:05 +0100
commit59a35402749a8b20db50b810ce29c1479594dced (patch)
tree85f5c1fa1c4043dff77b2da71c0219c9bf2e6105 /Bugzilla
parent56285b05dcdc9ebfe8df8119b387205def6db9dc (diff)
downloadbugzilla-59a35402749a8b20db50b810ce29c1479594dced.tar.gz
bugzilla-59a35402749a8b20db50b810ce29c1479594dced.tar.xz
Bug 526158: Make email_in.pl use Bugzilla::Bug->create to create bugs instead of requiring post_bug.cgi
Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=LpSolit
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/Bug.pm56
-rw-r--r--Bugzilla/User.pm9
-rw-r--r--Bugzilla/WebService/Bug.pm43
3 files changed, 67 insertions, 41 deletions
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:
diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm
index 7c458388c..3e6f3b6ba 100644
--- a/Bugzilla/User.pm
+++ b/Bugzilla/User.pm
@@ -716,7 +716,14 @@ sub can_enter_product {
my $dbh = Bugzilla->dbh;
$warn ||= 0;
- if (!defined $input) {
+ $input = trim($input) if !ref $input;
+ if (!defined $input or $input eq '') {
+ return unless $warn == THROW_ERROR;
+ ThrowUserError('object_not_specified',
+ { class => 'Bugzilla::Product' });
+ }
+
+ if (!scalar @{ $self->get_enterable_products }) {
return unless $warn == THROW_ERROR;
ThrowUserError('no_products');
}
diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm
index ad4bb9f30..33135f059 100644
--- a/Bugzilla/WebService/Bug.pm
+++ b/Bugzilla/WebService/Bug.pm
@@ -37,24 +37,6 @@ use Bugzilla::Util qw(trim);
# Constants #
#############
-# 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 uses.)
-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',
- limit => 'LIMIT',
- offset => 'OFFSET',
-};
-
use constant PRODUCT_SPECIFIC_FIELDS => qw(version target_milestone component);
use constant DATE_FIELDS => {
@@ -251,7 +233,7 @@ sub search {
{ param => 'limit', function => 'Bug.search()' });
}
- $params = _map_fields($params);
+ $params = Bugzilla::Bug::map_fields($params);
delete $params->{WHERE};
# Do special search types for certain fields.
@@ -286,7 +268,7 @@ sub search {
sub create {
my ($self, $params) = @_;
Bugzilla->login(LOGIN_REQUIRED);
- $params = _map_fields($params);
+ $params = Bugzilla::Bug::map_fields($params);
my $bug = Bugzilla::Bug->create($params);
Bugzilla::BugMail::Send($bug->bug_id, { changer => $bug->reporter->login });
return { id => $self->type('int', $bug->bug_id) };
@@ -294,7 +276,8 @@ sub create {
sub legal_values {
my ($self, $params) = @_;
- my $field = FIELD_MAP->{$params->{field}} || $params->{field};
+ my $field = Bugzilla::Bug::FIELD_MAP->{$params->{field}}
+ || $params->{field};
my @global_selects = Bugzilla->get_fields(
{type => [FIELD_TYPE_SINGLE_SELECT, FIELD_TYPE_MULTI_SELECT]});
@@ -520,24 +503,6 @@ sub _attachment_to_hash {
};
}
-# Convert WebService API field names to internal DB field names.
-# Used by create() and search().
-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};
- }
-
- unless (Bugzilla->user->is_timetracker) {
- delete @field_values{qw(estimated_time remaining_time deadline)};
- }
-
- return \%field_values;
-}
-
1;
__END__