diff options
author | Max Kanat-Alexander <mkanat@bugzilla.org> | 2010-07-20 23:58:47 +0200 |
---|---|---|
committer | Max Kanat-Alexander <mkanat@bugzilla.org> | 2010-07-20 23:58:47 +0200 |
commit | 0d280b9011568abf2c5f95a33fd20195b91528d9 (patch) | |
tree | f08cd0a72cc845e7577f863f86ef7ade48f6a563 /Bugzilla/WebService/Util.pm | |
parent | 69be160f92f1d20408c0e390610dffbd619f63cb (diff) | |
download | bugzilla-0d280b9011568abf2c5f95a33fd20195b91528d9.tar.gz bugzilla-0d280b9011568abf2c5f95a33fd20195b91528d9.tar.xz |
Bug 579514: Make Bug.attachments also return attachment data
r=dkl, a=mkanat
Diffstat (limited to 'Bugzilla/WebService/Util.pm')
-rw-r--r-- | Bugzilla/WebService/Util.pm | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/Bugzilla/WebService/Util.pm b/Bugzilla/WebService/Util.pm index dbf5ec593..e94feb490 100644 --- a/Bugzilla/WebService/Util.pm +++ b/Bugzilla/WebService/Util.pm @@ -28,7 +28,8 @@ use base qw(Exporter); require Test::Taint; our @EXPORT_OK = qw( - filter + filter + filter_wants taint_data validate ); @@ -36,21 +37,29 @@ our @EXPORT_OK = qw( sub filter ($$) { my ($params, $hash) = @_; my %newhash = %$hash; - my %include = map { $_ => 1 } @{ $params->{'include_fields'} || [] }; - my %exclude = map { $_ => 1 } @{ $params->{'exclude_fields'} || [] }; foreach my $key (keys %$hash) { - if (defined $params->{include_fields}) { - delete $newhash{$key} if !$include{$key}; - } - if (defined $params->{exclude_fields}) { - delete $newhash{$key} if $exclude{$key}; - } + delete $newhash{$key} if !filter_wants($params, $key); } return \%newhash; } +sub filter_wants ($$) { + my ($params, $field) = @_; + my %include = map { $_ => 1 } @{ $params->{'include_fields'} || [] }; + my %exclude = map { $_ => 1 } @{ $params->{'exclude_fields'} || [] }; + + if (defined $params->{include_fields}) { + return 0 if !$include{$field}; + } + if (defined $params->{exclude_fields}) { + return 0 if $exclude{$field}; + } + + return 1; +} + sub taint_data { my @params = @_; return if !@params; @@ -115,20 +124,25 @@ internally in the WebService code. filter({ include_fields => ['id', 'name'], exclude_fields => ['name'] }, $hash); - + my $wants = filter_wants $params, 'field_name'; validate(@_, 'ids'); =head1 METHODS =over -=item C<filter_fields> +=item C<filter> This helps implement the C<include_fields> and C<exclude_fields> arguments of WebService methods. Given a hash (the second argument to this subroutine), this will remove any keys that are I<not> in C<include_fields> and then remove any keys that I<are> in C<exclude_fields>. +=item C<filter_wants> + +Returns C<1> if a filter would preserve the specified field when passing +a hash to L</filter>, C<0> otherwise. + =item C<validate> This helps in the validation of parameters passed into the WebSerice |