MT#16985 InterceptDB points to pair instead of RO

Change-Id: Ie951b784aaaead64d8af2e376dc8d970a3b1dcd0
changes/85/3885/1
Andreas Granig 10 years ago
parent 6ef3ad1239
commit d6096237ef

@ -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:

@ -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:

@ -1,4 +1,4 @@
package NGCP::Panel::Model::RoDB;
package NGCP::Panel::Model::InterceptDB;
use strict;
use File::ShareDir 'dist_file';

@ -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;

@ -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);

Loading…
Cancel
Save