diff options
author | mkanat%bugzilla.org <> | 2006-11-13 12:04:25 +0100 |
---|---|---|
committer | mkanat%bugzilla.org <> | 2006-11-13 12:04:25 +0100 |
commit | a3ae4ab4b3dacb799e7e370c4785a64e9f4596af (patch) | |
tree | 911bea15f15bcb527f77958590091b6dd24c90d4 | |
parent | 790e8bbba2ae44ebc7473c61b3e9f7aafa8e2d5e (diff) | |
download | bugzilla-a3ae4ab4b3dacb799e7e370c4785a64e9f4596af.tar.gz bugzilla-a3ae4ab4b3dacb799e7e370c4785a64e9f4596af.tar.xz |
Bug 355839: The WebService should provide lists of legal field values
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=mbd, a=myk
-rwxr-xr-x | Bugzilla/WebService/Bug.pm | 109 | ||||
-rwxr-xr-x | Bugzilla/WebService/Constants.pm | 2 | ||||
-rw-r--r-- | template/en/default/global/user-error.html.tmpl | 4 |
3 files changed, 115 insertions, 0 deletions
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<Bugzilla::WebService> for a description of B<STABLE>, B<UNSTABLE>, and B<EXPERIMENTAL>. +=head2 Utility Functions + +=over + +=item C<legal_values> B<EXPERIMENTAL> + +=over + +=item B<Description> + +Tells you what values are allowed for a particular field. + +=item B<Params> + +=over + +=item C<field> - The name of the field you want information about. +This should be the same as the name you would use in L</create>, below. + +=item C<product_id> - 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<Returns> + +C<values> - An array of strings: the legal values for this field. +The values will be sorted as they normally would be in Bugzilla. + +=item B<Errors> + +=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<create> B<EXPERIMENTAL> 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, diff --git a/template/en/default/global/user-error.html.tmpl b/template/en/default/global/user-error.html.tmpl index ef53b2b8e..83d4a0a16 100644 --- a/template/en/default/global/user-error.html.tmpl +++ b/template/en/default/global/user-error.html.tmpl @@ -1138,6 +1138,10 @@ Patches cannot be more than [% Param('maxpatchsize') %] KB in size. Try breaking your patch into several pieces. + [% ELSIF error == "product_access_denied" %] + Either the product '[% product FILTER html %]' does not exist or + you don't have access to it. + [% ELSIF error == "product_doesnt_exist" %] [% title = "Specified Product Does Not Exist" %] The product '[% product FILTER html %]' does not exist. |