]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 355839: The WebService should provide lists of legal field values
authormkanat%bugzilla.org <>
Mon, 13 Nov 2006 11:04:25 +0000 (11:04 +0000)
committermkanat%bugzilla.org <>
Mon, 13 Nov 2006 11:04:25 +0000 (11:04 +0000)
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=mbd, a=myk

Bugzilla/WebService/Bug.pm
Bugzilla/WebService/Constants.pm
template/en/default/global/user-error.html.tmpl

index d61448d7d88eb537a3bba9deb89c387ea90944b0..0e40c98bbab73955d7fe046719127f3e276c0c37 100755 (executable)
@@ -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>
index e0bb05e5a8dfae49789fb7960b1d85a2e530080d..d1f816c84cf4e7bfd3e5d1f4c61d3cd3ff4712f0 100755 (executable)
@@ -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,
index ef53b2b8e8394e2153549484d0015294e34ee518..83d4a0a161dae24aa6bc8d5da090a96982d9af2d 100644 (file)
     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.