diff --git a/lib/NGCP/Panel/Controller/API/Interceptions.pm b/lib/NGCP/Panel/Controller/API/Interceptions.pm index e6f8d05da7..b308463927 100644 --- a/lib/NGCP/Panel/Controller/API/Interceptions.pm +++ b/lib/NGCP/Panel/Controller/API/Interceptions.pm @@ -1,8 +1,6 @@ package NGCP::Panel::Controller::API::Interceptions; -use NGCP::Panel::Utils::Generic qw(:all); use Sipwise::Base; -use Moose; -#use namespace::sweep; +use namespace::sweep; use boolean qw(true); use Data::HAL qw(); use Data::HAL::Link qw(); @@ -148,7 +146,7 @@ sub OPTIONS :Allow { my ($self, $c) = @_; my $allowed_methods = $self->allowed_methods_filtered($c); $c->response->headers(HTTP::Headers->new( - Allow => join(', ', @{ $allowed_methods }), + Allow => $allowed_methods->join(', '), Accept_Post => 'application/hal+json; profile=http://purl.org/sipwise/ngcp-api/#rel-'.$self->resource_name, )); $c->response->content_type('application/json'); @@ -159,8 +157,8 @@ sub OPTIONS :Allow { sub POST :Allow { my ($self, $c) = @_; - my $guard = $c->model('DB')->txn_scope_guard; - my $cguard = $c->model('RoDB')->txn_scope_guard; + my $guard = $c->model('InterceptDB')->txn_scope_guard; + my $cguard = $c->model('DB')->txn_scope_guard; { my $resource = $self->get_valid_post_data( c => $c, @@ -175,7 +173,7 @@ sub POST :Allow { form => $form, ); - my $num_rs = $c->model('RoDB')->resultset('voip_numbers')->search( + my $num_rs = $c->model('DB')->resultset('voip_numbers')->search( \[ 'concat(cc,ac,sn) = ?', [ {} => $resource->{number} ]] ); unless($num_rs->first) { @@ -183,7 +181,9 @@ sub POST :Allow { $self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Number does not exist"); last; } - $resource->{reseller_id} = $num_rs->first->reseller_id; + # use the long way, since with ossbss provisioning, the reseller_id + # is not set in this case + $resource->{reseller_id} = $num_rs->first->subscriber->contract->contact->reseller_id; my $sub = $num_rs->first->subscriber; unless($sub) { @@ -211,8 +211,10 @@ sub POST :Allow { my $item; my $dbresource = { %{ $resource } }; $dbresource = $self->resnames_to_dbnames($dbresource); + $dbresource->{reseller_id} = $resource->{reseller_id}; + try { - $item = $c->model('DB')->resultset('voip_intercept')->create($dbresource); + $item = $c->model('InterceptDB')->resultset('voip_intercept')->create($dbresource); my $res = NGCP::Panel::Utils::Interception::request($c, 'POST', undef, { liid => $resource->{liid}, uuid => $resource->{uuid}, @@ -250,7 +252,4 @@ sub end : Private { $self->log_response($c); } -no Moose; -1; - # vim: set tabstop=4 expandtab: diff --git a/lib/NGCP/Panel/Controller/API/InterceptionsItem.pm b/lib/NGCP/Panel/Controller/API/InterceptionsItem.pm index 88d5f7ed1a..6cc29ab51e 100644 --- a/lib/NGCP/Panel/Controller/API/InterceptionsItem.pm +++ b/lib/NGCP/Panel/Controller/API/InterceptionsItem.pm @@ -1,8 +1,6 @@ package NGCP::Panel::Controller::API::InterceptionsItem; -use NGCP::Panel::Utils::Generic qw(:all); use Sipwise::Base; -use Moose; -#use namespace::sweep; +use namespace::sweep; use HTTP::Headers qw(); use HTTP::Status qw(:constants); use MooseX::ClassAttribute qw(class_has); @@ -77,7 +75,7 @@ sub OPTIONS :Allow { my ($self, $c, $id) = @_; my $allowed_methods = $self->allowed_methods_filtered($c); $c->response->headers(HTTP::Headers->new( - Allow => join(', ', @{ $allowed_methods }), + Allow => $allowed_methods->join(', '), Accept_Patch => 'application/json-patch+json', )); $c->response->content_type('application/json'); @@ -87,8 +85,8 @@ sub OPTIONS :Allow { sub PATCH :Allow { my ($self, $c, $id) = @_; - my $cguard = $c->model('RoDB')->txn_scope_guard; - my $guard = $c->model('DB')->txn_scope_guard; + my $cguard = $c->model('DB')->txn_scope_guard; + my $guard = $c->model('InterceptDB')->txn_scope_guard; { my $preference = $self->require_preference($c); last unless $preference; @@ -152,8 +150,8 @@ sub PATCH :Allow { sub PUT :Allow { my ($self, $c, $id) = @_; - my $cguard = $c->model('RoDB')->txn_scope_guard; - my $guard = $c->model('DB')->txn_scope_guard; + my $cguard = $c->model('DB')->txn_scope_guard; + my $guard = $c->model('InterceptDB')->txn_scope_guard; { my $preference = $self->require_preference($c); last unless $preference; @@ -215,7 +213,7 @@ sub DELETE :Allow { my ($self, $c, $id) = @_; my $cguard = $c->model('DB')->txn_scope_guard; - my $guard = $c->model('DB')->txn_scope_guard; + my $guard = $c->model('InterceptDB')->txn_scope_guard; { my $item = $self->item_by_id($c, $id); my $uuid = $item->uuid; @@ -258,7 +256,4 @@ sub end : Private { $self->log_response($c); } -no Moose; -1; - # vim: set tabstop=4 expandtab: diff --git a/lib/NGCP/Panel/Model/RoDB.pm b/lib/NGCP/Panel/Model/InterceptDB.pm similarity index 94% rename from lib/NGCP/Panel/Model/RoDB.pm rename to lib/NGCP/Panel/Model/InterceptDB.pm index 97f9c7cd98..c89af92492 100644 --- a/lib/NGCP/Panel/Model/RoDB.pm +++ b/lib/NGCP/Panel/Model/InterceptDB.pm @@ -1,4 +1,4 @@ -package NGCP::Panel::Model::RoDB; +package NGCP::Panel::Model::InterceptDB; use strict; use File::ShareDir 'dist_file'; diff --git a/lib/NGCP/Panel/Model/RoDB/Base.pm b/lib/NGCP/Panel/Model/InterceptDB/Base.pm similarity index 91% rename from lib/NGCP/Panel/Model/RoDB/Base.pm rename to lib/NGCP/Panel/Model/InterceptDB/Base.pm index 2268b11a19..138f357227 100644 --- a/lib/NGCP/Panel/Model/RoDB/Base.pm +++ b/lib/NGCP/Panel/Model/InterceptDB/Base.pm @@ -1,7 +1,7 @@ -package NGCP::Panel::Model::RoDB::Base; +package NGCP::Panel::Model::InterceptDB::Base; #use base 'Catalyst::Model::Adaptor'; use base 'Catalyst::Model'; -use NGCP::Panel::Model::RoDB; +use NGCP::Panel::Model::InterceptDB; use Moose; @@ -69,6 +69,6 @@ __PACKAGE__->config( has 'schema' => ( is => 'rw', - isa => 'NGCP::Panel::Model::RoDB', + isa => 'NGCP::Panel::Model::InterceptDB', ); 1; diff --git a/lib/NGCP/Panel/Role/API/Interceptions.pm b/lib/NGCP/Panel/Role/API/Interceptions.pm index 452ac1a993..a6119d8cfb 100644 --- a/lib/NGCP/Panel/Role/API/Interceptions.pm +++ b/lib/NGCP/Panel/Role/API/Interceptions.pm @@ -1,5 +1,4 @@ package NGCP::Panel::Role::API::Interceptions; -use NGCP::Panel::Utils::Generic qw(:all); use Moose::Role; use Sipwise::Base; with 'NGCP::Panel::Role::API' => { @@ -17,7 +16,7 @@ use NGCP::Panel::Form::InterceptionAPI; sub item_rs { my ($self, $c) = @_; - my $item_rs = $c->model('DB')->resultset('voip_intercept')->search({ + my $item_rs = $c->model('InterceptDB')->resultset('voip_intercept')->search({ deleted => 0, }); return $item_rs; @@ -153,7 +152,7 @@ sub update_item { sub subres_from_number { my ($self, $c, $number) = @_; - my $num_rs = $c->model('RoDB')->resultset('voip_numbers')->search( + my $num_rs = $c->model('DB')->resultset('voip_numbers')->search( \[ 'concat(cc,ac,sn) = ?', [ {} => $number ]] ); unless($num_rs->first) { @@ -170,9 +169,14 @@ sub subres_from_number { my $res = $num_rs->first->reseller; unless($res) { - $c->log->error("invalid number '$number', not assigned to any reseller"); - $self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Number is not active"); - return; + # with ossbss provisioning, reseller is not set on number, + # so take the long way here + $res = $sub->contract->contact->reseller; + unless($res) { + $c->log->error("invalid number '$number', not assigned to any reseller"); + $self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Number is not active"); + return; + } } return ($sub, $res);