From 9e71dcae1e1bf233f655ced691f5798cbe430f68 Mon Sep 17 00:00:00 2001 From: Sebastin Santy Date: Thu, 15 Jun 2017 22:37:02 +0530 Subject: Bug 1373000 - New BugModal API for product data and component+product-specific data --- extensions/BugModal/lib/WebService.pm | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'extensions/BugModal/lib/WebService.pm') diff --git a/extensions/BugModal/lib/WebService.pm b/extensions/BugModal/lib/WebService.pm index 338129e9b..33fec6bab 100644 --- a/extensions/BugModal/lib/WebService.pm +++ b/extensions/BugModal/lib/WebService.pm @@ -22,11 +22,31 @@ use Bugzilla::Milestone; use Bugzilla::Product; use Bugzilla::Version; use List::MoreUtils qw(any first_value); +use Taint::Util qw(untaint); # these methods are much lighter than our public API calls sub rest_resources { return [ + # return all the products accessible by the user. + # required by new-bug + qr{^/bug_modal/products}, { + GET => { + method => 'products' + }, + }, + + # return all the components pertaining to the product. + # required by new-bug + qr{^/bug_modal/components}, { + GET => { + method => 'components', + params => sub { + return { product_name => Bugzilla->input_params->{product} } + }, + }, + }, + # return all the lazy-loaded data; kept in sync with the UI's # requirements. qr{^/bug_modal/edit/(\d+)$}, { @@ -62,6 +82,24 @@ sub rest_resources { ] } +sub products { + my $user = Bugzilla->user; + return { products => _name($user->get_enterable_products) } +} + +sub components { + my ($self, $params) = @_; + if (!ref $params->{product_name}) { + untaint($params->{product_name}); + } + else { + ThrowCodeError('params_required',{ function => 'BugModal.components', params => ['product'] }); + } + my $product = Bugzilla::Product->check({ name => $params->{product_name}, cache => 1 }); + $product = Bugzilla->user->can_enter_product($product, 1); + return { components => _name($product->components) } +} + # everything we need for edit mode in a single call, returning just the fields # that the ui requires. sub edit { -- cgit v1.2.3-24-g4f1b