From 0d280b9011568abf2c5f95a33fd20195b91528d9 Mon Sep 17 00:00:00 2001 From: Max Kanat-Alexander Date: Tue, 20 Jul 2010 14:58:47 -0700 Subject: Bug 579514: Make Bug.attachments also return attachment data r=dkl, a=mkanat --- Bugzilla/WebService/Util.pm | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'Bugzilla/WebService/Util.pm') 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 +=item C This helps implement the C and C arguments of WebService methods. Given a hash (the second argument to this subroutine), this will remove any keys that are I in C and then remove any keys that I in C. +=item C + +Returns C<1> if a filter would preserve the specified field when passing +a hash to L, C<0> otherwise. + =item C This helps in the validation of parameters passed into the WebSerice -- cgit v1.2.3-24-g4f1b