diff --git a/lib/NGCP/Panel/Form/DestinationSet.pm b/lib/NGCP/Panel/Form/DestinationSet.pm index 9adbed2e21..4079100552 100644 --- a/lib/NGCP/Panel/Form/DestinationSet.pm +++ b/lib/NGCP/Panel/Form/DestinationSet.pm @@ -62,10 +62,12 @@ sub build_destinations { if($c->config->{features}->{callingcard}); push @options, { label => 'Call Through', value => 'callthrough' } if($c->config->{features}->{callthrough}); - push @options, { label => 'Auto Attendant', value => 'autoattendant' } - if($c->config->{features}->{cloudpbx} && $c->stash->{pbx}); - push @options, { label => 'Office Hours Announcement', value => 'officehours' } - if($c->config->{features}->{cloudpbx} && $c->stash->{pbx}); + if($c->config->{features}->{cloudpbx} && $c->stash->{pbx}){ + push @options, + { label => 'Auto Attendant', value => 'autoattendant' }, + { label => 'Office Hours Announcement', value => 'officehours' }, + { label => 'Custom Hours Announcement', value => 'customhours' }; + } push @options, { label => 'Local Subscriber', value => 'localuser' } if($c->config->{features}->{callthrough} || $c->config->{features}->{callingcard} ); } diff --git a/lib/NGCP/Panel/Form/SubscriberCFSimple.pm b/lib/NGCP/Panel/Form/SubscriberCFSimple.pm index 4667e01a90..40fd1f0400 100644 --- a/lib/NGCP/Panel/Form/SubscriberCFSimple.pm +++ b/lib/NGCP/Panel/Form/SubscriberCFSimple.pm @@ -47,10 +47,12 @@ sub build_destinations { if($c->config->{features}->{callingcard}); push @options, { label => 'Call Through', value => 'callthrough' } if($c->config->{features}->{callthrough}); - push @options, { label => 'Auto Attendant', value => 'autoattendant' } - if($c->config->{features}->{cloudpbx} && $c->stash->{pbx}); - push @options, { label => 'Office Hours Announcement', value => 'officehours' } - if($c->config->{features}->{cloudpbx} && $c->stash->{pbx}); + if($c->config->{features}->{cloudpbx} && $c->stash->{pbx}){ + push @options, + { label => 'Auto Attendant', value => 'autoattendant' }, + { label => 'Office Hours Announcement', value => 'officehours' }, + { label => 'Custom Hours Announcement', value => 'customhours' }; + } push @options, { label => 'Local Subscriber', value => 'localuser' } if($c->config->{features}->{callthrough} || $c->config->{features}->{callingcard} ); } diff --git a/lib/NGCP/Panel/Utils/Subscriber.pm b/lib/NGCP/Panel/Utils/Subscriber.pm index adad59dae2..ab27f8d7c4 100644 --- a/lib/NGCP/Panel/Utils/Subscriber.pm +++ b/lib/NGCP/Panel/Utils/Subscriber.pm @@ -81,6 +81,8 @@ sub destination_as_string { return "Auto Attendant"; } elsif($dest =~ /^sip:office-hours\@app\.local$/) { return "Office Hours Announcement"; + } elsif($dest =~ /^sip:custom-hours\@app\.local$/) { + return "Custom Hours Announcement"; } else { my $d = $dest; $d =~ s/^sips?://; @@ -1121,6 +1123,8 @@ sub field_to_destination { $d = "sip:auto-attendant\@app.local"; } elsif($d eq "officehours") { $d = "sip:office-hours\@app.local"; + } elsif($d eq "customhours") { + $d = "sip:custom-hours\@app.local"; } else { my $v = $uri; $v =~ s/^sips?://; @@ -1152,6 +1156,8 @@ sub destination_to_field { $d = 'autoattendant'; } elsif($d =~ /^sip:office-hours\@app\.local$/) { $d = 'officehours'; + } elsif($d =~ /^sip:custom-hours\@app\.local$/) { + $d = 'customhours'; } else { $duri = $d; $d = 'uri'; diff --git a/t/api-rest/api-callforwards.t b/t/api-rest/api-callforwards.t index 895f7359af..d36959a03b 100644 --- a/t/api-rest/api-callforwards.t +++ b/t/api-rest/api-callforwards.t @@ -5,7 +5,7 @@ use Test::More; use Test::Collection; use Test::FakeData; use Data::Dumper; - +use Clone qw/clone/; my $fake_data = Test::FakeData->new; $fake_data->set_data_from_script({ @@ -25,7 +25,36 @@ $fake_data->set_data_from_script({ { destination => "voicebox", timeout => 500 }, ], ringtimeout => 10, - } + }, + cfb => { + destinations => [ + { + destination => "customhours", + priority => "1", + timeout => "300" + }, + { + destination => "officehours", + priority => "2", + timeout => "300" + }, + ], + sources => [ + { + source => "123-13-13" + } + ], + 'times' => [ + { + hour => "18-8", + mday => undef, + minute => "0-0", + month => undef, + wday => "6-2", + year => undef + } + ] + }, }, }, }); @@ -43,13 +72,12 @@ SKIP:{ my ($res,$req,$content); my $cf1 = $test_machine->get_item_hal(); - if(!$cf1->{content}->{total_count}){ + if(!$cf1->{total_count} && !$cf1->{content_collection}->{total_count}){ skip("Testing requires at least one present callforward. No creation is available.",1); } $test_machine->check_bundle(); - - my($cf1_id) = $test_machine->get_id_from_hal($cf1->{content}); #($cf1,'callforwards'); + my($cf1_id) = $test_machine->get_id_from_hal($cf1->{content_collection}); #($cf1,'callforwards'); cmp_ok ($cf1_id, '>', 0, "should be positive integer"); my $cf1single_uri = "/api/callforwards/$cf1_id"; my $cf1single; @@ -69,6 +97,8 @@ SKIP:{ is ($cf1_put->{content}->{cft}{destinations}->[0]->{simple_destination}, "5678", "Check first destination of cft"); like ($cf1_put->{content}->{cft}{destinations}->[0]->{destination}, qr/^sip:5678@/, "Check first destination of cft (regex, full uri)"); is ($cf1_put->{content}->{cft}{destinations}->[1]->{destination}, "voicebox", "Check second destination of cft"); + is ($cf1_put->{content}->{cfb}{destinations}->[0]->{destination}, "customhours", "Check customhours destination"); + is ($cf1_put->{content}->{cfb}{destinations}->[1]->{destination}, "officehours", "Check customhours destination"); #write invalid 'timeout' ($res,$content,$req) = $test_machine->request_put({ @@ -89,7 +119,7 @@ SKIP:{ is($content->{code}, "400", "check error code in body"); like($content->{message}, qr/Invalid id/, "check error message in body"); - my($cf2_put,$cf2_get) = $test_machine->check_put2get({data_in => $cf1_put->{content}, uri => $cf1single_uri},undef, 1 ); + my($cf2_put,$cf2_get) = $test_machine->check_put2get({data_in => clone($cf1_put->{content}), uri => $cf1single_uri},undef, 1 ); is_deeply($cf1_put->{content}, $cf2_put->{content}, "check put if unmodified put returns the same"); $test_machine->check_embedded($cf2_put->{content}); diff --git a/t/api-rest/api-cfdestinationsets.t b/t/api-rest/api-cfdestinationsets.t index 8b533b9a7b..0816f9f29f 100644 --- a/t/api-rest/api-cfdestinationsets.t +++ b/t/api-rest/api-cfdestinationsets.t @@ -3,10 +3,39 @@ use warnings; use Test::More; use Test::Collection; +use Test::FakeData; my $test_machine = Test::Collection->new( name => 'cfdestinationsets', ); +my $fake_data = Test::FakeData->new; + +$test_machine->methods->{collection}->{allowed} = {map {$_ => 1} qw(GET HEAD OPTIONS POST)}; +$test_machine->methods->{item}->{allowed} = {map {$_ => 1} qw(GET HEAD OPTIONS PUT PATCH DELETE)}; + +$fake_data->set_data_from_script({ + 'cfdestinationsets' => { + data => { + destinations => [ + { + destination => "sip:custom-hours\@app.local", + priority => 1, + timeout => 300, + } + ], + name => "Weekend days", + subscriber_id => sub { return shift->get_id('subscribers',@_); }, + }, + }, +}); + +$test_machine->DATA_ITEM_STORE($fake_data->process('cfdestinationsets')); +$test_machine->form_data_item( ); + +# create 3 new billing zones from DATA_ITEM +$test_machine->check_create_correct( 3, sub{ $_[0]->{name} .= $_[1]->{i} ; } ); +$test_machine->check_get2put(); +$test_machine->check_bundle(); diag('Note that the next tests require at least one subscriber to be present ' . 'and accessible to the current API user.'); @@ -66,6 +95,7 @@ SKIP: is($res->code, 404, "check get nonexistent cftimesets item"); } +$test_machine->clear_test_data_all(); done_testing; # vim: set tabstop=4 expandtab: