From 2fc47431839bbc31fafde0c0e798b95e358f1ee9 Mon Sep 17 00:00:00 2001 From: Gerhard Jungwirth Date: Wed, 23 Apr 2014 13:10:14 +0200 Subject: [PATCH] MT#6497 API use billing subscriber id on all places in cf_*_sets that is: - api/cfdestinationsets - api/cftimesets --- .../Panel/Controller/API/CFDestinationSets.pm | 19 +++++++++++++------ lib/NGCP/Panel/Controller/API/CFTimeSets.pm | 18 ++++++++++++------ lib/NGCP/Panel/Role/API/CFDestinationSets.pm | 14 ++++++++++---- lib/NGCP/Panel/Role/API/CFMappings.pm | 2 +- lib/NGCP/Panel/Role/API/CFTimeSets.pm | 12 +++++++++--- lib/NGCP/Panel/Role/API/CallForwards.pm | 10 +++------- 6 files changed, 48 insertions(+), 27 deletions(-) diff --git a/lib/NGCP/Panel/Controller/API/CFDestinationSets.pm b/lib/NGCP/Panel/Controller/API/CFDestinationSets.pm index 104e11b446..dc4ad37a64 100644 --- a/lib/NGCP/Panel/Controller/API/CFDestinationSets.pm +++ b/lib/NGCP/Panel/Controller/API/CFDestinationSets.pm @@ -32,9 +32,11 @@ class_has 'query_params' => ( query => { first => sub { my $q = shift; - { subscriber_id => $q }; + return { 'voip_subscriber.id' => $q }; + }, + second => sub { + return { join => {subscriber => 'voip_subscriber'}}; }, - second => sub {}, }, }, { @@ -177,13 +179,18 @@ sub POST :Allow { last; } - my $subscriber = $schema->resultset('provisioning_voip_subscribers')->find({ + my $b_subscriber = $schema->resultset('voip_subscribers')->find({ id => $resource->{subscriber_id}, }); - unless($subscriber) { + unless($b_subscriber) { $self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'subscriber_id'."); last; } + my $subscriber = $b_subscriber->provisioning_voip_subscriber; + unless($subscriber) { + $self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid subscriber."); + last; + } if (! exists $resource->{destinations} ) { $resource->{destinations} = []; } @@ -192,7 +199,7 @@ sub POST :Allow { last; } try { - my $primary_nr_rs = $subscriber->voip_subscriber->primary_number; + my $primary_nr_rs = $b_subscriber->primary_number; my $number; if ($primary_nr_rs) { $number = $primary_nr_rs->cc . ($primary_nr_rs->ac //'') . $primary_nr_rs->sn; @@ -203,7 +210,7 @@ sub POST :Allow { $dset = $schema->resultset('voip_cf_destination_sets')->create({ name => $resource->{name}, - subscriber_id => $resource->{subscriber_id}, + subscriber_id => $subscriber->id, }); for my $d ( @{$resource->{destinations}} ) { delete $d->{destination_set_id}; diff --git a/lib/NGCP/Panel/Controller/API/CFTimeSets.pm b/lib/NGCP/Panel/Controller/API/CFTimeSets.pm index e89467d1bc..9bf902d9b3 100644 --- a/lib/NGCP/Panel/Controller/API/CFTimeSets.pm +++ b/lib/NGCP/Panel/Controller/API/CFTimeSets.pm @@ -32,9 +32,11 @@ class_has 'query_params' => ( query => { first => sub { my $q = shift; - { subscriber_id => $q }; + return { 'voip_subscriber.id' => $q }; + }, + second => sub { + return { join => {subscriber => 'voip_subscriber'}}; }, - second => sub {}, }, }, { @@ -176,14 +178,18 @@ sub POST :Allow { $self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Required: 'subscriber_id'"); last; } - - my $subscriber = $schema->resultset('provisioning_voip_subscribers')->find({ + my $b_subscriber = $schema->resultset('voip_subscribers')->find({ id => $resource->{subscriber_id}, }); - unless($subscriber) { + unless($b_subscriber) { $self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'subscriber_id'."); last; } + my $subscriber = $b_subscriber->provisioning_voip_subscriber; + unless($subscriber) { + $self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid subscriber."); + last; + } if (! exists $resource->{times} ) { $resource->{times} = []; } @@ -194,7 +200,7 @@ sub POST :Allow { try { $tset = $schema->resultset('voip_cf_time_sets')->create({ name => $resource->{name}, - subscriber_id => $resource->{subscriber_id}, + subscriber_id => $subscriber->id, }); for my $t ( @{$resource->{times}} ) { delete $t->{time_set_id}; diff --git a/lib/NGCP/Panel/Role/API/CFDestinationSets.pm b/lib/NGCP/Panel/Role/API/CFDestinationSets.pm index 124de31cc0..e3296e6a08 100644 --- a/lib/NGCP/Panel/Role/API/CFDestinationSets.pm +++ b/lib/NGCP/Panel/Role/API/CFDestinationSets.pm @@ -38,6 +38,7 @@ sub hal_from_item { $resource{destinations} = \@destinations; my $b_subs_id = $item->subscriber->voip_subscriber->id; + $resource{subscriber_id} = $b_subs_id; my $hal = Data::HAL->new( links => [ @@ -113,14 +114,19 @@ sub update_item { } } - my $subscriber = $schema->resultset('provisioning_voip_subscribers')->find($resource->{subscriber_id}); - unless ($subscriber) { + my $b_subscriber = $schema->resultset('voip_subscribers')->find($resource->{subscriber_id}); + unless ($b_subscriber) { $self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'subscriber_id'."); return; } + my $subscriber = $b_subscriber->provisioning_voip_subscriber; + unless($subscriber) { + $self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid subscriber."); + last; + } try { - my $primary_nr_rs = $subscriber->voip_subscriber->primary_number; + my $primary_nr_rs = $b_subscriber->primary_number; my $number; if ($primary_nr_rs) { $number = $primary_nr_rs->cc . ($primary_nr_rs->ac //'') . $primary_nr_rs->sn; @@ -131,7 +137,7 @@ sub update_item { $item->update({ name => $resource->{name}, - subscriber_id => $resource->{subscriber_id}, + subscriber_id => $subscriber->id, })->discard_changes; $item->voip_cf_destinations->delete; for my $d ( @{$resource->{destinations}} ) { diff --git a/lib/NGCP/Panel/Role/API/CFMappings.pm b/lib/NGCP/Panel/Role/API/CFMappings.pm index 2b8e5fdea0..91fe4f6f2b 100644 --- a/lib/NGCP/Panel/Role/API/CFMappings.pm +++ b/lib/NGCP/Panel/Role/API/CFMappings.pm @@ -78,7 +78,7 @@ sub item_rs { $item_rs = $c->model('DB')->resultset('voip_subscribers') ->search( { status => { '!=' => 'terminated' } }, - { prefetch => 'provisioning_voip_subscriber',} + { prefetch => 'provisioning_voip_subscriber',}, ); if($c->user->roles eq "reseller") { $item_rs = $item_rs->search({ diff --git a/lib/NGCP/Panel/Role/API/CFTimeSets.pm b/lib/NGCP/Panel/Role/API/CFTimeSets.pm index 8178e7786b..1ee40a557f 100644 --- a/lib/NGCP/Panel/Role/API/CFTimeSets.pm +++ b/lib/NGCP/Panel/Role/API/CFTimeSets.pm @@ -34,6 +34,7 @@ sub hal_from_item { $resource{times} = \@times; my $b_subs_id = $item->subscriber->voip_subscriber->id; + $resource{subscriber_id} = $b_subs_id; my $hal = Data::HAL->new( links => [ @@ -102,16 +103,21 @@ sub update_item { return; } - my $subscriber = $schema->resultset('provisioning_voip_subscribers')->find($resource->{subscriber_id}); - unless ($subscriber) { + my $b_subscriber = $schema->resultset('voip_subscribers')->find($resource->{subscriber_id}); + unless ($b_subscriber) { $self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'subscriber_id'."); return; } + my $subscriber = $b_subscriber->provisioning_voip_subscriber; + unless($subscriber) { + $self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid subscriber."); + last; + } try { $item->update({ name => $resource->{name}, - subscriber_id => $resource->{subscriber_id}, + subscriber_id => $subscriber->id, })->discard_changes; $item->voip_cf_periods->delete; for my $t ( @{$resource->{times}} ) { diff --git a/lib/NGCP/Panel/Role/API/CallForwards.pm b/lib/NGCP/Panel/Role/API/CallForwards.pm index a026d0b3b4..9a7d0fa5aa 100644 --- a/lib/NGCP/Panel/Role/API/CallForwards.pm +++ b/lib/NGCP/Panel/Role/API/CallForwards.pm @@ -86,7 +86,7 @@ sub item_rs { $item_rs = $c->model('DB')->resultset('voip_subscribers') ->search( { status => { '!=' => 'terminated' } }, - { prefetch => 'provisioning_voip_subscriber',} + { prefetch => 'provisioning_voip_subscriber',}, ); if($c->user->roles eq "reseller") { $item_rs = $item_rs->search({ @@ -197,15 +197,11 @@ sub update_item { domain => $domain, uri => $d->{destination}, ); - $dset->voip_cf_destinations->update_or_create({ - %$d - }); + $dset->voip_cf_destinations->update_or_create($d); } for my $t (@{ $resource->{$type}{times} }) { delete $t->{time_set_id}; - $tset->voip_cf_periods->update_or_create({ - %$t - }); + $tset->voip_cf_periods->update_or_create($t); } unless ( $dset && $dset->voip_cf_destinations->count ) { $mapping->delete;