Commit f6a1bb13 authored by Simon Green's avatar Simon Green Committed by Frédéric Buclin

Bug 838846: In Product.get, include_fields => ['components'] no longer returns…

Bug 838846: In Product.get, include_fields => ['components'] no longer returns data about components r/a=LpSolit
parent d5f626b5
...@@ -267,6 +267,13 @@ the returned hashes. ...@@ -267,6 +267,13 @@ the returned hashes.
If you specify all the fields, then this function will return empty If you specify all the fields, then this function will return empty
hashes. hashes.
Some RPC calls support specifying sub fields. If an RPC call states that
it support sub field restrictions, you can restrict what information is
returned within the first field. For example, if you call Products.get
with an include_fields of components.name, then only the component name
would be returned (and nothing else). You can include the main field,
and exclude a sub field.
Invalid field names are ignored. Invalid field names are ignored.
Specifying fields here overrides C<include_fields>, so if you specify a Specifying fields here overrides C<include_fields>, so if you specify a
......
...@@ -212,12 +212,12 @@ sub _product_to_hash { ...@@ -212,12 +212,12 @@ sub _product_to_hash {
} }
if (filter_wants($params, 'versions')) { if (filter_wants($params, 'versions')) {
$field_data->{versions} = [map { $field_data->{versions} = [map {
$self->_version_to_hash($_) $self->_version_to_hash($_, $params)
} @{$product->versions}]; } @{$product->versions}];
} }
if (filter_wants($params, 'milestones')) { if (filter_wants($params, 'milestones')) {
$field_data->{milestones} = [map { $field_data->{milestones} = [map {
$self->_milestone_to_hash($_) $self->_milestone_to_hash($_, $params)
} @{$product->milestones}]; } @{$product->milestones}];
} }
return filter($params, $field_data); return filter($params, $field_data);
...@@ -241,23 +241,26 @@ sub _component_to_hash { ...@@ -241,23 +241,26 @@ sub _component_to_hash {
0, 0,
is_active => is_active =>
$self->type('boolean', $component->is_active), $self->type('boolean', $component->is_active),
flag_types => { };
if (filter_wants($params, 'flag_types', 'components')) {
$field_data->{flag_types} = {
bug => bug =>
[map { [map {
$self->_flag_type_to_hash($_, $params) $self->_flag_type_to_hash($_)
} @{$component->flag_types->{'bug'}}], } @{$component->flag_types->{'bug'}}],
attachment => attachment =>
[map { [map {
$self->_flag_type_to_hash($_, $params) $self->_flag_type_to_hash($_)
} @{$component->flag_types->{'attachment'}}], } @{$component->flag_types->{'attachment'}}],
} };
}; }
return filter($params, $field_data, 'component'); return filter($params, $field_data, 'components');
} }
sub _flag_type_to_hash { sub _flag_type_to_hash {
my ($self, $flag_type, $params) = @_; my ($self, $flag_type) = @_;
my $field_data = { return {
id => id =>
$self->type('int', $flag_type->id), $self->type('int', $flag_type->id),
name => name =>
...@@ -281,12 +284,11 @@ sub _flag_type_to_hash { ...@@ -281,12 +284,11 @@ sub _flag_type_to_hash {
request_group => request_group =>
$self->type('int', $flag_type->request_group_id), $self->type('int', $flag_type->request_group_id),
}; };
return filter($params, $field_data, 'flag_type');
} }
sub _version_to_hash { sub _version_to_hash {
my ($self, $version) = @_; my ($self, $version, $params) = @_;
return { my $field_data = {
id => id =>
$self->type('int', $version->id), $self->type('int', $version->id),
name => name =>
...@@ -296,11 +298,12 @@ sub _version_to_hash { ...@@ -296,11 +298,12 @@ sub _version_to_hash {
is_active => is_active =>
$self->type('boolean', $version->is_active), $self->type('boolean', $version->is_active),
}; };
return filter($params, $field_data, 'versions');
} }
sub _milestone_to_hash { sub _milestone_to_hash {
my ($self, $milestone) = @_; my ($self, $milestone, $params) = @_;
return { my $field_data = {
id => id =>
$self->type('int', $milestone->id), $self->type('int', $milestone->id),
name => name =>
...@@ -310,6 +313,7 @@ sub _milestone_to_hash { ...@@ -310,6 +313,7 @@ sub _milestone_to_hash {
is_active => is_active =>
$self->type('boolean', $milestone->is_active), $self->type('boolean', $milestone->is_active),
}; };
return filter($params, $field_data, 'milestones');
} }
1; 1;
...@@ -417,6 +421,8 @@ In addition to the parameters below, this method also accepts the ...@@ -417,6 +421,8 @@ In addition to the parameters below, this method also accepts the
standard L<include_fields|Bugzilla::WebService/include_fields> and standard L<include_fields|Bugzilla::WebService/include_fields> and
L<exclude_fields|Bugzilla::WebService/exclude_fields> arguments. L<exclude_fields|Bugzilla::WebService/exclude_fields> arguments.
This RPC call supports sub field restrictions.
=over =over
=item C<ids> =item C<ids>
......
...@@ -40,11 +40,20 @@ sub filter_wants ($$;$) { ...@@ -40,11 +40,20 @@ sub filter_wants ($$;$) {
$field = "${prefix}.${field}" if $prefix; $field = "${prefix}.${field}" if $prefix;
if (defined $params->{include_fields}) { if (defined $params->{exclude_fields} && $exclude{$field}) {
return 0 if !$include{$field}; return 0;
} }
if (defined $params->{exclude_fields}) { if (defined $params->{include_fields} && !$include{$field}) {
return 0 if $exclude{$field}; if ($prefix) {
# Include the field if the parent is include (and this one is not excluded)
return 0 if !$include{$prefix};
}
else {
# We want to include this if one of the sub keys is included
my $key = $field . '.';
my $len = length($key);
return 0 if ! grep { substr($_, 0, $len) eq $key } keys %include;
}
} }
return 1; return 1;
......
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