From bddadea51bd9cd2bbf921c5c84bca185b6c5db9b Mon Sep 17 00:00:00 2001 From: Irina Peshinskaya Date: Tue, 28 Oct 2014 13:45:17 +0200 Subject: [PATCH] MT#9177 Untested Device forms. --- lib/NGCP/Panel/Controller/Device.pm | 136 ++++++++++----------- lib/NGCP/Panel/Form/CFDestinationSetAPI.pm | 2 +- lib/NGCP/Panel/Form/Device/Model.pm | 102 ++++++++++------ lib/NGCP/Panel/Form/Device/ModelAdmin.pm | 2 +- lib/NGCP/Panel/Utils/DeviceBootstrap.pm | 3 +- share/templates/device/list.tt | 38 +++++- 6 files changed, 167 insertions(+), 116 deletions(-) diff --git a/lib/NGCP/Panel/Controller/Device.pm b/lib/NGCP/Panel/Controller/Device.pm index 88b84a6a8a..fe49b00314 100644 --- a/lib/NGCP/Panel/Controller/Device.pm +++ b/lib/NGCP/Panel/Controller/Device.pm @@ -25,13 +25,14 @@ sub base :Chained('/') :PathPart('device') :CaptureArgs(0) { # TODO: move out fw/profile/config fetching to separate func to not # load it for subscriber access? - - my $devmod_rs = $c->model('DB')->resultset('autoprov_devices'); + my $reseller_id; if($c->user->roles eq 'reseller') { - $devmod_rs = $devmod_rs->search({ reseller_id => $c->user->reseller_id }); + $reseller_id = $c->user->reseller_id; } elsif($c->user->roles eq 'subscriber' || $c->user->roles eq 'subscriberadmin') { - $devmod_rs = $devmod_rs->search({ reseller_id => $c->user->voip_subscriber->contract->contact->reseller_id }); + $reseller_id = $c->user->voip_subscriber->contract->contact->reseller_id; } + + my $devmod_rs = $c->model('DB')->resultset('autoprov_devices')->search({ reseller_id => $reseller_id }); $c->stash->{devmod_dt_columns} = NGCP::Panel::Utils::Datatables::set_columns($c, [ { name => 'id', search => 1, title => $c->loc('#') }, { name => 'reseller.name', search => 1, title => $c->loc('Reseller') }, @@ -39,21 +40,11 @@ sub base :Chained('/') :PathPart('device') :CaptureArgs(0) { { name => 'model', search => 1, title => $c->loc('Model') }, ]); - my $devfw_rs = $c->model('DB')->resultset('autoprov_firmwares'); - if($c->user->roles eq "subscriberadmin" || $c->user->roles eq "subscriber") { - $devfw_rs = $devfw_rs->search({ - 'device.reseller_id' => $c->user->voip_subscriber->contract->contact->reseller_id, - }, { - join => 'device', - }); - } elsif($c->user->roles eq "reseller") { - $devfw_rs = $devfw_rs->search({ - 'device.reseller_id' => $c->user->reseller_id - }, { - join => 'device', - }); - } - + my $devfw_rs = $c->model('DB')->resultset('autoprov_firmwares')->search({ + 'device.reseller_id' => $reseller_id, + },{ + join => 'device', + }); $c->stash->{devfw_dt_columns} = NGCP::Panel::Utils::Datatables::set_columns($c, [ { name => 'id', search => 1, title => $c->loc('#') }, { name => 'device.reseller.name', search => 1, title => $c->loc('Reseller') }, @@ -63,21 +54,11 @@ sub base :Chained('/') :PathPart('device') :CaptureArgs(0) { { name => 'version', search => 1, title => $c->loc('Version') }, ]); - my $devconf_rs = $c->model('DB')->resultset('autoprov_configs'); - if($c->user->roles eq "subscriberadmin" || $c->user->roles eq "subscriber") { - $devconf_rs = $devconf_rs->search({ - 'device.reseller_id' => $c->user->voip_subscriber->contract->contact->reseller_id, - }, { - join => 'device', - }); - } elsif($c->user->roles eq "reseller") { - $devconf_rs = $devconf_rs->search({ - 'device.reseller_id' => $c->user->reseller_id - }, { - join => 'device', - }); - } - + my $devconf_rs = $c->model('DB')->resultset('autoprov_configs')->search({ + 'device.reseller_id' => $reseller_id, + }, { + join => 'device', + }); $c->stash->{devconf_dt_columns} = NGCP::Panel::Utils::Datatables::set_columns($c, [ { name => 'id', search => 1, title => $c->loc('#') }, { name => 'device.reseller.name', search => 1, title => $c->loc('Reseller') }, @@ -86,20 +67,11 @@ sub base :Chained('/') :PathPart('device') :CaptureArgs(0) { { name => 'version', search => 1, title => $c->loc('Version') }, ]); - my $devprof_rs = $c->model('DB')->resultset('autoprov_profiles'); - if($c->user->roles eq "subscriberadmin" || $c->user->roles eq "subscriber") { - $devprof_rs = $devprof_rs->search({ - 'device.reseller_id' => $c->user->voip_subscriber->contract->contact->reseller_id, - }, { - join => { 'config' => 'device' }, - }); - } elsif($c->user->roles eq "reseller") { - $devprof_rs = $devprof_rs->search({ - 'device.reseller_id' => $c->user->reseller_id - }, { - join => { 'config' => 'device' }, - }); - } + my $devprof_rs = $c->model('DB')->resultset('autoprov_profiles')->search({ + 'device.reseller_id' => $reseller_id, + }, { + join => { 'config' => 'device' }, + }); $c->stash->{devprof_dt_columns} = NGCP::Panel::Utils::Datatables::set_columns($c, [ { name => 'id', search => 1, title => $c->loc('#') }, { name => 'config.device.reseller.name', search => 1, title => $c->loc('Reseller') }, @@ -110,20 +82,11 @@ sub base :Chained('/') :PathPart('device') :CaptureArgs(0) { { name => 'config.version', search => 1, title => $c->loc('Configuration Version') }, ]); - my $fielddev_rs = $c->model('DB')->resultset('autoprov_field_devices'); - if($c->user->roles eq "subscriberadmin" || $c->user->roles eq "subscriber") { - $fielddev_rs = $fielddev_rs->search({ - 'device.reseller_id' => $c->user->voip_subscriber->contract->contact->reseller_id, - }, { - join => { 'profile' => { 'config' => 'device' } }, - }); - } elsif($c->user->roles eq "reseller") { - $fielddev_rs = $fielddev_rs->search({ - 'device.reseller_id' => $c->user->reseller_id - }, { - join => { 'profile' => { 'config' => 'device' } }, - }); - } + my $fielddev_rs = $c->model('DB')->resultset('autoprov_field_devices')->search({ + 'device.reseller_id' => $reseller_id, + },{ + join => { 'profile' => { 'config' => 'device' } }, + }); $c->stash->{fielddev_dt_columns} = NGCP::Panel::Utils::Datatables::set_columns($c, [ { name => 'id', search => 1, title => $c->loc('#') }, { name => 'identifier', search => 1, title => $c->loc('MAC Address / Identifier') }, @@ -132,14 +95,14 @@ sub base :Chained('/') :PathPart('device') :CaptureArgs(0) { { name => 'contract.contact.email', search => 1, title => $c->loc('Customer Email') }, ]); - $c->stash( devmod_rs => $devmod_rs, - devfw_rs => $devfw_rs, - devconf_rs => $devconf_rs, - devprof_rs => $devprof_rs, + devfw_rs => $devfw_rs, + devconf_rs => $devconf_rs, + devprof_rs => $devprof_rs, fielddev_rs => $fielddev_rs, - template => 'device/list.tt', + reseller_id => $reseller_id, + template => 'device/list.tt', ); } @@ -211,6 +174,7 @@ sub devmod_create :Chained('base') :PathPart('model/create') :Args(0) :Does(ACL) my $linerange = delete $form->params->{linerange}; my $devmod = $schema->resultset('autoprov_devices')->create($form->params); + $c->forward('devmod_sync_parameters',[$schema,$devmod,$form->params] ); foreach my $range(@{ $linerange }) { delete $range->{id}; @@ -309,7 +273,14 @@ sub devmod_edit :Chained('devmod_base') :PathPart('edit') :Args(0) :Does(ACL) :A my $r = { $range->get_inflated_columns }; $r->{keys} = $keys; push @{ $params->{linerange} }, $r; + } + + foreach ( @{ $c->model('DB')->resultset('autoprov_sync_parameters')->search_rs({ + 'me.bootstrap_method' => $c->stash->{devmod}->bootstrap_method, + })->all} ){ + $params->{'bootstrap_config_'.$c->stash->{devmod}->bootstrap_method.'_'.$_->parameter_name} = $_->parameter_value; } + $params->{reseller}{id} = delete $params->{reseller_id}; $params = $params->merge($c->session->{created_objects}); $c->stash(edit_model => 1); # to make front_image optional @@ -365,16 +336,17 @@ sub devmod_edit :Chained('devmod_base') :PathPart('edit') :Args(0) :Does(ACL) :A delete $form->params->{mac_image}; delete $form->params->{mac_image_type}; } - - my $params = {}; - foreach(qw/linerange sync_uri sync_method sync_params/){ - $params->{$_} = delete $form->params->{$_}; - } $c->stash->{devmod}->update($form->params); - + + $schema->resultset('autoprov_sync')->search_rs({ + device_id => $c->stash->{devmod}->id, + })->delete; + #$c->forward('devmod_sync_parameters',[$schema, $c->stash->{devmod}, $form->params]); + + my $linerange = delete $form->params->{'linerange'}; my @existing_range = (); my $range_rs = $c->stash->{devmod}->autoprov_device_line_ranges; - foreach my $range(@{ $params->{linerange} }) { + foreach my $range(@{ $linerange }) { next unless(defined $range); my $keys = delete $range->{keys}; $range->{num_lines} = @{ $keys }; # backward compatibility @@ -451,6 +423,22 @@ sub devmod_edit :Chained('devmod_base') :PathPart('edit') :Args(0) :Does(ACL) :A ); } +sub devmod_sync_parameters :Private { + my($self,$c,$schema,$devmod,$params) = @_; + #$schema ||= $c->model('DB'); + my $bootstrap_method = $params->{'bootstrap_method'}; + my $bootstrap_params_rs = $schema->resultset('autoprov_sync_parameters')->search_rs({ + 'me.bootstrap_method' => $bootstrap_method, + }); + foreach (@$bootstrap_params_rs->all){ + my $sync_parameter = { + device_id => $devmod->id, + parameter_id => $_->id, + parameter_value => $params->{'bootstrap_config_'.$bootstrap_method.'_'.$_->parameter_name}, + }; + $schema->resultset('autoprov_sync')->create($sync_parameter); + } +} sub devmod_download_frontimage_by_profile :Chained('devprof_base') :PathPart('frontimage') :Args(0) { my ($self, $c) = @_; diff --git a/lib/NGCP/Panel/Form/CFDestinationSetAPI.pm b/lib/NGCP/Panel/Form/CFDestinationSetAPI.pm index 7191bfd673..59eaa29da8 100644 --- a/lib/NGCP/Panel/Form/CFDestinationSetAPI.pm +++ b/lib/NGCP/Panel/Form/CFDestinationSetAPI.pm @@ -32,7 +32,7 @@ has_field 'destinations' => ( type => 'Repeatable', element_attr => { rel => ['tooltip'], - title => ['An array of destinations, each containing the keys "destination", "timeout" and "priority".'] + title => ['An array of destinations, each containing the keys "destination", "timeout", "priority" and "simple_destination".'] }, ); diff --git a/lib/NGCP/Panel/Form/Device/Model.pm b/lib/NGCP/Panel/Form/Device/Model.pm index 1c7b4f3dc2..27ba677747 100644 --- a/lib/NGCP/Panel/Form/Device/Model.pm +++ b/lib/NGCP/Panel/Form/Device/Model.pm @@ -21,6 +21,7 @@ has_field 'vendor' => ( element_attr => { rel => ['tooltip'], title => ['The vendor name of this device.'], + javascript => ' onchange="vendor2bootstrapMethod(this);" ', }, ); @@ -48,43 +49,6 @@ has_field 'mac_image' => ( max_size => '67108864', # 64MB ); -has_field 'sync_uri' => ( - type => 'Text', - required => 0, - label => 'Bootstrap Sync URI', - default => 'http://[% client.ip %]/admin/resync', - element_attr => { - rel => ['tooltip'], - title => ['The sync URI to set the provisioning server of the device (e.g. http://client.ip/admin/resync. The client.ip variable is automatically expanded during provisioning time.'], - }, -); - -has_field 'sync_method' => ( - type => 'Select', - required => 0, - label => 'Bootstrap Sync HTTP Method', - options => [ - { label => 'GET', value => 'GET' }, - { label => 'POST', value => 'POST' }, - ], - default => 'GET', - element_attr => { - rel => ['tooltip'], - title => ['The HTTP method to set the provisioning server (one of GET, POST).'], - }, -); - -has_field 'sync_params' => ( - type => 'Text', - required => 0, - label => 'Bootstrap Sync Parameters', - default => '[% server.uri %]/$MA', - element_attr => { - rel => ['tooltip'], - title => ['The parameters appended to the sync URI when setting the provisioning server, e.g. server.uri/$MA. The server.uri variable is automatically expanded during provisioning time.'], - }, -); - has_field 'linerange' => ( type => 'Repeatable', label => 'Line/Key Range', @@ -233,6 +197,68 @@ has_field 'linerange_add' => ( element_class => [qw/btn btn-primary pull-right/], ); +has_field 'bootstrap_method' => ( + type => 'Select', + required => 1, + label => 'Bootstrap Method', + options => [ + { label => 'HTTP (Cisco)', value => 'http' }, + { label => 'Panasonic redirect', value => 'redirect_panasonic' }, + { label => 'Linksys redirect', value => 'redirect_linksys' }, + { label => 'Panasonic redirect', value => 'redirect_' }, + ], + default => 'http', + element_attr => { + rel => ['tooltip'], + title => ['Selected method will be used to configure device provisioning server.'], + javascript => ' onchange="bootstrapDynamicFields(this.options[this.selectedIndex].value);" ', + }, +); + + +has_field 'bootstrap_config_http_sync_uri' => ( + type => 'Text', + required => 0, + label => 'Bootstrap Sync URI', + default => 'http://[% client.ip %]/admin/resync', + wrapper_class => [qw/bootstrap_config bootstrap_config_http/], + element_attr => { + rel => ['tooltip'], + title => ['The sync URI to set the provisioning server of the device (e.g. http://client.ip/admin/resync. The client.ip variable is automatically expanded during provisioning time.'], + }, +); + +has_field 'bootstrap_config_http_sync_method' => ( + type => 'Select', + required => 0, + label => 'Bootstrap Sync HTTP Method', + options => [ + { label => 'GET', value => 'GET' }, + { label => 'POST', value => 'POST' }, + ], + default => 'GET', + wrapper_class => [qw/bootstrap_config bootstrap_config_http/], + element_attr => { + rel => ['tooltip'], + title => ['The HTTP method to set the provisioning server (one of GET, POST).'], + }, +); + + +has_field 'bootstrap_config_http_sync_params' => ( + type => 'Text', + required => 0, + label => 'Bootstrap Sync Parameters', + default => '[% server.uri %]/$MA', + wrapper_class => [qw/bootstrap_config bootstrap_config_http/], + element_attr => { + rel => ['tooltip'], + title => ['The parameters appended to the sync URI when setting the provisioning server, e.g. server.uri/$MA. The server.uri variable is automatically expanded during provisioning time.'], + }, +); + + + has_field 'save' => ( type => 'Submit', value => 'Save', @@ -243,7 +269,7 @@ has_field 'save' => ( has_block 'fields' => ( tag => 'div', class => [qw/modal-body/], - render_list => [qw/vendor model linerange linerange_add front_image mac_image sync_uri sync_method sync_params/], + render_list => [qw/vendor model linerange linerange_add bootstrap_method bootstrap_config_http_sync_uri bootstrap_config_http_sync_method bootstrap_config_http_sync_params front_image mac_image/], ); has_block 'actions' => ( diff --git a/lib/NGCP/Panel/Form/Device/ModelAdmin.pm b/lib/NGCP/Panel/Form/Device/ModelAdmin.pm index 6ee26bcdcf..ec30a562de 100644 --- a/lib/NGCP/Panel/Form/Device/ModelAdmin.pm +++ b/lib/NGCP/Panel/Form/Device/ModelAdmin.pm @@ -26,7 +26,7 @@ has_field 'save' => ( has_block 'fields' => ( tag => 'div', class => [qw/modal-body/], - render_list => [qw/reseller vendor model linerange linerange_add front_image mac_image sync_uri sync_method sync_params/], + render_list => [qw/reseller vendor model linerange linerange_add bootstrap_method bootstrap_config_http_sync_uri bootstrap_config_http_sync_method bootstrap_config_http_sync_params front_image mac_image/], ); has_block 'actions' => ( diff --git a/lib/NGCP/Panel/Utils/DeviceBootstrap.pm b/lib/NGCP/Panel/Utils/DeviceBootstrap.pm index f76a6dd6c3..b836cdffa9 100644 --- a/lib/NGCP/Panel/Utils/DeviceBootstrap.pm +++ b/lib/NGCP/Panel/Utils/DeviceBootstrap.pm @@ -81,7 +81,8 @@ sub panasonic_bootstrap_register{ $authorization .= '='; #params => c,redirect_uri,redirect_uri_params, mac - $params->{redirect_uri_params} ||= $params->{mac}; + #$params->{redirect_uri_params} ||= $params->{mac}; + $params->{redirect_uri_params} ||= '{MAC}'; my $uri = get_bootstrap_uri($params); $uri = URI::Escape::uri_escape($uri); diff --git a/share/templates/device/list.tt b/share/templates/device/list.tt index 04f5af8753..2a16538743 100644 --- a/share/templates/device/list.tt +++ b/share/templates/device/list.tt @@ -6,7 +6,43 @@ [% back_created = 1 -%] - + +
[% FOREACH m IN messages -%]
[% m.text %]