Implement subscriber creation.

agranig/1_0_subfix
Andreas Granig 13 years ago
parent 4b4c393c41
commit 394595cd48

@ -43,7 +43,7 @@ my $builder = Local::Module::Build->new(
'Moose::Util::TypeConstraints' => 0,
'MooseX::Object::Pluggable' => 0,
'namespace::autoclean' => 0,
'NGCP::Schema' => '1.003',
'NGCP::Schema' => '1.004',
'Scalar::Util' => 0,
'strict' => 0,
'Template' => 0,

@ -311,8 +311,8 @@ sub customer_ajax :Chained('customer_list') :PathPart('ajax') :Args(0) {
});
$c->forward( "/ajax_process_resultset", [$rs,
["id","contact_id", "billing_profile_id", "billing_profile_name","status"],
["billing_profile.name", "status"]]);
["id","contact_id", "external_id", "billing_profile_id", "billing_profile_name","status"],
["external_id", "billing_profile.name", "status"]]);
$c->detach( $c->view("JSON") );
}

@ -101,10 +101,6 @@ sub base :Chained('list_customer') :PathPart('') :CaptureArgs(1) {
sub details :Chained('base') :PathPart('details') :Args(0) {
my ($self, $c) = @_;
$c->stash(
subscribers => $c->stash->{contract}->voip_subscribers,
);
}
sub edit_fraud :Chained('base') :PathPart('fraud/edit') :Args(1) {

@ -4,6 +4,7 @@ use namespace::sweep;
BEGIN { extends 'Catalyst::Controller'; }
use NGCP::Panel::Utils::Contract;
use NGCP::Panel::Form::Subscriber;
use UUID;
use Data::Printer;
@ -25,17 +26,157 @@ sub auto :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) :AllowedRol
return 1;
}
sub master :Chained('/') :PathPart('subscriber') {
sub sub_list :Chained('/') :PathPart('subscriber') :CaptureArgs(0) {
my ($self, $c) = @_;
$c->stash(
template => 'subscriber/list.tt',
);
}
sub root :Chained('sub_list') :PathPart('') :Args(0) {
my ($self, $c) = @_;
}
sub create_list :Chained('sub_list') :PathPart('create') :Args(0) {
my ($self, $c) = @_;
my $form = NGCP::Panel::Form::Subscriber->new;
$form->process(
posted => ($c->request->method eq 'POST'),
params => $c->request->params,
action => $c->uri_for('/subscriber/create'),
);
return if NGCP::Panel::Utils::check_form_buttons(
c => $c,
form => $form,
fields => [qw/domain.create/],
back_uri => $c->uri_for('/subscriber/create'),
);
if($form->validated) {
# TODO: save subscriber
$c->log->debug(">>>>>>>>>>>>>>>>>>>>>>>>>> subscriber validated");
# TODO: use transaction
my $schema = $c->model('DB');
try {
$schema->txn_do(sub {
my ($uuid_bin, $uuid_string);
UUID::generate($uuid_bin);
UUID::unparse($uuid_bin, $uuid_string);
# TODO: check if we find a reseller and contract and domains
my $reseller = $c->model('DB')->resultset('resellers')
->find($c->request->params->{'reseller.id'});
my $contract = $c->model('DB')->resultset('contracts')
->find($c->request->params->{'contract.id'});
my $prov_domain = $c->model('DB')->resultset('voip_domains')
->find($c->request->params->{'domain.id'});
my $billing_domain = $c->model('DB')->resultset('domains')
->find({domain => $prov_domain->domain});
my $number;
if(defined $c->request->params->{'e164.cc'} && $c->request->params->{'e164.cc'} ne '') {
# TODO: must have sn set!
$number = $reseller->voip_numbers->create({
cc => $c->request->params->{'e164.cc'},
ac => $c->request->params->{'e164.ac'} || '',
sn => $c->request->params->{'e164.sn'} || '',
status => 'active',
});
}
my $billing_subscriber = $contract->voip_subscribers->create({
uuid => $uuid_string,
username => $c->request->params->{username},
domain_id => $billing_domain->id,
status => $c->request->params->{status},
primary_number_id => defined $number ? $number->id : undef,
});
if(defined $number) {
$number->update({ subscriber_id => $billing_subscriber->id });
}
$c->model('DB')->resultset('provisioning_voip_subscribers')->create({
uuid => $uuid_string,
username => $c->request->params->{username},
password => $c->request->params->{password},
webusername => $c->request->params->{webusername},
webpassword => $c->request->params->{webpassword},
admin => $c->request->params->{administrative} || 0,
account_id => $contract->id,
domain_id => $prov_domain->id,
});
});
$c->flash(messages => [{type => 'success', text => 'Subscriber successfully created!'}]);
$c->response->redirect($c->uri_for('/subscriber'));
return;
} catch($e) {
$c->log->error("Failed to create subscriber: $e");
$c->flash(messages => [{type => 'error', text => 'Creating subscriber failed!'}]);
$c->response->redirect($c->uri_for('/subscriber'));
return;
}
}
$c->log->debug(">>>>>>>>>>>>>>>>>>>>>>>>>> subscriber NOT validated");
$c->stash(close_target => $c->uri_for());
$c->stash(create_flag => 1);
$c->stash(form => $form)
}
sub base :Chained('/subscriber/sub_list') :PathPart('') :CaptureArgs(1) {
my ($self, $c, $subscriber_id) = @_;
unless($subscriber_id && $subscriber_id->is_integer) {
$c->flash(messages => [{type => 'error', text => 'Invalid subscriber id detected!'}]);
$c->response->redirect($c->uri_for());
return;
}
my $res = $c->model('DB')->resultset('voip_subscribers')->find($subscriber_id);
unless(defined($res)) {
$c->flash(messages => [{type => 'error', text => 'Subscriber does not exist!'}]);
$c->response->redirect($c->uri_for());
return;
}
$c->stash(subscriber => {$res->get_columns});
$c->stash(subscriber_result => $res);
}
sub ajax :Chained('sub_list') :PathPart('ajax') :Args(0) {
my ($self, $c) = @_;
my $dispatch_to = '_ajax_resultset_' . $c->user->auth_realm;
my $resultset = $self->$dispatch_to($c);
$c->forward( "/ajax_process_resultset", [$resultset,
["id", "username", "domain_id"],
["username", "domain_id"]]);
$c->detach( $c->view("JSON") );
}
sub _ajax_resultset_admin {
my ($self, $c) = @_;
return $c->model('DB')->resultset('voip_subscribers');
}
sub _ajax_resultset_reseller {
my ($self, $c) = @_;
# TODO: filter for reseller
return $c->model('DB')->resultset('voip_subscribers');
}
sub master :Chained('/') :PathPart('subscriber') :Args(1) {
my ($self, $c, $subscriber_id) = @_;
$c->stash(
template => 'subscriber/master.tt',
edit_flag => 1,
form => NGCP::Panel::Form::Subscriber->new,
);
}
=head1 AUTHOR
Andreas Granig,,,

@ -0,0 +1,26 @@
package NGCP::Panel::Field::CustomerContract;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler::Field::Compound';
has_field 'id' => (
type => '+NGCP::Panel::Field::DataTable',
label => 'Customer',
do_label => 0,
do_wrapper => 0,
required => 1,
template => 'share/templates/helpers/datatables_field.tt',
ajax_src => '/contract/customer/ajax',
table_titles => ['#', 'Contact #', 'External #', 'Status'],
table_fields => ['id', 'contact_id', 'external_id', 'status'],
);
has_field 'create' => (
type => 'Button',
do_label => 0,
value => 'Create Contract',
element_class => [qw/btn btn-tertiary pull-right/],
);
1;
# vim: set tabstop=4 expandtab:

@ -0,0 +1,18 @@
package NGCP::Panel::Field::NumberStatusSelect;
use Moose;
extends 'HTML::FormHandler::Field::Select';
sub build_options {
my ($self) = @_;
return [
{ label => 'active', value => 'active' },
{ label => 'reserved', value => 'reserved' },
{ label => 'locked', value => 'locked' },
{ label => 'deported', value => 'deported' },
];
}
1;
# vim: set tabstop=4 expandtab:

@ -0,0 +1,17 @@
package NGCP::Panel::Field::SubscriberStatusSelect;
use Moose;
extends 'HTML::FormHandler::Field::Select';
sub build_options {
my ($self) = @_;
return [
{ label => 'active', value => 'active' },
{ label => 'locked', value => 'locked' },
{ label => 'terminated', value => 'terminated' },
];
}
1;
# vim: set tabstop=4 expandtab:

@ -7,14 +7,29 @@ use Moose::Util::TypeConstraints;
use HTML::FormHandler::Widget::Block::Bootstrap;
use NGCP::Panel::Field::Domain;
use NGCP::Panel::Field::CustomerContract;
use NGCP::Panel::Field::Reseller;
has '+widget_wrapper' => ( default => 'Bootstrap' );
sub build_render_list {[qw/fields actions/]}
sub build_form_element_class { [qw/form-horizontal/] }
has_field 'reseller' => (
type => '+NGCP::Panel::Field::Reseller',
label => 'Reseller',
not_nullable => 1,
);
has_field 'contract' => (
type => '+NGCP::Panel::Field::CustomerContract',
label => 'Customer',
not_nullable => 1,
);
has_field 'webusername' => (
type => 'Text',
label => 'Web Username',
required => 0,
element_attr => {
rel => ['tooltip'],
title => ['The username to log into the CSC Panel']
@ -24,6 +39,7 @@ has_field 'webusername' => (
has_field 'webpassword' => (
type => 'Password',
label => 'Web Password',
required => 0,
element_attr => {
rel => ['tooltip'],
title => ['The password to log into the CSC Panel']
@ -33,6 +49,7 @@ has_field 'webpassword' => (
has_field 'e164' => (
type => 'Compound',
order => 99,
required => 0,
label => 'E164 Number',
do_label => 1,
do_wrapper => 1,
@ -74,9 +91,10 @@ has_field 'e164.sn' => (
do_wrapper => 0,
);
has_field 'sipusername' => (
has_field 'username' => (
type => 'Text',
label => 'SIP Username',
required => 1,
noupdate => 1,
element_attr => {
rel => ['tooltip'],
@ -84,24 +102,32 @@ has_field 'sipusername' => (
},
);
has_field 'sipdomain' => (
has_field 'domain' => (
type => '+NGCP::Panel::Field::Domain',
label => 'SIP Domain',
not_nullable => 1,
);
has_field 'sippassword' => (
has_field 'password' => (
type => 'Password',
label => 'SIP Password',
required => 1,
element_attr => {
rel => ['tooltip'],
title => ['The SIP password for the User-Agents']
},
);
has_field 'status' => (
type => '+NGCP::Panel::Field::SubscriberStatusSelect',
label => 'Status',
not_nullable => 1,
);
has_field 'administrative' => (
type => 'Boolean',
label => 'Administrative',
required => 0,
element_attr => {
rel => ['tooltip'],
title => ['Subscriber can configure other subscribers within the Customer Account']
@ -112,6 +138,7 @@ has_field 'administrative' => (
has_field 'external_id' => (
type => 'Text',
label => 'External ID',
required => 0,
element_attr => {
rel => ['tooltip'],
title => ['An external id, e.g. provided by a 3rd party provisioning']
@ -130,7 +157,7 @@ has_field 'save' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/webusername webpassword e164 sipusername sipdomain sippassword external_id administrative/ ],
render_list => [qw/reseller contract webusername webpassword e164 username domain password status external_id administrative/ ],
);
has_block 'actions' => (

@ -40,11 +40,11 @@
</tr>
</thead>
<tbody>
[% FOR subscriber IN subscribers -%]
[% FOR subscriber IN contract.voip_subscribers -%]
<tr>
<td>[% subscriber.username %]@[% subscriber.domain.domain %]</td>
<td>[% subscriber.primary_number.cc %] [% subscriber.primary_number.ac %] [% subscriber.primary_number.sn %]</td>
<td>TODO[% # subscriber.provisioning_voip_subscriber.password %]</td>
<td>[% subscriber.provisioning_voip_subscriber.password %]</td>
<td class="ngcp-actions-column"></td>
</tr>
[% END -%]

@ -1,7 +1,6 @@
[% META title = 'Domains' -%]
[%
helper.name = 'Domain';
helper.show_create_button = 1;
helper.data = domains;
helper.messages = messages;
helper.column_titles = [ '#', 'Domain' ];

@ -0,0 +1,25 @@
[% META title = 'Subscribers' -%]
[%
helper.name = 'Subscriber';
helper.data = subscribers;
helper.messages = messages;
helper.column_titles = [ '#', 'Username', 'Domain #' ];
helper.column_fields = [ 'id', 'username', 'domain_id' ];
helper.close_target = close_target;
helper.create_flag = create_flag;
helper.edit_flag = edit_flag;
helper.form_object = form;
helper.ajax_uri = c.uri_for( c.controller.action_for('ajax') );
helper.dt_buttons = [
{ name = 'Delete', uri = "/subscriber/'+full[\"id\"]+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' },
{ name = 'Preferences', uri = "/subscriber/'+full[\"id\"]+'/preferences", class = 'btn-small btn-tertiary', icon = 'icon-list' },
];
helper.top_buttons = [
{ name = 'Create Subscriber', uri = c.uri_for_action('/subscriber/create_list'), icon = 'icon-star' },
];
PROCESS 'helpers/datatables.tt';
-%]
[% # vim: set tabstop=4 syntax=html expandtab: -%]
Loading…
Cancel
Save