summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authorDavid Lawrence <dkl@redhat.com>2014-06-16 17:15:35 +0200
committerDavid Lawrence <dkl@redhat.com>2014-06-16 17:15:35 +0200
commit0a2592d00b9d230f78b69c5808cbca108af54967 (patch)
tree6a0d72b2433b75c2ef8879ec23ff1ff507eb6165 /Bugzilla
parentdd10df6857319589e15cc404ad8690cdf54a6768 (diff)
downloadbugzilla-0a2592d00b9d230f78b69c5808cbca108af54967.tar.gz
bugzilla-0a2592d00b9d230f78b69c5808cbca108af54967.tar.xz
Bug 880669 - Extend current BzAPI BMO extension to contain compatibility changes on top of native rest
r=glob
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/Util.pm8
-rw-r--r--Bugzilla/WebService/Bug.pm29
-rw-r--r--Bugzilla/WebService/Server/REST.pm26
-rw-r--r--Bugzilla/WebService/Util.pm10
4 files changed, 54 insertions, 19 deletions
diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm
index 225edbe4a..27a7e5e23 100644
--- a/Bugzilla/Util.pm
+++ b/Bugzilla/Util.pm
@@ -45,7 +45,7 @@ use base qw(Exporter);
bz_crypt generate_random_password
validate_email_syntax clean_text
get_text template_var disable_utf8
- detect_encoding email_filter);
+ enable_utf8 detect_encoding email_filter);
use Bugzilla::Constants;
use Bugzilla::RNG qw(irand);
@@ -778,6 +778,12 @@ sub disable_utf8 {
}
}
+sub enable_utf8 {
+ if (Bugzilla->params->{'utf8'}) {
+ binmode STDOUT, ':utf8'; # Turn on UTF8 encoding.
+ }
+}
+
use constant UTF8_ACCIDENTAL => qw(shiftjis big5-eten euc-kr euc-jp);
sub detect_encoding {
diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm
index 710bff112..a82f55d3b 100644
--- a/Bugzilla/WebService/Bug.pm
+++ b/Bugzilla/WebService/Bug.pm
@@ -54,11 +54,25 @@ use Storable qw(dclone);
use constant PRODUCT_SPECIFIC_FIELDS => qw(version target_milestone component);
-use constant DATE_FIELDS => {
- comments => ['new_since'],
- history => ['new_since'],
- search => ['last_change_time', 'creation_time'],
-};
+sub DATE_FIELDS {
+ my $fields = {
+ comments => ['new_since'],
+ create => [],
+ history => ['new_since'],
+ search => ['last_change_time', 'creation_time'],
+ update => []
+ };
+
+ # Add date related custom fields
+ foreach my $field (Bugzilla->active_custom_fields) {
+ next unless ($field->type == FIELD_TYPE_DATETIME
+ || $field->type == FIELD_TYPE_DATE);
+ push(@{ $fields->{create} }, $field->name);
+ push(@{ $fields->{update} }, $field->name);
+ }
+
+ return $fields;
+}
use constant BASE64_FIELDS => {
add_attachment => ['data'],
@@ -558,7 +572,7 @@ sub search {
# Backwards compatibility with old method regarding role search
$match_params->{'reporter'} = delete $match_params->{'creator'} if $match_params->{'creator'};
- foreach my $role (qw(assigned_to reporter qa_contact longdesc cc)) {
+ foreach my $role (qw(assigned_to reporter qa_contact commenter cc)) {
next if !exists $match_params->{$role};
my $value = delete $match_params->{$role};
$match_params->{"f${last_field_id}"} = $role;
@@ -594,6 +608,9 @@ sub search {
my @bugs = map { $bug_objects{$_} } @bug_ids;
@bugs = map { $self->_bug_to_hash($_, $params) } @bugs;
+ # BzAPI
+ Bugzilla->request_cache->{bzapi_search_bugs} = [ map { $bug_objects{$_} } @bug_ids ];
+
return { bugs => \@bugs };
}
diff --git a/Bugzilla/WebService/Server/REST.pm b/Bugzilla/WebService/Server/REST.pm
index 96e4b3179..1be457c8f 100644
--- a/Bugzilla/WebService/Server/REST.pm
+++ b/Bugzilla/WebService/Server/REST.pm
@@ -16,7 +16,7 @@ use Bugzilla;
use Bugzilla::Constants;
use Bugzilla::Error;
use Bugzilla::Hook;
-use Bugzilla::Util qw(correct_urlbase html_quote);
+use Bugzilla::Util qw(correct_urlbase html_quote disable_utf8 enable_utf8);
use Bugzilla::WebService::Constants;
use Bugzilla::WebService::Util qw(taint_data fix_credentials);
@@ -78,8 +78,12 @@ sub handle {
# Fix includes/excludes for each call
rest_include_exclude($params);
- # Set callback name if exists
- $self->_bz_callback($params->{'callback'}) if $params->{'callback'};
+ # Set callback name if content-type is 'application/javascript'
+ if ($params->{'callback'}
+ || $self->content_type eq 'application/javascript')
+ {
+ $self->_bz_callback($params->{'callback'} || 'callback');
+ }
Bugzilla->input_params($params);
@@ -111,8 +115,13 @@ sub response {
# along with the result/error such as version and id which
# we will strip off for REST calls.
my $content = $response->content;
+
my $json_data = {};
if ($content) {
+ # Content is in bytes at this point and needs to be converted
+ # back to utf8 string.
+ enable_utf8();
+ utf8::decode($content) if !utf8::is_utf8($content);
$json_data = $self->json->decode($content);
}
@@ -152,6 +161,9 @@ sub response {
$content = $self->json->encode($result);
}
+ utf8::encode($content) if utf8::is_utf8($content);
+ disable_utf8();
+
$response->content($content);
$self->SUPER::response($response);
@@ -307,16 +319,16 @@ sub bz_rest_params {
sub bz_rest_options {
my ($self, $options) = @_;
$self->{_bz_rest_options} = $options if $options;
- return $self->{_bz_rest_options};
+ return [ sort { $a cmp $b } @{ $self->{_bz_rest_options} } ];
}
sub rest_include_exclude {
my ($params) = @_;
- if ($params->{'include_fields'} && !ref $params->{'include_fields'}) {
+ if (exists $params->{'include_fields'} && !ref $params->{'include_fields'}) {
$params->{'include_fields'} = [ split(/[\s+,]/, $params->{'include_fields'}) ];
}
- if ($params->{'exclude_fields'} && !ref $params->{'exclude_fields'}) {
+ if (exists $params->{'exclude_fields'} && !ref $params->{'exclude_fields'}) {
$params->{'exclude_fields'} = [ split(/[\s+,]/, $params->{'exclude_fields'}) ];
}
@@ -344,7 +356,7 @@ sub _retrieve_json_params {
my $extra_params = {};
my $json = delete $params->{'POSTDATA'} || delete $params->{'PUTDATA'};
if ($json) {
- eval { $extra_params = $self->json->decode($json); };
+ eval { $extra_params = $self->json->utf8(0)->decode($json); };
if ($@) {
ThrowUserError('json_rpc_invalid_params', { err_msg => $@ });
}
diff --git a/Bugzilla/WebService/Util.pm b/Bugzilla/WebService/Util.pm
index 9f053095c..856fd3481 100644
--- a/Bugzilla/WebService/Util.pm
+++ b/Bugzilla/WebService/Util.pm
@@ -166,14 +166,14 @@ sub filter_wants($$;$$) {
delete $exclude{$key};
}
- # If the user has asked to include all or exclude all
- return $cache->{$field} = 0 if $exclude_types{'all'};
- return $cache->{$field} = 1 if $include_types{'all'};
-
# Explicit inclusion/exclusion
return $cache->{$field} = 0 if $exclude{$field};
return $cache->{$field} = 1 if $include{$field};
+ # If the user has asked to include all or exclude all
+ return $cache->{$field} = 0 if $exclude_types{'all'};
+ return $cache->{$field} = 1 if $include_types{'all'};
+
# If the user has not asked for any fields specifically or if the user has asked
# for one or more of the field's types (and not excluded them)
foreach my $type (keys %field_types) {
@@ -214,7 +214,7 @@ sub _delete_bad_keys {
# However, we need to validate our argument names in some way.
# We know that all hash keys passed in to the WebService will
# match \w+, so we delete any key that doesn't match that.
- if ($key !~ /^\w+$/) {
+ if ($key !~ /^[\w\.\-]+$/) {
delete $item->{$key};
}
}