diff options
author | Frank Becker <Frank@Frank-Becker.de> | 2012-07-31 06:40:07 +0200 |
---|---|---|
committer | Dave Lawrence <dlawrence@mozilla.com> | 2012-07-31 06:40:07 +0200 |
commit | 13baf25cc7c01779bb50931f22d52ac6ad1504d0 (patch) | |
tree | edaa34d3ac537a53f25c5b877503c5d65a3bb9a5 | |
parent | 9f657478549c3d35623e08957930d1cc62c20ddc (diff) | |
download | bugzilla-13baf25cc7c01779bb50931f22d52ac6ad1504d0.tar.gz bugzilla-13baf25cc7c01779bb50931f22d52ac6ad1504d0.tar.xz |
Bug 775056 - Add prefix to filter() and filter_wants()
-rw-r--r-- | Bugzilla/WebService/Util.pm | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/Bugzilla/WebService/Util.pm b/Bugzilla/WebService/Util.pm index adb7fb43a..6d3a37767 100644 --- a/Bugzilla/WebService/Util.pm +++ b/Bugzilla/WebService/Util.pm @@ -34,27 +34,30 @@ our @EXPORT_OK = qw( validate ); -sub filter ($$) { - my ($params, $hash) = @_; +sub filter ($$;$) { + my ($params, $hash, $prefix) = @_; my %newhash = %$hash; foreach my $key (keys %$hash) { - delete $newhash{$key} if !filter_wants($params, $key); + delete $newhash{$key} if !filter_wants($params, $key, $prefix); } return \%newhash; } -sub filter_wants ($$) { - my ($params, $field) = @_; +sub filter_wants ($$;$) { + my ($params, $field, $prefix) = @_; my %include = map { $_ => 1 } @{ $params->{'include_fields'} || [] }; my %exclude = map { $_ => 1 } @{ $params->{'exclude_fields'} || [] }; + my $field_temp; + + $field = "${prefix}.${field}" if $prefix; if (defined $params->{include_fields}) { - return 0 if !$include{$field}; + return 0 if !$include{$field_temp}; } if (defined $params->{exclude_fields}) { - return 0 if $exclude{$field}; + return 0 if $exclude{$field_temp}; } return 1; @@ -136,6 +139,13 @@ 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>. +An optional third option can be passed that prefixes the field name to allow +filtering of data two or more levels deep. + +For example, if you want to filter out the C<id> key/value in components returned +by Product.get, you would use the value C<component.id> in your C<exclude_fields> +list. + =head2 filter_wants Returns C<1> if a filter would preserve the specified field when passing |