diff --git a/lib/NGCP/Panel/Controller/Customer.pm b/lib/NGCP/Panel/Controller/Customer.pm index e399c4ea9f..10621adeba 100644 --- a/lib/NGCP/Panel/Controller/Customer.pm +++ b/lib/NGCP/Panel/Controller/Customer.pm @@ -3,6 +3,8 @@ use Sipwise::Base; use namespace::sweep; BEGIN { extends 'Catalyst::Controller'; } use NGCP::Panel::Form::Customer; +use NGCP::Panel::Form::CustomerMonthlyFraud; +use NGCP::Panel::Form::CustomerDailyFraud; use NGCP::Panel::Utils; use Data::Printer; @@ -50,13 +52,81 @@ sub base :Chained('list_customer') :PathPart('') :CaptureArgs(1) { my $contract = $c->model('billing')->resultset('contracts') ->find($contract_id); + $c->stash(fraud => $contract->contract_fraud_preference); + $c->stash(template => 'customer/details.tt'); $c->stash(contract => $contract); } sub details :Chained('base') :PathPart('details') :Args(0) { my ($self, $c) = @_; +} - $c->stash(template => 'customer/details.tt'); +sub edit_fraud :Chained('base') :PathPart('fraud/edit') :Args(1) { + my ($self, $c, $type) = @_; + + my $posted = ($c->request->method eq 'POST'); + my $form; + if($type eq "month") { + $form = NGCP::Panel::Form::CustomerMonthlyFraud->new; + } elsif($type eq "day") { + $form = NGCP::Panel::Form::CustomerDailyFraud->new; + } else { + $c->flash(messages => [{type => 'error', text => "Invalid fraud interval '$type'!"}]); + $c->response->redirect($c->uri_for_action("/customer/details", [$c->stash->{contract}->id])); + return; + } + + my $fraud_prefs = $c->stash->{fraud} || + $c->model('billing')->resultset('contract_fraud_preferences') + ->new_result({ contract_id => $c->stash->{contract}->id}); + $form->process( + posted => $posted, + params => $c->request->params, + action => $c->uri_for_action("/customer/edit_fraud", $c->stash->{contract}->id, $type), + item => $fraud_prefs, + ); + if($posted && $form->validated) { + $c->flash(messages => [{type => 'success', text => 'Fraud settings successfully changed!'}]); + $c->response->redirect($c->uri_for_action("/customer/details", [$c->stash->{contract}->id])); + return; + } + + $c->stash(close_target => $c->uri_for_action("/customer/details", [$c->stash->{contract}->id])); + $c->stash(form => $form); + $c->stash(edit_flag => 1); +} + +sub delete_fraud :Chained('base') :PathPart('fraud/delete') :Args(1) { + my ($self, $c, $type) = @_; + + if($type eq "month") { + $type = "interval"; + } elsif($type eq "day") { + $type = "daily"; + } else { + $c->flash(messages => [{type => 'error', text => "Invalid fraud interval '$type'!"}]); + $c->response->redirect($c->uri_for_action("/customer/details", [$c->stash->{contract}->id])); + return; + } + + my $fraud_prefs = $c->stash->{fraud}; + if($fraud_prefs) { + try { + $fraud_prefs->update({ + "fraud_".$type."_limit" => undef, + "fraud_".$type."_lock" => undef, + "fraud_".$type."_notify" => undef, + }); + } catch($e) { + $c->log->error("Failed to clear fraud interval: $e"); + $c->flash(messages => [{type => 'error', text => "Failed to clear fraud interval!"}]); + $c->response->redirect($c->uri_for_action("/customer/details", [$c->stash->{contract}->id])); + return; + } + } + $c->flash(messages => [{type => 'success', text => "Successfully cleared fraud interval!"}]); + $c->response->redirect($c->uri_for_action("/customer/details", [$c->stash->{contract}->id])); + return; } =head1 AUTHOR diff --git a/lib/NGCP/Panel/Form/CustomerDailyFraud.pm b/lib/NGCP/Panel/Form/CustomerDailyFraud.pm new file mode 100644 index 0000000000..c681163a8a --- /dev/null +++ b/lib/NGCP/Panel/Form/CustomerDailyFraud.pm @@ -0,0 +1,79 @@ +package NGCP::Panel::Form::CustomerDailyFraud; + +use HTML::FormHandler::Moose; +extends 'HTML::FormHandler::Model::DBIC'; +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 'fraud_daily_limit' => ( + type => 'Integer', + label => 'Daily Fraud Limit', + required => 1, +); + +has_field 'fraud_daily_lock' => ( + type => 'Select', + label => 'Lock Level', + options => [ + { value => 0, label => 'none' }, + { value => 1, label => 'foreign calls' }, + { value => 2, label => 'all outgoing calls' }, + { value => 3, label => 'incoming and outgoing' }, + { value => 4, label => 'global (including CSC)' }, + ], +); + +has_field 'fraud_daily_notify' => ( + type => '+NGCP::Panel::Field::EmailList', + label => 'Notify Emails', + maxlength => 255, +); + +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/fraud_daily_limit fraud_daily_lock fraud_daily_notify/], +); + +has_block 'actions' => ( + tag => 'div', + class => [qw/modal-footer/], + render_list => [qw/save/], +); + +1; + +=head1 NAME + +NGCP::Panel::Form::NCOSPattern + +=head1 DESCRIPTION + +Form to modify a billing.ncos_pattern_list row. + +=head1 METHODS + +=head1 AUTHOR + +Gerhard Jungwirth + +=head1 LICENSE + +This library is free software. You can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +# vim: set tabstop=4 expandtab: diff --git a/lib/NGCP/Panel/Form/CustomerMonthlyFraud.pm b/lib/NGCP/Panel/Form/CustomerMonthlyFraud.pm new file mode 100644 index 0000000000..946c649201 --- /dev/null +++ b/lib/NGCP/Panel/Form/CustomerMonthlyFraud.pm @@ -0,0 +1,79 @@ +package NGCP::Panel::Form::CustomerMonthlyFraud; + +use HTML::FormHandler::Moose; +extends 'HTML::FormHandler::Model::DBIC'; +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 'fraud_interval_limit' => ( + type => 'Integer', + label => 'Monthly Fraud Limit', + required => 1, +); + +has_field 'fraud_interval_lock' => ( + type => 'Select', + label => 'Lock Level', + options => [ + { value => 0, label => 'none' }, + { value => 1, label => 'foreign calls' }, + { value => 2, label => 'all outgoing calls' }, + { value => 3, label => 'incoming and outgoing' }, + { value => 4, label => 'global (including CSC)' }, + ], +); + +has_field 'fraud_interval_notify' => ( + type => '+NGCP::Panel::Field::EmailList', + label => 'Notify Emails', + maxlength => 255, +); + +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/fraud_interval_limit fraud_interval_lock fraud_interval_notify/], +); + +has_block 'actions' => ( + tag => 'div', + class => [qw/modal-footer/], + render_list => [qw/save/], +); + +1; + +=head1 NAME + +NGCP::Panel::Form::NCOSPattern + +=head1 DESCRIPTION + +Form to modify a billing.ncos_pattern_list row. + +=head1 METHODS + +=head1 AUTHOR + +Gerhard Jungwirth + +=head1 LICENSE + +This library is free software. You can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +# vim: set tabstop=4 expandtab: diff --git a/share/templates/customer/details.tt b/share/templates/customer/details.tt index dba610b1bb..7ab874440f 100644 --- a/share/templates/customer/details.tt +++ b/share/templates/customer/details.tt @@ -1,5 +1,15 @@ [% site_config.title = 'Account Details' -%] +[% + lock_levels = [ + { level = 0, text = "none" }, + { level = 1, text = "foreign calls" }, + { level = 2, text = "all outgoing calls" }, + { level = 3, text = "incoming and outgoing" }, + { level = 4, text = "global (including web login)" }, + ]; +-%] +
Back @@ -32,7 +42,7 @@ testuser1@example.org 4312345 Fooagent 1/0 something very long in version 20130702 foooooooooo - + testuser2@example.org @@ -89,22 +99,76 @@ - + Monthly Settings - billing profile default - billing profile default - billing profile default - + [% fraud_def_message = (fraud.fraud_interval_limit.defined ? "none" : "billing profile default") %] + [% fraud.fraud_interval_limit.defined ? fraud.fraud_interval_limit : fraud_def_message %] + + [% IF fraud.fraud_interval_lock.defined -%] + + [% ELSE -%] + [% fraud_def_message %] + [% END -%] + + [% fraud.fraud_interval_notify.defined ? fraud.fraud_interval_notify : fraud_def_message %] + + + - + Daily Settings - billing profile default - billing profile default - billing profile default - + [% fraud_def_message = (fraud.fraud_daily_limit.defined ? "none" : "billing profile default") %] + [% fraud.fraud_daily_limit.defined ? fraud.fraud_daily_limit : fraud_def_message %] + + [% IF fraud.fraud_daily_lock.defined -%] + + [% ELSE -%] + [% fraud_def_message %] + [% END -%] + + [% fraud.fraud_daily_notify.defined ? fraud.fraud_daily_notify : fraud_def_message %] + + + +[% IF edit_flag == 1 -%] +[% + PROCESS "helpers/modal.tt"; + modal_header(m.create_flag=0, + m.name = "Fraud Settings"); + form.render; + modal_footer(); + modal_script(m.close_target = close_target); +-%] +[% END -%] [% # vim: set tabstop=4 syntax=html expandtab: -%]