From ab79afbb67dfdd04e11e111b7508d427d9c0976e Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Mon, 5 Aug 2013 11:31:41 +0200 Subject: [PATCH] Fix config paths and dbalias creation. In case a subscriber is created from within the customer view, then also clear the created objects and write a dbalias. --- lib/NGCP/Panel.pm | 37 +++++------------------ lib/NGCP/Panel/Controller/Customer.pm | 15 +++++++++ lib/NGCP/Panel/Controller/Login.pm | 4 +++ lib/NGCP/Panel/Controller/Root.pm | 2 +- lib/NGCP/Panel/Controller/Subscriber.pm | 4 +-- lib/NGCP/Panel/Field/BillingProfile.pm | 2 +- lib/NGCP/Panel/Field/BillingZone.pm | 2 +- lib/NGCP/Panel/Field/Contact.pm | 2 +- lib/NGCP/Panel/Field/Contract.pm | 2 +- lib/NGCP/Panel/Field/CustomerContract.pm | 2 +- lib/NGCP/Panel/Field/DataTable.pm | 11 +++++-- lib/NGCP/Panel/Field/Domain.pm | 2 +- lib/NGCP/Panel/Field/Reseller.pm | 2 +- lib/NGCP/Panel/Field/ResellerContract.pm | 2 +- lib/NGCP/Panel/Form/DestinationSet.pm | 33 ++++++++++++++------ lib/NGCP/Panel/Form/SubscriberCFSimple.pm | 33 ++++++++++++++------ ngcp_panel.conf | 8 +++++ share/templates/login/login.tt | 2 +- share/templates/statistics/list.tt | 2 +- 19 files changed, 104 insertions(+), 63 deletions(-) diff --git a/lib/NGCP/Panel.pm b/lib/NGCP/Panel.pm index 5e48586909..66d8256790 100644 --- a/lib/NGCP/Panel.pm +++ b/lib/NGCP/Panel.pm @@ -30,14 +30,13 @@ extends 'Catalyst'; our $VERSION = '0.01'; -# Configure the application. -# -# Note that settings in ngcp_panel.conf (or other external -# configuration file that you set up manually) take precedence -# over this when using ConfigLoader. Thus configuration -# details given here can function as a default configuration, -# with an external configuration file acting as an override for -# local deployment. +my $panel_config; +for my $path(qw#/etc/ngcp-panel/ngcp_panel.conf etc/ngcp_panel.conf ngcp_panel.conf#) { + if(-f $path) { + $panel_config = $path; + } +} +$panel_config //= 'ngcp_panel.conf'; __PACKAGE__->config( name => 'NGCP::Panel', @@ -46,7 +45,7 @@ __PACKAGE__->config( enable_catalyst_header => 1, # Send X-Catalyst header encoding => 'UTF-8', 'Plugin::ConfigLoader' => { - file => '/etc/ngcp-panel/ngcp_panel.conf', + file => $panel_config, }, 'View::HTML' => { INCLUDE_PATH => [ @@ -92,26 +91,6 @@ __PACKAGE__->config( } } }, - subscriber => { - credential => { - class => 'Password', - password_field => 'password', - password_type => 'clear' - }, - store => { - class => 'Minimal', - users => { - subscriberadmin => { - password => 'subscriberadmin', - roles => [qw/subscriberadmin subscriber/], - }, - subscriber => { - password => 'subscriber', - roles => [qw/subscriber/], - }, - } - } - }, reseller => { credential => { class => 'Password', diff --git a/lib/NGCP/Panel/Controller/Customer.pm b/lib/NGCP/Panel/Controller/Customer.pm index 92f8b8283c..567fc53816 100644 --- a/lib/NGCP/Panel/Controller/Customer.pm +++ b/lib/NGCP/Panel/Controller/Customer.pm @@ -141,9 +141,12 @@ sub subscriber_create :Chained('base') :PathPart('subscriber/create') :Args(0) { my ($self, $c) = @_; my $form = NGCP::Panel::Form::CustomerSubscriber->new; + my $params = {}; + $params = $params->merge($c->session->{created_objects}); $form->process( posted => ($c->request->method eq 'POST'), params => $c->request->params, + item => $params, ); NGCP::Panel::Utils::Navigation::check_form_buttons( c => $c, @@ -244,6 +247,18 @@ sub subscriber_create :Chained('base') :PathPart('subscriber/create') :Args(0) { password => sprintf("%04d", int(rand 10000)), email => '', }); + if($number) { + $schema->resultset('dbaliases')->create({ + alias_username => $number->cc . + ($number->ac || ''). + $number->sn, + alias_domain => $prov_subscriber->domain->domain, + username => $prov_subscriber->username, + domain => $prov_subscriber->domain->domain, + }); + } + + delete $c->session->{created_objects}->{domain}; }); $c->flash(messages => [{type => 'success', text => 'Subscriber successfully created!'}]); diff --git a/lib/NGCP/Panel/Controller/Login.pm b/lib/NGCP/Panel/Controller/Login.pm index 8944b46fed..45d10a2ab9 100644 --- a/lib/NGCP/Panel/Controller/Login.pm +++ b/lib/NGCP/Panel/Controller/Login.pm @@ -27,8 +27,12 @@ sub index :Path Form { my ( $self, $c, $realm ) = @_; $c->log->debug("*** Login::index"); +=pod $realm = 'subscriber' unless($realm and ($realm eq 'admin' or $realm eq 'reseller')); +=cut + $realm = 'admin' + unless($realm and ($realm eq 'reseller')); my $form = NGCP::Panel::Form::Login->new; $form->process( diff --git a/lib/NGCP/Panel/Controller/Root.pm b/lib/NGCP/Panel/Controller/Root.pm index 9e7f7667c2..bf7992c50b 100644 --- a/lib/NGCP/Panel/Controller/Root.pm +++ b/lib/NGCP/Panel/Controller/Root.pm @@ -46,7 +46,7 @@ sub auto :Private { } $c->log->debug("*** Root::auto do login, target='$target'"); $c->session(target => $target); - $c->response->redirect($c->uri_for('/login')); + $c->response->redirect($c->uri_for('/login/admin')); return; } diff --git a/lib/NGCP/Panel/Controller/Subscriber.pm b/lib/NGCP/Panel/Controller/Subscriber.pm index d4f47614ca..b90b6dc655 100644 --- a/lib/NGCP/Panel/Controller/Subscriber.pm +++ b/lib/NGCP/Panel/Controller/Subscriber.pm @@ -472,9 +472,9 @@ sub preferences_callforward :Chained('base') :PathPart('preferences/callforward' my $cf_form; if($cf_type eq "cft") { - $cf_form = NGCP::Panel::Form::SubscriberCFTSimple->new; + $cf_form = NGCP::Panel::Form::SubscriberCFTSimple->new(ctx => $c); } else { - $cf_form = NGCP::Panel::Form::SubscriberCFSimple->new; + $cf_form = NGCP::Panel::Form::SubscriberCFSimple->new(ctx => $c); } $cf_form->process( diff --git a/lib/NGCP/Panel/Field/BillingProfile.pm b/lib/NGCP/Panel/Field/BillingProfile.pm index 94643efb7e..564fcdf15d 100644 --- a/lib/NGCP/Panel/Field/BillingProfile.pm +++ b/lib/NGCP/Panel/Field/BillingProfile.pm @@ -8,7 +8,7 @@ has_field 'id' => ( do_label => 0, do_wrapper => 0, required => 1, - template => '/usr/share/ngcp-panel/templates/helpers/datatables_field.tt', + template => 'helpers/datatables_field.tt', ajax_src => '/billing/ajax', table_titles => ['#', 'Profile'], table_fields => ['id', 'name'], diff --git a/lib/NGCP/Panel/Field/BillingZone.pm b/lib/NGCP/Panel/Field/BillingZone.pm index a039b1864a..d372738de9 100644 --- a/lib/NGCP/Panel/Field/BillingZone.pm +++ b/lib/NGCP/Panel/Field/BillingZone.pm @@ -8,7 +8,7 @@ has_field 'id' => ( do_label => 0, do_wrapper => 0, required => 1, - template => '/usr/share/ngcp-panel/templates/helpers/datatables_field.tt', + template => 'helpers/datatables_field.tt', ajax_src => '../zones/ajax', # /billing//zones/ajax table_titles => ['#', 'Zone', 'Zone Detail'], table_fields => ['id', 'zone', 'detail'], diff --git a/lib/NGCP/Panel/Field/Contact.pm b/lib/NGCP/Panel/Field/Contact.pm index 196a5774b2..5d91aa8a64 100644 --- a/lib/NGCP/Panel/Field/Contact.pm +++ b/lib/NGCP/Panel/Field/Contact.pm @@ -8,7 +8,7 @@ has_field 'id' => ( do_label => 0, do_wrapper => 0, required => 1, - template => '/usr/share/ngcp-panel/templates/helpers/datatables_field.tt', + template => 'helpers/datatables_field.tt', ajax_src => '/contact/ajax', table_titles => ['#', 'Reseller', 'First Name', 'Last Name', 'Email'], table_fields => ['id', 'reseller_name', 'firstname', 'lastname', 'email'], diff --git a/lib/NGCP/Panel/Field/Contract.pm b/lib/NGCP/Panel/Field/Contract.pm index fdbb8b831f..cfe0e63579 100644 --- a/lib/NGCP/Panel/Field/Contract.pm +++ b/lib/NGCP/Panel/Field/Contract.pm @@ -8,7 +8,7 @@ has_field 'id' => ( do_label => 0, do_wrapper => 0, required => 1, - template => '/usr/share/ngcp-panel/templates/helpers/datatables_field.tt', + template => 'helpers/datatables_field.tt', ajax_src => '/contract/peering/ajax', table_titles => ['#', 'Status', 'Billing Profile'], table_fields => ['id', 'status', 'billing_mappings_billing_profile_name'], diff --git a/lib/NGCP/Panel/Field/CustomerContract.pm b/lib/NGCP/Panel/Field/CustomerContract.pm index 437dd2612d..11bf74ab6c 100644 --- a/lib/NGCP/Panel/Field/CustomerContract.pm +++ b/lib/NGCP/Panel/Field/CustomerContract.pm @@ -8,7 +8,7 @@ has_field 'id' => ( do_label => 0, do_wrapper => 0, required => 1, - template => '/usr/share/ngcp-panel/templates/helpers/datatables_field.tt', + template => 'helpers/datatables_field.tt', ajax_src => '/contract/customer/ajax', table_titles => ['#', 'Reseller', 'Contact Email', 'External #', 'Status'], table_fields => ['id', 'contact_reseller_name', 'contact_email', 'external_id', 'status'], diff --git a/lib/NGCP/Panel/Field/DataTable.pm b/lib/NGCP/Panel/Field/DataTable.pm index cb351753d5..15402dbe8f 100644 --- a/lib/NGCP/Panel/Field/DataTable.pm +++ b/lib/NGCP/Panel/Field/DataTable.pm @@ -6,8 +6,7 @@ extends 'HTML::FormHandler::Field'; has '+widget' => (default => ''); # leave this empty, as there is no widget ... has 'template' => ( isa => 'Str', is => 'rw', - # TODO: not found in real environment! - default => '/usr/share/ngcp-panel/templates/helpers/datatables_field.tt' ); + default => 'helpers/datatables_field.tt' ); has 'ajax_src' => ( isa => 'Str', is => 'rw' ); has 'table_fields' => ( isa => 'ArrayRef', is => 'rw' ); has 'table_titles' => ( isa => 'ArrayRef', is => 'rw' ); @@ -29,7 +28,13 @@ sub render_element { table_titles => $self->table_titles, errors => $self->errors, }; - my $t = new Template({ ABSOLUTE => 1, }); + my $t = new Template({ + ABSOLUTE => 1, + INCLUDE_PATH => [ + '/usr/share/ngcp-panel/templates', + 'share/templates', + ], + }); $t->process($self->template, $vars, \$output) or die "Failed to process Datatables field template: ".$t->error(); diff --git a/lib/NGCP/Panel/Field/Domain.pm b/lib/NGCP/Panel/Field/Domain.pm index 758421b6e5..1573ea7396 100644 --- a/lib/NGCP/Panel/Field/Domain.pm +++ b/lib/NGCP/Panel/Field/Domain.pm @@ -8,7 +8,7 @@ has_field 'id' => ( do_label => 0, do_wrapper => 0, required => 1, - template => '/usr/share/ngcp-panel/templates/helpers/datatables_field.tt', + template => 'helpers/datatables_field.tt', ajax_src => '/domain/ajax', table_titles => ['#', 'Reseller', 'Domain'], table_fields => ['id', 'domain_resellers_reseller_name', 'domain'], diff --git a/lib/NGCP/Panel/Field/Reseller.pm b/lib/NGCP/Panel/Field/Reseller.pm index 5bd6a52495..254bf91f08 100644 --- a/lib/NGCP/Panel/Field/Reseller.pm +++ b/lib/NGCP/Panel/Field/Reseller.pm @@ -8,7 +8,7 @@ has_field 'id' => ( do_label => 0, do_wrapper => 0, required => 1, - template => '/usr/share/ngcp-panel/templates/helpers/datatables_field.tt', + template => 'helpers/datatables_field.tt', ajax_src => '/reseller/ajax', table_titles => ['#', 'Name', 'Contract #', 'Status'], table_fields => ['id', 'name', 'contract_id', 'status'], diff --git a/lib/NGCP/Panel/Field/ResellerContract.pm b/lib/NGCP/Panel/Field/ResellerContract.pm index 028aa0dbfe..bd7083a32a 100644 --- a/lib/NGCP/Panel/Field/ResellerContract.pm +++ b/lib/NGCP/Panel/Field/ResellerContract.pm @@ -8,7 +8,7 @@ has_field 'id' => ( do_label => 0, do_wrapper => 0, required => 1, - template => '/usr/share/ngcp-panel/templates/helpers/datatables_field.tt', + template => 'helpers/datatables_field.tt', ajax_src => '/reseller/ajax_contract', table_titles => ['#', 'Contact Email', 'External #', 'Status'], table_fields => ['id', 'contact_email', 'external_id', 'status'], diff --git a/lib/NGCP/Panel/Form/DestinationSet.pm b/lib/NGCP/Panel/Form/DestinationSet.pm index 26298cc830..6dd0ec7cd7 100644 --- a/lib/NGCP/Panel/Form/DestinationSet.pm +++ b/lib/NGCP/Panel/Form/DestinationSet.pm @@ -38,15 +38,7 @@ has_field 'destination.destination' => ( widget => 'RadioGroup', label => 'Destination', do_label => 1, - options => [ - { label => 'Voicemail', value => 'voicebox' }, - { label => 'Conference', value => 'conference' }, - { label => 'Fax2Mail', value => 'fax2mail' }, - { label => 'Calling Card', value => 'callingcard' }, - { label => 'Call Trough', value => 'callthrough' }, - { label => 'Local Subscriber', value => 'localuser' }, - { label => 'URI/Number', value => 'uri' }, - ], + options_method => \&build_destinations, default => 'uri', tags => { before_element => '
', @@ -54,6 +46,29 @@ has_field 'destination.destination' => ( }, ); +sub build_destinations { + my ($self) = @_; + + my @options = (); + push @options, { label => 'Voicemail', value => 'voicebox' }; + my $c = $self->form->ctx; + if(defined $c) { + push @options, { label => 'Conference', value => 'conference' } + if($c->config->{features}->{conference}); + push @options, { label => 'Fax2Mail', value => 'fax2mail' } + if($c->config->{features}->{faxserver}); + push @options, { label => 'Calling Card', value => 'callingcard' } + if($c->config->{features}->{callingcard}); + push @options, { label => 'Call Trough', value => 'callthrough' } + if($c->config->{features}->{callthrough}); + push @options, { label => 'Local Subscriber', value => 'localuser' } + if($c->config->{features}->{callthrough} || $c->config->{features}->{callingcard} ); + } + push @options, { label => 'URI/Number', value => 'uri' }; + + return \@options; +} + has_field 'destination.uri' => ( type => 'Compound', do_label => 0, diff --git a/lib/NGCP/Panel/Form/SubscriberCFSimple.pm b/lib/NGCP/Panel/Form/SubscriberCFSimple.pm index 0b4f963259..b2db08bfea 100644 --- a/lib/NGCP/Panel/Form/SubscriberCFSimple.pm +++ b/lib/NGCP/Panel/Form/SubscriberCFSimple.pm @@ -27,18 +27,33 @@ has_field 'destination.destination' => ( widget => 'RadioGroup', label => 'Destination', do_label => 1, - options => [ - { label => 'Voicemail', value => 'voicebox' }, - { label => 'Conference', value => 'conference' }, - { label => 'Fax2Mail', value => 'fax2mail' }, - { label => 'Calling Card', value => 'callingcard' }, - { label => 'Call Trough', value => 'callthrough' }, - { label => 'Local Subscriber', value => 'localuser' }, - { label => 'URI/Number', value => 'uri' }, - ], + options_method => \&build_destionations, default => 'uri', ); +sub build_destinations { + my ($self) = @_; + + my @options = (); + push @options, { label => 'Voicemail', value => 'voicebox' }; + my $c = $self->form->ctx; + if(defined $c) { + push @options, { label => 'Conference', value => 'conference' } + if($c->config->{features}->{conference}); + push @options, { label => 'Fax2Mail', value => 'fax2mail' } + if($c->config->{features}->{faxserver}); + push @options, { label => 'Calling Card', value => 'callingcard' } + if($c->config->{features}->{callingcard}); + push @options, { label => 'Call Trough', value => 'callthrough' } + if($c->config->{features}->{callthrough}); + push @options, { label => 'Local Subscriber', value => 'localuser' } + if($c->config->{features}->{callthrough} || $c->config->{features}->{callingcard} ); + } + push @options, { label => 'URI/Number', value => 'uri' }; + + return \@options; +} + has_field 'destination.uri' => ( type => 'Compound', do_label => 0, diff --git a/ngcp_panel.conf b/ngcp_panel.conf index d784f2273b..3d81aba4d7 100644 --- a/ngcp_panel.conf +++ b/ngcp_panel.conf @@ -14,6 +14,14 @@ log4perl.appender.Default.layout.ConversionPattern=%d{ISO8601} [%p] [%F +%L] %m{ schema_class NGCP::Schema + + faxserver 0 + callthrough 0 + callingcard 0 + faxserver 0 + conference 1 + + element_order source element_order destination diff --git a/share/templates/login/login.tt b/share/templates/login/login.tt index e5574b908a..46b1bc2e52 100644 --- a/share/templates/login/login.tt +++ b/share/templates/login/login.tt @@ -9,7 +9,7 @@