From a3ae4ab4b3dacb799e7e370c4785a64e9f4596af Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Mon, 13 Nov 2006 11:04:25 +0000 Subject: Bug 355839: The WebService should provide lists of legal field values Patch By Max Kanat-Alexander r=mbd, a=myk --- Bugzilla/WebService/Bug.pm | 109 +++++++++++++++++++++++++++++++++++++++ Bugzilla/WebService/Constants.pm | 2 + 2 files changed, 111 insertions(+) (limited to 'Bugzilla/WebService') diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm index d61448d7d..0e40c98bb 100755 --- a/Bugzilla/WebService/Bug.pm +++ b/Bugzilla/WebService/Bug.pm @@ -21,6 +21,9 @@ use strict; use base qw(Bugzilla::WebService); import SOAP::Data qw(type); +use Bugzilla::Constants; +use Bugzilla::Error; +use Bugzilla::Field; use Bugzilla::WebService::Constants; use Bugzilla::Util qw(detaint_natural); use Bugzilla::Bug; @@ -42,6 +45,17 @@ use constant FIELD_MAP => { platform => 'rep_platform', }; +use constant GLOBAL_SELECT_FIELDS => qw( + bug_severity + bug_status + op_sys + priority + rep_platform + resolution +); + +use constant PRODUCT_SPECIFIC_FIELDS => qw(version target_milestone component); + ########### # Methods # ########### @@ -83,6 +97,50 @@ sub create { return { id => type('int')->value($bug->bug_id) }; } +sub legal_values { + my ($self, $params) = @_; + my $field = FIELD_MAP->{$params->{field}} || $params->{field}; + + my @custom_select = + Bugzilla->get_fields({ type => FIELD_TYPE_SINGLE_SELECT }); + + my $values; + if (grep($_ eq $field, GLOBAL_SELECT_FIELDS, @custom_select)) { + $values = get_legal_field_values($field); + } + elsif (grep($_ eq $field, PRODUCT_SPECIFIC_FIELDS)) { + my $id = $params->{product_id}; + defined $id || ThrowCodeError('param_required', + { function => 'Bug.legal_values', param => 'product_id' }); + grep($_->id eq $id, @{Bugzilla->user->get_accessible_products}) + || ThrowUserError('product_access_denied', { product => $id }); + + my $product = new Bugzilla::Product($id); + my @objects; + if ($field eq 'version') { + @objects = @{$product->versions}; + } + elsif ($field eq 'target_milestone') { + @objects = @{$product->milestones}; + } + elsif ($field eq 'component') { + @objects = @{$product->components}; + } + + $values = [map { $_->name } @objects]; + } + else { + ThrowCodeError('invalid_field_name', { field => $params->{field} }); + } + + my @result; + foreach my $val (@$values) { + push(@result, type('string')->value($val)); + } + + return { values => \@result }; +} + 1; __END__ @@ -101,6 +159,57 @@ This part of the Bugzilla API allows you to file a new bug in Bugzilla. See L for a description of B, B, and B. +=head2 Utility Functions + +=over + +=item C B + +=over + +=item B + +Tells you what values are allowed for a particular field. + +=item B + +=over + +=item C - The name of the field you want information about. +This should be the same as the name you would use in L, below. + +=item C - If you're picking a product-specific field, you have +to specify the id of the product you want the values for. + +=back + +=item B + +C - An array of strings: the legal values for this field. +The values will be sorted as they normally would be in Bugzilla. + +=item B + +=over + +=item 106 (Invalid Product) + +You were required to specify a product, and either you didn't, or you +specified an invalid product (or a product that you can't access). + +=item 108 (Invalid Field Name) + +You specified a field that doesn't exist or isn't a drop-down field. + +=back + +=back + + +=back + +=head2 Bug Creation and Modification + =over =item C B diff --git a/Bugzilla/WebService/Constants.pm b/Bugzilla/WebService/Constants.pm index e0bb05e5a..d1f816c84 100755 --- a/Bugzilla/WebService/Constants.pm +++ b/Bugzilla/WebService/Constants.pm @@ -52,6 +52,7 @@ use constant WS_ERROR_CODE => { invalid_bug_id_or_alias => 100, invalid_bug_id_non_existent => 101, bug_access_denied => 102, + invalid_field_name => 108, # These all mean "invalid alias" alias_not_defined => 103, alias_too_long => 103, @@ -67,6 +68,7 @@ use constant WS_ERROR_CODE => { # Invalid Product no_products => 106, entry_access_denied => 106, + product_access_denied => 106, product_disabled => 106, # Invalid Summary require_summary => 107, -- cgit v1.2.3-24-g4f1b