Implement customer fraud levels.

agranig/1_0_subfix
Andreas Granig 12 years ago
parent 3b0119e603
commit f3f7f62868

@ -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

@ -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:

@ -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:

@ -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)" },
];
-%]
<div class="row">
<span>
<a class="btn btn-primary btn-large" href="[% c.uri_for() %]"><i class="icon-arrow-left"></i> Back</a>
@ -32,7 +42,7 @@
<td>testuser1@example.org</td>
<td>4312345</td>
<td>Fooagent 1/0 something very long in version 20130702 foooooooooo</td>
<td class="ngcp-actions-column"></th>
<td class="ngcp-actions-column"> </th>
</tr>
<tr>
<td>testuser2@example.org</td>
@ -89,22 +99,76 @@
</tr>
</thead>
<tbody>
<tr>
<tr class="sw_action_row">
<td>Monthly Settings</td>
<td>billing profile default</td>
<td>billing profile default</td>
<td>billing profile default</td>
<td class="ngcp-actions-column"></th>
[% fraud_def_message = (fraud.fraud_interval_limit.defined ? "none" : "billing profile default") %]
<td>[% fraud.fraud_interval_limit.defined ? fraud.fraud_interval_limit : fraud_def_message %]</td>
<td>
[% IF fraud.fraud_interval_lock.defined -%]
<select disabled="disabled">
[% FOR l IN lock_levels -%]
<option [% fraud.fraud_interval_lock == l.level ? 'selected="selected"' : '' %]>[% l.text %]</option>
[% END -%]
</select>
[% ELSE -%]
[% fraud_def_message %]
[% END -%]
</td>
<td>[% fraud.fraud_interval_notify.defined ? fraud.fraud_interval_notify : fraud_def_message %]</td>
<td class="ngcp-actions-column">
<div class="sw_actions pull-right">
<a class="btn btn-small btn-primary"
href="[% c.uri_for_action("/customer/edit_fraud", [c.req.captures.0], "month") %]">
<i class="icon-edit"></i> Edit</i>
</a>
<a class="btn btn-small btn-secondary" data-confirm="Delete"
href="[% c.uri_for_action("/customer/delete_fraud", [c.req.captures.0], "month") %]">
<i class="icon-trash"></i> Delete</i>
</a>
</div>
</td>
</tr>
<tr>
<tr class="sw_action_row">
<td>Daily Settings</td>
<td>billing profile default</td>
<td>billing profile default</td>
<td>billing profile default</td>
<td class="ngcp-actions-column"></th>
[% fraud_def_message = (fraud.fraud_daily_limit.defined ? "none" : "billing profile default") %]
<td>[% fraud.fraud_daily_limit.defined ? fraud.fraud_daily_limit : fraud_def_message %]</td>
<td>
[% IF fraud.fraud_daily_lock.defined -%]
<select disabled="disabled">
[% FOR l IN lock_levels -%]
<option [% fraud.fraud_daily_lock == l.level ? 'selected="selected"' : '' %]>[% l.text %]</option>
[% END -%]
</select>
[% ELSE -%]
[% fraud_def_message %]
[% END -%]
</td>
<td>[% fraud.fraud_daily_notify.defined ? fraud.fraud_daily_notify : fraud_def_message %]</td>
<td class="ngcp-actions-column">
<div class="sw_actions pull-right">
<a class="btn btn-small btn-primary"
href="[% c.uri_for_action("/customer/edit_fraud", [c.req.captures.0], "day") %]">
<i class="icon-edit"></i> Edit</i>
</a>
<a class="btn btn-small btn-secondary" data-confirm="Delete"
href="[% c.uri_for_action("/customer/delete_fraud", [c.req.captures.0], "day") %]">
<i class="icon-trash"></i> Delete</i>
</a>
</div>
</td>
</tr>
</tbody>
</table>
[% 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: -%]

Loading…
Cancel
Save