diff --git a/lib/NGCP/Panel/Controller/API/CFDestinationSetsItem.pm b/lib/NGCP/Panel/Controller/API/CFDestinationSetsItem.pm index a6be9f2ead..7b2e2b77b8 100644 --- a/lib/NGCP/Panel/Controller/API/CFDestinationSetsItem.pm +++ b/lib/NGCP/Panel/Controller/API/CFDestinationSetsItem.pm @@ -109,7 +109,7 @@ sub PATCH :Allow { my $dset = $self->item_by_id($c, $id); last unless $self->resource_exists($c, destinationset => $dset); - my $old_resource = $self->hal_from_item($c, $dset, "destinationsets")->resource; + my $old_resource = $self->hal_from_item($c, $dset, "cfdestinationsets")->resource; my $resource = $self->apply_patch($c, $old_resource, $json); last unless $resource; @@ -117,7 +117,7 @@ sub PATCH :Allow { $dset = $self->update_item($c, $dset, $old_resource, $resource, $form); last unless $dset; - my $hal = $self->hal_from_item($c, $dset, "destinationsets"); + my $hal = $self->hal_from_item($c, $dset, "cfdestinationsets"); last unless $self->add_update_journal_item_hal($c,$hal); $guard->commit; @@ -147,7 +147,7 @@ sub PUT :Allow { last unless $preference; my $dset = $self->item_by_id($c, $id); - last unless $self->resource_exists($c, destinationset => $dset); + last unless $self->resource_exists($c, cfdestinationset => $dset); my $resource = $self->get_valid_put_data( c => $c, id => $id, @@ -160,7 +160,7 @@ sub PUT :Allow { $dset = $self->update_item($c, $dset, $old_resource, $resource, $form); last unless $dset; - my $hal = $self->hal_from_item($c, $dset, "destinationsets"); + my $hal = $self->hal_from_item($c, $dset, "cfdestinationsets"); last unless $self->add_update_journal_item_hal($c,$hal); $guard->commit; diff --git a/lib/NGCP/Panel/Controller/API/CFTimeSets.pm b/lib/NGCP/Panel/Controller/API/CFTimeSets.pm index 126ffeb428..aabe700666 100644 --- a/lib/NGCP/Panel/Controller/API/CFTimeSets.pm +++ b/lib/NGCP/Panel/Controller/API/CFTimeSets.pm @@ -208,6 +208,12 @@ sub POST :Allow { $self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to create cftimeset."); last; } + + last unless $self->add_create_journal_item_hal($c,sub { + my $self = shift; + my ($c) = @_; + my $_dset = $self->item_by_id($c, $tset->id); + return $self->hal_from_item($c, $_dset, "cftimesets"); }); $guard->commit; diff --git a/lib/NGCP/Panel/Controller/API/CFTimeSetsItem.pm b/lib/NGCP/Panel/Controller/API/CFTimeSetsItem.pm index fc8443bb17..1b1aa1fc71 100644 --- a/lib/NGCP/Panel/Controller/API/CFTimeSetsItem.pm +++ b/lib/NGCP/Panel/Controller/API/CFTimeSetsItem.pm @@ -108,8 +108,8 @@ sub PATCH :Allow { last unless $json; my $tset = $self->item_by_id($c, $id); - last unless $self->resource_exists($c, timeset => $tset); - my $old_resource = $self->hal_from_item($c, $tset, "timesets")->resource; + last unless $self->resource_exists($c, cftimeset => $tset); + my $old_resource = $self->hal_from_item($c, $tset, "cftimesets")->resource; my $resource = $self->apply_patch($c, $old_resource, $json); last unless $resource; @@ -117,7 +117,7 @@ sub PATCH :Allow { $tset = $self->update_item($c, $tset, $old_resource, $resource, $form); last unless $tset; - my $hal = $self->hal_from_item($c, $tset, "timesets"); + my $hal = $self->hal_from_item($c, $tset, "cftimesets"); last unless $self->add_update_journal_item_hal($c,$hal); $guard->commit; @@ -147,7 +147,7 @@ sub PUT :Allow { last unless $preference; my $tset = $self->item_by_id($c, $id); - last unless $self->resource_exists($c, timeset => $tset); + last unless $self->resource_exists($c, cftimeset => $tset); my $resource = $self->get_valid_put_data( c => $c, id => $id, @@ -160,7 +160,7 @@ sub PUT :Allow { $tset = $self->update_item($c, $tset, $old_resource, $resource, $form); last unless $tset; - my $hal = $self->hal_from_item($c, $tset, "destinationsets"); + my $hal = $self->hal_from_item($c, $tset, "cftimesets"); last unless $self->add_update_journal_item_hal($c,$hal); $guard->commit; diff --git a/lib/NGCP/Panel/Form/CFTimeSetAPI.pm b/lib/NGCP/Panel/Form/CFTimeSetAPI.pm index e18a0b469b..016e5ec663 100644 --- a/lib/NGCP/Panel/Form/CFTimeSetAPI.pm +++ b/lib/NGCP/Panel/Form/CFTimeSetAPI.pm @@ -25,7 +25,7 @@ has_field 'times' => ( do_label => 0, element_attr => { rel => ['tooltip'], - title => ['An array of time definitions with keys "year", "month", "mday", "wday", "hour", "minute", where each key can be a number like "10" or a range like "10-20".'] + title => ['An array of time definitions with keys "year", "month", "mday", "wday", "hour", "minute", where each value can be a number like "10" or a range like "10-20".'] }, ); diff --git a/lib/NGCP/Panel/Role/API/CFTimeSets.pm b/lib/NGCP/Panel/Role/API/CFTimeSets.pm index 3250375e2f..b9a264189e 100644 --- a/lib/NGCP/Panel/Role/API/CFTimeSets.pm +++ b/lib/NGCP/Panel/Role/API/CFTimeSets.pm @@ -128,8 +128,8 @@ sub update_item { $item->create_related("voip_cf_periods", $t); } } catch($e) { - $c->log->error("failed to create cfdestinationset: $e"); - $self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to create cfdestinationset."); + $c->log->error("failed to create cftimeset: $e"); + $self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to create cftimeset."); return; }; diff --git a/ngcp_panel.conf b/ngcp_panel.conf index da2f061ec2..09ec0b6dd6 100644 --- a/ngcp_panel.conf +++ b/ngcp_panel.conf @@ -124,9 +124,9 @@ log4perl.appender.Default.layout.ConversionPattern=%d{ISO8601} [%p] [%F +%L] %m{ - rest_api_keyfile /etc/ngcp-panel/api_ssl/api_ca.key - rest_api_certfile /etc/ngcp-panel/api_ssl/api_ca.crt - server_certfile /etc/ngcp-panel/api_ssl/api_ca.crt + rest_api_keyfile /etc/ngcp-config/ssl/api_ca.key + rest_api_certfile /etc/ngcp-config/ssl/api_ca.crt + server_certfile /etc/ngcp-config/ssl/myserver.crt diff --git a/t/api-journals.t b/t/api-journals.t index 5a1bce71d1..bc6792819f 100644 --- a/t/api-journals.t +++ b/t/api-journals.t @@ -22,8 +22,8 @@ for my $path(qw#/etc/ngcp-panel/ngcp_panel.conf etc/ngcp_panel.conf ngcp_panel.c } } $panel_config //= 'ngcp_panel.conf'; -#my $catalyst_config = Config::General->new("../ngcp_panel.conf"); -my $catalyst_config = Config::General->new($panel_config); +my $catalyst_config = Config::General->new("../ngcp_panel.conf"); +#my $catalyst_config = Config::General->new($panel_config); my %config = $catalyst_config->getall(); my $enable_journal_tests = 1; @@ -38,17 +38,17 @@ my $ssl_ca_cert = $ENV{API_SSL_CA_CERT} || "/etc/ngcp-panel/api_ssl/api_ca.crt"; my ($ua, $req, $res); $ua = LWP::UserAgent->new; -$ua->ssl_opts( - SSL_cert_file => $valid_ssl_client_cert, - SSL_key_file => $valid_ssl_client_key, - SSL_ca_file => $ssl_ca_cert, -); - #$ua->ssl_opts( -# verify_hostname => 0, +# SSL_cert_file => $valid_ssl_client_cert, +# SSL_key_file => $valid_ssl_client_key, +# SSL_ca_file => $ssl_ca_cert, #); -#$ua->credentials("127.0.0.1:4443", "api_admin_http", 'administrator', 'administrator'); -##$ua->timeout(500); #useless, need to change the nginx timeout + +$ua->ssl_opts( + verify_hostname => 0, +); +$ua->credentials("127.0.0.1:4443", "api_admin_http", 'administrator', 'administrator'); +#$ua->timeout(500); #useless, need to change the nginx timeout my $t = time; my $default_reseller_id = 1; @@ -78,6 +78,105 @@ my $subscriberpreferences = test_subscriberpreferences($subscriber,$customersoun done_testing; +sub test_cftimeset { + my ($t,$subscriber) = @_; + + my @destinations = map { { destination => $_, + timeout => '10', + priority => '1', + simple_destination => undef }; } ( + 'voicebox', + 'fax2mail', + 'conference', + 'callingcard', + 'callthrough', + 'localuser', + 'autoattendant', + 'officehours', + 'test_destination@example.com'); + + $req = HTTP::Request->new('POST', $uri.'/api/cfdestinationsets/'); + $req->header('Content-Type' => 'application/json'); + $req->content(JSON::to_json({ + name => "cf_destination_set_".($t-1), + subscriber_id => $subscriber->{id}, + destinations => \@destinations, + })); + $res = $ua->request($req); + is($res->code, 201, "POST test cfdestinationset"); + my $cfdestinationset_uri = $uri.'/'.$res->header('Location'); + $req = HTTP::Request->new('GET', $cfdestinationset_uri); + $res = $ua->request($req); + is($res->code, 200, "fetch POSTed test cfdestinationset"); + my $cfdestinationset = JSON::from_json($res->decoded_content); + + _test_item_journal_link('cfdestinationsets',$cfdestinationset); + _test_journal_options_head('cfdestinationsets',$cfdestinationset->{id}); + my $journals = {}; + my $journal = _test_journal_top_journalitem('cfdestinationsets',$cfdestinationset->{id},$cfdestinationset,'create',$journals); + _test_journal_options_head('cfdestinationsets',$cfdestinationset->{id},$journal->{id}); + + $req = HTTP::Request->new('PUT', $cfdestinationset_uri); + $req->header('Content-Type' => 'application/json'); + $req->header('Prefer' => 'return=representation'); + $req->content(JSON::to_json({ + name => "cf_destination_set_".($t-1).'_put', + subscriber_id => $subscriber->{id}, + destinations => \@destinations, + })); + $res = $ua->request($req); + is($res->code, 200, "PUT test cfdestinationset"); + $req = HTTP::Request->new('GET', $cfdestinationset_uri); + $res = $ua->request($req); + is($res->code, 200, "fetch PUT test cfdestinationset"); + $cfdestinationset = JSON::from_json($res->decoded_content); + + _test_item_journal_link('cfdestinationsets',$cfdestinationset); + $journal = _test_journal_top_journalitem('cfdestinationsets',$cfdestinationset->{id},$cfdestinationset,'update',$journals,$journal); + + $req = HTTP::Request->new('PATCH', $cfdestinationset_uri); + $req->header('Content-Type' => 'application/json-patch+json'); + $req->header('Prefer' => 'return=representation'); + $req->content(JSON::to_json( + [ { op => 'replace', path => '/name', value => "cf_destination_set_".($t-1).'_patch' } ] + )); + $res = $ua->request($req); + is($res->code, 200, "PATCH test cfdestinationset"); + $req = HTTP::Request->new('GET', $cfdestinationset_uri); + $res = $ua->request($req); + is($res->code, 200, "fetch PATCHed test cfdestinationset"); + $cfdestinationset = JSON::from_json($res->decoded_content); + + _test_item_journal_link('cfdestinationsets',$cfdestinationset); + $journal = _test_journal_top_journalitem('cfdestinationsets',$cfdestinationset->{id},$cfdestinationset,'update',$journals,$journal); + + $req = HTTP::Request->new('DELETE', $cfdestinationset_uri); + $res = $ua->request($req); + is($res->code, 204, "delete POSTed test cfdestinationset"); + #$domain = JSON::from_json($res->decoded_content); + + $journal = _test_journal_top_journalitem('cfdestinationsets',$cfdestinationset->{id},$cfdestinationset,'delete',$journals,$journal); + + _test_journal_collection('cfdestinationsets',$cfdestinationset->{id},$journals); + + $req = HTTP::Request->new('POST', $uri.'/api/cfdestinationsets/'); + $req->header('Content-Type' => 'application/json'); + $req->content(JSON::to_json({ + name => "cf_destination_set_".$t, + subscriber_id => $subscriber->{id}, + destinations => \@destinations, + })); + $res = $ua->request($req); + is($res->code, 201, "POST another test cfdestinationset"); + $cfdestinationset_uri = $uri.'/'.$res->header('Location'); + $req = HTTP::Request->new('GET', $cfdestinationset_uri); + $res = $ua->request($req); + is($res->code, 200, "fetch POSTed test cfdestinationset"); + $cfdestinationset = JSON::from_json($res->decoded_content); + + return $cfdestinationset; + +} sub test_cfdestinationset { my ($t,$subscriber) = @_;