diff --git a/lib/NGCP/Panel/Controller/Customer.pm b/lib/NGCP/Panel/Controller/Customer.pm index f180e410bf..5ed7fc1ad4 100644 --- a/lib/NGCP/Panel/Controller/Customer.pm +++ b/lib/NGCP/Panel/Controller/Customer.pm @@ -149,9 +149,12 @@ sub subscriber_create :Chained('base') :PathPart('subscriber/create') :Args(0) { # TODO: check if we find a reseller and contract and domains - my $number; + my $number; my $cli = 0; if(defined $c->request->params->{'e164.cc'} && $c->request->params->{'e164.cc'} ne '') { + $cli = $c->request->params->{'e164.cc'} . + ($c->request->params->{'e164.ac'} || '') . + $c->request->params->{'e164.sn'}; $number = $reseller->voip_numbers->create({ cc => $c->request->params->{'e164.cc'}, @@ -204,7 +207,7 @@ sub subscriber_create :Chained('base') :PathPart('subscriber/create') :Args(0) { 'subscriber_id' => $prov_subscriber->id, 'value' => $c->request->params->{'e164.cc'}, }); - my $cli = $c->request->params->{'e164.cc'} . + $cli = $c->request->params->{'e164.cc'} . (defined $c->request->params->{'e164.ac'} && length($c->request->params->{'e164.ac'}) > 0 ? $c->request->params->{'e164.ac'} : '' @@ -216,6 +219,14 @@ sub subscriber_create :Chained('base') :PathPart('subscriber/create') :Args(0) { 'value' => $cli, }); } + + $schema->resultset('voicemail_users')->create({ + customer_id => $uuid_string, + mailbox => $cli, + password => sprintf("%04d", int(rand 10000)), + email => '', + }); + }); $c->flash(messages => [{type => 'success', text => 'Subscriber successfully created!'}]); $c->response->redirect($c->uri_for_action('/customer/details', [$contract->id])); diff --git a/lib/NGCP/Panel/Controller/Subscriber.pm b/lib/NGCP/Panel/Controller/Subscriber.pm index 0c9ee44de6..cade630313 100644 --- a/lib/NGCP/Panel/Controller/Subscriber.pm +++ b/lib/NGCP/Panel/Controller/Subscriber.pm @@ -15,6 +15,10 @@ use NGCP::Panel::Form::SubscriberCFAdvanced; use NGCP::Panel::Form::SubscriberCFTAdvanced; use NGCP::Panel::Form::DestinationSet; use NGCP::Panel::Form::TimeSet; +use NGCP::Panel::Form::Voicemail::Pin; +use NGCP::Panel::Form::Voicemail::Email; +use NGCP::Panel::Form::Voicemail::Attach; +use NGCP::Panel::Form::Voicemail::Delete; use UUID; use Data::Printer; @@ -126,6 +130,7 @@ sub create_list :Chained('sub_list') :PathPart('create') :Args(0) { domain_id => $prov_domain->id, }); + my $cli = 0; my $voip_preferences = $schema->resultset('voip_preferences')->search({ 'usr_pref' => 1, }); @@ -148,7 +153,7 @@ sub create_list :Chained('sub_list') :PathPart('create') :Args(0) { 'subscriber_id' => $prov_subscriber->id, 'value' => $c->request->params->{'e164.cc'}, }); - my $cli = $c->request->params->{'e164.cc'} . + $cli = $c->request->params->{'e164.cc'} . (defined $c->request->params->{'e164.ac'} && length($c->request->params->{'e164.ac'}) > 0 ? $c->request->params->{'e164.ac'} : '' @@ -160,6 +165,12 @@ sub create_list :Chained('sub_list') :PathPart('create') :Args(0) { 'value' => $cli, }); } + $schema->resultset('voicemail_users')->create({ + customer_id => $uuid_string, + mailbox => $cli, + password => sprintf("%04d", int(rand 10000)), + email => '', + }); }); $c->flash(messages => [{type => 'success', text => 'Subscriber successfully created!'}]); $c->response->redirect($c->uri_for('/subscriber')); @@ -1310,8 +1321,8 @@ sub details :Chained('master') :PathPart('') :Args(0) { my ($self, $c) = @_; } -sub edit_master :Chained('master') :PathPart('edit') { - my ($self, $c, $attribute) = @_; +sub edit_master :Chained('master') :PathPart('edit') :Args(0) { + my ($self, $c) = @_; my $form = NGCP::Panel::Form::SubscriberEdit->new; my $posted = ($c->request->method eq 'POST'); @@ -1426,6 +1437,88 @@ sub edit_master :Chained('master') :PathPart('edit') { } +sub edit_voicebox :Chained('base') :PathPart('preferences/voicebox/edit') :Args(1) { + my ($self, $c, $attribute) = @_; + + my $form; + my $posted = ($c->request->method eq 'POST'); + my $vm_user = $c->stash->{subscriber}->provisioning_voip_subscriber->voicemail_user; + unless($vm_user) { + $c->log->error("no voicemail user found for subscriber uuid ".$c->stash->{subscriber}->uuid); + $c->flash(messages => [{type => 'error', text => 'Failed to find voicemail user'}]); + $c->response->redirect($c->uri_for_action('/subscriber/preferences', [$c->req->captures->[0]])); + return; + # TODO: we could create one instead? + } + my $params; + + try { + given($attribute) { + when('pin') { + $form = NGCP::Panel::Form::Voicemail::Pin->new; + $params = { 'pin' => $vm_user->password }; + $form->process(params => $posted ? $c->req->params : $params); + if($posted && $form->validated) { + $vm_user->update({ password => $form->field('pin')->value }); + } + } + when('email') { + $form = NGCP::Panel::Form::Voicemail::Email->new; + $params = { 'email' => $vm_user->email }; + $form->process(params => $posted ? $c->req->params : $params); + if($posted && $form->validated) { + $vm_user->update({ email => $form->field('email')->value }); + } + } + when('attach') { + $form = NGCP::Panel::Form::Voicemail::Attach->new; + $params = { 'attach' => $vm_user->attach eq 'yes' ? 1 : 0 }; + $form->process(params => $posted ? $c->req->params : $params); + if($posted && $form->validated) { + $vm_user->update({ attach => $form->field('attach')->value ? 'yes' : 'no' }); + } + } + when('delete') { + $form = NGCP::Panel::Form::Voicemail::Delete->new; + $params = { 'delete' => $vm_user->get_column('delete') eq 'yes' ? 1 : 0 }; + $form->process(params => $posted ? $c->req->params : $params); + if($posted && $form->validated) { + $vm_user->update({ + # TODO: which accessor? + column_delete => $form->field('delete')->value ? 'yes' : 'no', + # force attach if delete flag is set, otherwise message will be lost + 'attach' => $form->field('delete')->value ? 'yes' : $vm_user->attach, + }); + } + } + default { + $c->log->error("trying to set invalid voicemail param '$attribute' for subscriber uuid ".$c->stash->{subscriber}->uuid); + $c->flash(messages => [{type => 'error', text => 'Invalid voicemail setting'}]); + $c->response->redirect($c->uri_for_action('/subscriber/preferences', [$c->req->captures->[0]])); + return; + } + } + if($posted && $form->validated) { + $c->flash(messages => [{type => 'success', text => 'Successfully updated voicemail setting'}]); + $c->response->redirect($c->uri_for_action('/subscriber/preferences', [$c->req->captures->[0]])); + return; + } + } catch($e) { + $c->log->error("updating voicemail setting failed: $e"); + $c->flash(messages => [{type => 'error', text => 'Failed to update voicemail setting'}]); + $c->response->redirect($c->uri_for_action('/subscriber/preferences', [$c->req->captures->[0]])); + return; + } + + $c->stash( + template => 'subscriber/preferences.tt', + edit_cf_flag => 1, + cf_description => $attribute, + cf_form => $form, + close_target => $c->uri_for_action('/subscriber/preferences', [$c->req->captures->[0]]), + ); +} + sub ajax_calls :Chained('master') :PathPart('calls/ajax') :Args(0) { my ($self, $c) = @_; diff --git a/lib/NGCP/Panel/Form/Voicemail/Attach.pm b/lib/NGCP/Panel/Form/Voicemail/Attach.pm new file mode 100644 index 0000000000..e2879fd374 --- /dev/null +++ b/lib/NGCP/Panel/Form/Voicemail/Attach.pm @@ -0,0 +1,39 @@ +package NGCP::Panel::Form::Voicemail::Attach; + +use HTML::FormHandler::Moose; +extends 'HTML::FormHandler'; +use Moose::Util::TypeConstraints; + +use HTML::FormHandler::Widget::Block::Bootstrap; + +has '+widget_wrapper' => ( default => 'Bootstrap' ); +sub build_render_list {[qw/fields actions/]} +sub build_form_element_class { [qw/form-horizontal/] } + +has_field 'attach' => ( + type => 'Boolean', + label => 'Attach WAV', + required => 0, +); + +has_field 'save' => ( + type => 'Submit', + value => 'Save', + element_class => [qw/btn btn-primary/], + label => '', +); + +has_block 'fields' => ( + tag => 'div', + class => [qw/modal-body/], + render_list => [qw/attach/], +); + +has_block 'actions' => ( + tag => 'div', + class => [qw/modal-footer/], + render_list => [qw/save/], +); + +1; +# vim: set tabstop=4 expandtab: diff --git a/lib/NGCP/Panel/Form/Voicemail/Delete.pm b/lib/NGCP/Panel/Form/Voicemail/Delete.pm new file mode 100644 index 0000000000..c2d5b2aa6e --- /dev/null +++ b/lib/NGCP/Panel/Form/Voicemail/Delete.pm @@ -0,0 +1,39 @@ +package NGCP::Panel::Form::Voicemail::Delete; + +use HTML::FormHandler::Moose; +extends 'HTML::FormHandler'; +use Moose::Util::TypeConstraints; + +use HTML::FormHandler::Widget::Block::Bootstrap; + +has '+widget_wrapper' => ( default => 'Bootstrap' ); +sub build_render_list {[qw/fields actions/]} +sub build_form_element_class { [qw/form-horizontal/] } + +has_field 'delete' => ( + type => 'Boolean', + label => 'Delete WAV', + required => 0, +); + +has_field 'save' => ( + type => 'Submit', + value => 'Save', + element_class => [qw/btn btn-primary/], + label => '', +); + +has_block 'fields' => ( + tag => 'div', + class => [qw/modal-body/], + render_list => [qw/delete/], +); + +has_block 'actions' => ( + tag => 'div', + class => [qw/modal-footer/], + render_list => [qw/save/], +); + +1; +# vim: set tabstop=4 expandtab: diff --git a/lib/NGCP/Panel/Form/Voicemail/Email.pm b/lib/NGCP/Panel/Form/Voicemail/Email.pm new file mode 100644 index 0000000000..73b10e93d2 --- /dev/null +++ b/lib/NGCP/Panel/Form/Voicemail/Email.pm @@ -0,0 +1,39 @@ +package NGCP::Panel::Form::Voicemail::Email; + +use HTML::FormHandler::Moose; +extends 'HTML::FormHandler'; +use Moose::Util::TypeConstraints; + +use HTML::FormHandler::Widget::Block::Bootstrap; + +has '+widget_wrapper' => ( default => 'Bootstrap' ); +sub build_render_list {[qw/fields actions/]} +sub build_form_element_class { [qw/form-horizontal/] } + +has_field 'email' => ( + type => 'Email', + label => 'Email', + required => 0, +); + +has_field 'save' => ( + type => 'Submit', + value => 'Save', + element_class => [qw/btn btn-primary/], + label => '', +); + +has_block 'fields' => ( + tag => 'div', + class => [qw/modal-body/], + render_list => [qw/email/], +); + +has_block 'actions' => ( + tag => 'div', + class => [qw/modal-footer/], + render_list => [qw/save/], +); + +1; +# vim: set tabstop=4 expandtab: diff --git a/lib/NGCP/Panel/Form/Voicemail/Pin.pm b/lib/NGCP/Panel/Form/Voicemail/Pin.pm new file mode 100644 index 0000000000..54d46d37dc --- /dev/null +++ b/lib/NGCP/Panel/Form/Voicemail/Pin.pm @@ -0,0 +1,39 @@ +package NGCP::Panel::Form::Voicemail::Pin; + +use HTML::FormHandler::Moose; +extends 'HTML::FormHandler'; +use Moose::Util::TypeConstraints; + +use HTML::FormHandler::Widget::Block::Bootstrap; + +has '+widget_wrapper' => ( default => 'Bootstrap' ); +sub build_render_list {[qw/fields actions/]} +sub build_form_element_class { [qw/form-horizontal/] } + +has_field 'pin' => ( + type => 'Text', + label => 'PIN', + required => 0, +); + +has_field 'save' => ( + type => 'Submit', + value => 'Save', + element_class => [qw/btn btn-primary/], + label => '', +); + +has_block 'fields' => ( + tag => 'div', + class => [qw/modal-body/], + render_list => [qw/pin/], +); + +has_block 'actions' => ( + tag => 'div', + class => [qw/modal-footer/], + render_list => [qw/save/], +); + +1; +# vim: set tabstop=4 expandtab: diff --git a/share/templates/subscriber/preferences.tt b/share/templates/subscriber/preferences.tt index f0f9a21c24..26568ab3a9 100644 --- a/share/templates/subscriber/preferences.tt +++ b/share/templates/subscriber/preferences.tt @@ -108,7 +108,7 @@
@@ -122,6 +122,77 @@ +| Name | +Value | + [% # one for actions -%] ++ |
|---|---|---|
| PIN | ++ [% subscriber.provisioning_voip_subscriber.voicemail_user.password %] + | +
+
+ Edit
+
+
+ |
+
| + [% subscriber.provisioning_voip_subscriber.voicemail_user.email %] + | +
+
+ Edit
+
+
+ |
+ |
| Delete after sending Email | ++ [% subscriber.provisioning_voip_subscriber.voicemail_user.get_column('delete') %] + | +
+
+ Edit
+
+
+ |
+
| Attach WAV in Email | ++ [% subscriber.provisioning_voip_subscriber.voicemail_user.attach %] + | +
+
+ Edit
+
+
+ |
+