From cd2f1c38499004485e3a817e8835b2a0ed9266fd Mon Sep 17 00:00:00 2001 From: Dave Lawrence Date: Mon, 15 Jul 2013 16:29:01 -0400 Subject: Bug 892601 - Port over upstream native REST patch (bug 866927) to bmo/4.2 r=glob --- Bugzilla/WebService/Util.pm | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'Bugzilla/WebService/Util.pm') diff --git a/Bugzilla/WebService/Util.pm b/Bugzilla/WebService/Util.pm index 193dab92d..20ed6170a 100644 --- a/Bugzilla/WebService/Util.pm +++ b/Bugzilla/WebService/Util.pm @@ -32,6 +32,7 @@ our @EXPORT_OK = qw( filter_wants taint_data validate + params_to_objects ); sub filter ($$;$) { @@ -119,6 +120,22 @@ sub validate { return ($self, $params); } +sub params_to_objects { + my ($params, $class) = @_; + my (@objects, @objects_by_ids); + + @objects = map { $class->check($_) } + @{ $params->{names} } if $params->{names}; + + @objects_by_ids = map { $class->check({ id => $_ }) } + @{ $params->{ids} } if $params->{ids}; + + push(@objects, @objects_by_ids); + my %seen; + @objects = grep { !$seen{$_->id}++ } @objects; + return \@objects; +} + __END__ =head1 NAME @@ -165,3 +182,19 @@ This helps in the validation of parameters passed into the WebService methods. Currently it converts listed parameters into an array reference if the client only passed a single scalar value. It modifies the parameters hash in place so other parameters should be unaltered. + +=head2 params_to_objects + +Creates objects of the type passed in as the second parameter, using the +parameters passed to a WebService method (the first parameter to this function). +Helps make life simpler for WebService methods that internally create objects +via both "ids" and "names" fields. Also de-duplicates objects that were loaded +by both "ids" and "names". Returns an arrayref of objects. + +=head1 B + +=over + +=item taint_data + +=back -- cgit v1.2.3-24-g4f1b