diff options
Diffstat (limited to 'extensions/ComponentWatching/lib')
-rw-r--r-- | extensions/ComponentWatching/lib/WebService.pm | 128 |
1 files changed, 65 insertions, 63 deletions
diff --git a/extensions/ComponentWatching/lib/WebService.pm b/extensions/ComponentWatching/lib/WebService.pm index ba4cb0225..331842f7b 100644 --- a/extensions/ComponentWatching/lib/WebService.pm +++ b/extensions/ComponentWatching/lib/WebService.pm @@ -21,30 +21,25 @@ use Bugzilla::Product; use Bugzilla::User; sub rest_resources { - return [ - qr{^/component-watching$}, { - GET => { - method => 'list', - }, - POST => { - method => 'add', - }, + return [ + qr{^/component-watching$}, + {GET => {method => 'list',}, POST => {method => 'add',},}, + qr{^/component-watching/(\d+)$}, + { + GET => { + method => 'get', + params => sub { + return {id => $_[0]}; }, - qr{^/component-watching/(\d+)$}, { - GET => { - method => 'get', - params => sub { - return { id => $_[0] } - }, - }, - DELETE => { - method => 'remove', - params => sub { - return { id => $_[0] } - }, - }, + }, + DELETE => { + method => 'remove', + params => sub { + return {id => $_[0]}; }, - ]; + }, + }, + ]; } # @@ -52,62 +47,69 @@ sub rest_resources { # sub list { - my ($self, $params) = @_; - my $user = Bugzilla->login(LOGIN_REQUIRED); + my ($self, $params) = @_; + my $user = Bugzilla->login(LOGIN_REQUIRED); - return Bugzilla::Extension::ComponentWatching::_getWatches($user); + return Bugzilla::Extension::ComponentWatching::_getWatches($user); } sub add { - my ($self, $params) = @_; - my $user = Bugzilla->login(LOGIN_REQUIRED); - my $result; - - # load product and verify access - my $productName = $params->{'product'}; - my $product = Bugzilla::Product->new({ name => $productName, cache => 1 }); - unless ($product && $user->can_access_product($product)) { - ThrowUserError('product_access_denied', { product => $productName }); + my ($self, $params) = @_; + my $user = Bugzilla->login(LOGIN_REQUIRED); + my $result; + + # load product and verify access + my $productName = $params->{'product'}; + my $product = Bugzilla::Product->new({name => $productName, cache => 1}); + unless ($product && $user->can_access_product($product)) { + ThrowUserError('product_access_denied', {product => $productName}); + } + + my $ra_componentNames = $params->{'component'}; + $ra_componentNames = [$ra_componentNames || ''] unless ref($ra_componentNames); + + if (grep { $_ eq '' } @$ra_componentNames) { + + # watching a product + $result + = Bugzilla::Extension::ComponentWatching::_addProductWatch($user, $product); + + } + else { + # watching specific components + foreach my $componentName (@$ra_componentNames) { + my $component + = Bugzilla::Component->new({ + name => $componentName, product => $product, cache => 1 + }); + unless ($component) { + ThrowUserError('product_access_denied', {product => $productName}); + } + $result = Bugzilla::Extension::ComponentWatching::_addComponentWatch($user, + $component); } + } - my $ra_componentNames = $params->{'component'}; - $ra_componentNames = [$ra_componentNames || ''] unless ref($ra_componentNames); - - if (grep { $_ eq '' } @$ra_componentNames) { - # watching a product - $result = Bugzilla::Extension::ComponentWatching::_addProductWatch($user, $product); - - } else { - # watching specific components - foreach my $componentName (@$ra_componentNames) { - my $component = Bugzilla::Component->new({ - name => $componentName, product => $product, cache => 1 - }); - unless ($component) { - ThrowUserError('product_access_denied', { product => $productName }); - } - $result = Bugzilla::Extension::ComponentWatching::_addComponentWatch($user, $component); - } - } - - Bugzilla::Extension::ComponentWatching::_addDefaultSettings($user); + Bugzilla::Extension::ComponentWatching::_addDefaultSettings($user); - return $result; + return $result; } sub get { - my ($self, $params) = @_; - my $user = Bugzilla->login(LOGIN_REQUIRED); + my ($self, $params) = @_; + my $user = Bugzilla->login(LOGIN_REQUIRED); - return Bugzilla::Extension::ComponentWatching::_getWatches($user, $params->{'id'}); + return Bugzilla::Extension::ComponentWatching::_getWatches($user, + $params->{'id'}); } sub remove { - my ($self, $params) = @_; - my $user = Bugzilla->login(LOGIN_REQUIRED); - my %result = (status => Bugzilla::Extension::ComponentWatching::_deleteWatch($user, $params->{'id'})); + my ($self, $params) = @_; + my $user = Bugzilla->login(LOGIN_REQUIRED); + my %result = (status => + Bugzilla::Extension::ComponentWatching::_deleteWatch($user, $params->{'id'})); - return \%result; + return \%result; } 1; |