TT#51109 Enable api soundgroups and soundhandles for subscriberadmin

Change-Id: Ie9f20f7c6f06ee87860762b57a5ae41f55c00238
changes/03/27003/2
Irina Peshinskaya 7 years ago
parent e4cfc9842a
commit e15e404232

@ -7,7 +7,9 @@ use parent qw/NGCP::Panel::Role::Entities NGCP::Panel::Role::API::SoundGroups/;
use HTTP::Status qw(:constants);
use NGCP::Panel::Utils::Security;
__PACKAGE__->set_config();
__PACKAGE__->set_config({
allowed_roles => [qw/admin reseller subscriberadmin/],
});
sub allowed_methods {
return [qw/GET OPTIONS HEAD/];

@ -5,7 +5,9 @@ use parent qw/NGCP::Panel::Role::EntitiesItem NGCP::Panel::Role::API::SoundGroup
use HTTP::Status qw(:constants);
__PACKAGE__->set_config();
__PACKAGE__->set_config({
allowed_roles => [qw/admin reseller subscriberadmin/],
});
sub allowed_methods{
return [qw/GET OPTIONS HEAD/];

@ -1,14 +1,14 @@
package NGCP::Panel::Controller::API::SoundHandles;
use NGCP::Panel::Utils::Generic qw(:all);
use Sipwise::Base;
use boolean qw(true);
use Data::HAL qw();
use Data::HAL::Link qw();
use HTTP::Headers qw();
use HTTP::Status qw(:constants);
use parent qw/NGCP::Panel::Role::Entities NGCP::Panel::Role::API::SoundHandles/;
__PACKAGE__->set_config({
allowed_roles => [qw/admin reseller subscriberadmin/],
});
sub allowed_methods{
return [qw/GET OPTIONS HEAD/];
@ -35,67 +35,6 @@ sub query_params {
},
];
}
use parent qw/NGCP::Panel::Role::Entities NGCP::Panel::Role::API::SoundHandles/;
sub resource_name{
return 'soundhandles';
}
sub dispatch_path{
return '/api/soundhandles/';
}
sub relation{
return 'http://purl.org/sipwise/ngcp-api/#rel-soundhandles';
}
__PACKAGE__->set_config({
allowed_roles => [qw/admin reseller/],
});
sub GET :Allow {
my ($self, $c) = @_;
my $page = $c->request->params->{page} // 1;
my $rows = $c->request->params->{rows} // 10;
{
my $items = $self->item_rs($c);
(my $total_count, $items, my $items_rows) = $self->paginate_order_collection($c, $items);
my (@embedded, @links);
my $form = $self->get_form($c);
for my $item (@$items_rows) {
push @embedded, $self->hal_from_item($c, $item, $form);
push @links, Data::HAL::Link->new(
relation => 'ngcp:'.$self->resource_name,
href => sprintf('/%s%d', $c->request->path, $item->id),
);
}
push @links,
Data::HAL::Link->new(
relation => 'curies',
href => 'http://purl.org/sipwise/ngcp-api/#rel-{rel}',
name => 'ngcp',
templated => true,
),
Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'),
$self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params);
my $hal = Data::HAL->new(
embedded => [@embedded],
links => [@links],
);
$hal->resource({
total_count => $total_count,
});
my $response = HTTP::Response->new(HTTP_OK, undef,
HTTP::Headers->new($hal->http_headers(skip_links => 1)), $hal->as_json);
$c->response->headers($response->headers);
$c->response->body($response->content);
return;
}
return;
}
1;
# vim: set tabstop=4 expandtab:

@ -6,53 +6,14 @@ use Sipwise::Base;
use HTTP::Headers qw();
use HTTP::Status qw(:constants);
use NGCP::Panel::Utils::ValidateJSON qw();
require Catalyst::ActionRole::ACL;
require NGCP::Panel::Role::HTTPMethods;
require Catalyst::ActionRole::RequireSSL;
sub allowed_methods{
return [qw/GET OPTIONS HEAD/];
}
use parent qw/NGCP::Panel::Role::EntitiesItem NGCP::Panel::Role::API::SoundHandles/;
sub resource_name{
return 'soundhandles';
}
sub dispatch_path{
return '/api/soundhandles/';
}
sub relation{
return 'http://purl.org/sipwise/ngcp-api/#rel-soundhandles';
}
__PACKAGE__->set_config({
allowed_roles => [qw/admin reseller/],
allowed_roles => [qw/admin reseller subscriberadmin/],
});
sub GET :Allow {
my ($self, $c, $id) = @_;
{
last unless $self->valid_id($c, $id);
my $item = $self->item_by_id($c, $id);
last unless $self->resource_exists($c, soundhandle => $item);
my $hal = $self->hal_from_item($c, $item);
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
(map { # XXX Data::HAL must be able to generate links with multiple relations
s|rel="(http://purl.org/sipwise/ngcp-api/#rel-resellers)"|rel="item $1"|r =~
s/rel=self/rel="item self"/r;
} $hal->http_headers),
), $hal->as_json);
$c->response->headers($response->headers);
$c->response->body($response->content);
return;
}
return;
sub allowed_methods{
return [qw/GET OPTIONS HEAD/];
}
1;

@ -1,16 +1,19 @@
package NGCP::Panel::Role::API::SoundHandles;
use NGCP::Panel::Utils::Generic qw(:all);
use Sipwise::Base;
use parent 'NGCP::Panel::Role::API';
use boolean qw(true);
use Data::HAL qw();
use Data::HAL::Link qw();
use HTTP::Status qw(:constants);
sub item_name{
return 'soundhandle';
}
sub resource_name{
return 'soundhandles';
}
sub _item_rs {
my ($self, $c) = @_;
@ -27,44 +30,6 @@ sub get_form {
return NGCP::Panel::Form::get("NGCP::Panel::Form::Sound::HandleAPI", $c);
}
sub item_by_id {
my ($self, $c, $id) = @_;
my $item_rs = $self->item_rs($c);
return $item_rs->find($id);
}
sub hal_from_item {
my ($self, $c, $item, $form) = @_;
my %resource = $item->get_inflated_columns;
my $hal = Data::HAL->new(
links => [
Data::HAL::Link->new(
relation => 'curies',
href => 'http://purl.org/sipwise/ngcp-api/#rel-{rel}',
name => 'ngcp',
templated => true,
),
Data::HAL::Link->new(relation => 'collection', href => sprintf("/api/%s/", $self->resource_name)),
Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'),
Data::HAL::Link->new(relation => 'self', href => sprintf("%s%d", $self->dispatch_path, $item->id)),
],
relation => 'ngcp:'.$self->resource_name,
);
$form //= $self->get_form($c);
$self->validate_form(
c => $c,
resource => \%resource,
form => $form,
run => 0,
);
$resource{id} = int($item->id);
$hal->resource({%resource});
return $hal;
}
1;
# vim: set tabstop=4 expandtab:

Loading…
Cancel
Save