From a7483ca3510c5491c06e24a26dc00a7b65447c20 Mon Sep 17 00:00:00 2001 From: Gerhard Jungwirth Date: Tue, 15 Apr 2014 12:16:09 +0200 Subject: [PATCH] MT#6497 API: callforwards, better validation --- lib/NGCP/Panel/Form/CFSimpleAPI.pm | 16 ++++++++-------- lib/NGCP/Panel/Role/API/CallForwards.pm | 25 ++++++++++++++++++------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/lib/NGCP/Panel/Form/CFSimpleAPI.pm b/lib/NGCP/Panel/Form/CFSimpleAPI.pm index 28fe247751..ed5633abfc 100644 --- a/lib/NGCP/Panel/Form/CFSimpleAPI.pm +++ b/lib/NGCP/Panel/Form/CFSimpleAPI.pm @@ -17,7 +17,7 @@ has_field 'cfu' => ( type => 'Compound', do_wrapper => 1, do_label => 0, - required => 1, + required => 0, element_attr => { rel => ['tooltip'], title => ['Call Forward Unconditional'] @@ -28,7 +28,7 @@ has_field 'cfb' => ( type => 'Compound', do_wrapper => 1, do_label => 0, - required => 1, + required => 0, element_attr => { rel => ['tooltip'], title => ['Call Forward Busy'] @@ -39,7 +39,7 @@ has_field 'cft' => ( type => 'Compound', do_wrapper => 1, do_label => 0, - required => 1, + required => 0, element_attr => { rel => ['tooltip'], title => ['Call Forward Timeout'] @@ -50,7 +50,7 @@ has_field 'cfna' => ( type => 'Compound', do_wrapper => 1, do_label => 0, - required => 1, + required => 0, element_attr => { rel => ['tooltip'], title => ['Call Forward Unavailable'] @@ -68,7 +68,7 @@ has_field 'cfu.destinations.destination' => ( ); has_field 'cfu.destinations.timeout' => ( - type => 'Text', + type => 'PosInteger', ); has_field 'cfu.times' => ( @@ -88,7 +88,7 @@ has_field 'cfb.destinations.destination' => ( ); has_field 'cfb.destinations.timeout' => ( - type => 'Text', + type => 'PosInteger', ); has_field 'cfb.times' => ( @@ -108,7 +108,7 @@ has_field 'cft.destinations.destination' => ( ); has_field 'cft.destinations.timeout' => ( - type => 'Text', + type => 'PosInteger', ); has_field 'cft.times' => ( @@ -128,7 +128,7 @@ has_field 'cfna.destinations.destination' => ( ); has_field 'cfna.destinations.timeout' => ( - type => 'Text', + type => 'PosInteger', ); has_field 'cfna.times' => ( diff --git a/lib/NGCP/Panel/Role/API/CallForwards.pm b/lib/NGCP/Panel/Role/API/CallForwards.pm index 3a770e0baa..5720cfbc50 100644 --- a/lib/NGCP/Panel/Role/API/CallForwards.pm +++ b/lib/NGCP/Panel/Role/API/CallForwards.pm @@ -115,6 +115,24 @@ sub update_item { die "need provisioning_voip_subscriber" unless $prov_subs; my $prov_subscriber_id = $prov_subs->id; + return unless $self->validate_form( + c => $c, + form => $form, + resource => $resource, + run => 1, + ); + + for my $type (qw/cfu cfb cft cfna/) { + next unless "ARRAY" eq ref $resource->{$type}{destinations}; + for my $d (@{ $resource->{$type}{destinations} }) { + if (exists $d->{timeout} && ! $d->{timeout}->is_integer) { + $c->log->error("Invalid timeout in '$type'"); + $self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid timeout in '$type'"); + return; + } + } + } + for my $type (qw/cfu cfb cft cfna/) { my $mapping = $c->model('DB')->resultset('voip_cf_mappings')->search_rs({ subscriber_id => $prov_subscriber_id, @@ -215,13 +233,6 @@ sub update_item { } } - return unless $self->validate_form( - c => $c, - form => $form, - resource => $resource, - run => 0, - ); - return $item; }