use Bugzilla::Error;
use Bugzilla::Field;
use Bugzilla::WebService::Constants;
-use Bugzilla::WebService::Util qw(filter);
+use Bugzilla::WebService::Util qw(filter validate);
use Bugzilla::Bug;
use Bugzilla::BugMail;
use Bugzilla::Util qw(trim);
###########
sub comments {
- my ($self, $params) = @_;
+ my ($self, $params) = validate(@_, 'bug_ids', 'comment_ids');
+
if (!(defined $params->{bug_ids} || defined $params->{comment_ids})) {
ThrowCodeError('params_required',
{ function => 'Bug.comments',
}
sub get {
- my ($self, $params) = @_;
+ my ($self, $params) = validate(@_, 'ids');
+
my $ids = $params->{ids};
defined $ids || ThrowCodeError('param_required', { param => 'ids' });
# it can be called as the following:
# $call = $rpc->call( 'Bug.get_history', { ids => [1,2] });
sub get_history {
- my ($self, $params) = @_;
+ my ($self, $params) = validate(@_, 'ids');
my $ids = $params->{ids};
defined $ids || ThrowCodeError('param_required', { param => 'ids' });
use base qw(Bugzilla::WebService);
use Bugzilla::Product;
use Bugzilla::User;
+use Bugzilla::WebService::Util qw(validate);
##################################################
# Add aliases here for method name compatibility #
# Get a list of actual products, based on list of ids
sub get {
- my ($self, $params) = @_;
+ my ($self, $params) = validate(@_, 'ids');
# Only products that are in the users accessible products,
# can be allowed to be returned
use Bugzilla::User;
use Bugzilla::Util qw(trim);
use Bugzilla::Token;
-use Bugzilla::WebService::Util qw(filter);
+use Bugzilla::WebService::Util qw(filter validate);
# Don't need auth to login
use constant LOGIN_EXEMPT => {
# $call = $rpc->call( 'User.get', { ids => [1,2,3],
# names => ['testusera@redhat.com', 'testuserb@redhat.com'] });
sub get {
- my ($self, $params) = @_;
+ my ($self, $params) = validate(@_, 'names', 'ids');
my @user_objects;
@user_objects = map { Bugzilla::User->check($_) } @{ $params->{names} }
use base qw(Exporter);
-our @EXPORT_OK = qw(filter);
+our @EXPORT_OK = qw(filter validate);
sub filter ($$) {
my ($params, $hash) = @_;
return \%newhash;
}
+sub validate {
+ my ($self, $params, @keys) = @_;
+
+ # If @keys is not empty then we convert any named
+ # parameters that have scalar values to arrayrefs
+ # that match.
+ foreach my $key (@keys) {
+ if (exists $params->{$key}) {
+ $params->{$key} = ref $params->{$key}
+ ? $params->{$key}
+ : [ $params->{$key} ];
+ }
+ }
+
+ return ($self, $params);
+}
+
__END__
=head1 NAME
filter({ include_fields => ['id', 'name'],
exclude_fields => ['name'] }, $hash);
+ validate(@_, 'ids');
+
=head1 METHODS
=over
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<validate>
+
+This helps in the validation of parameters passed into the WebSerice
+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.
+
=back