MT#6693 More subscriber editing rework.

- Update base cli of extensions on pbx admin primary number change.
- Use proper forms (hopefully) for editing various pbx subscriber types.
agranig/subprof
Andreas Granig 11 years ago
parent 16b44673f4
commit 9aead3f255

@ -17,6 +17,7 @@ use NGCP::Panel::Utils::Sems;
use NGCP::Panel::Utils::Hylafax;
use NGCP::Panel::Form::Subscriber;
use NGCP::Panel::Form::SubscriberEdit;
use NGCP::Panel::Form::Customer::PbxSubscriberEdit;
use NGCP::Panel::Form::Customer::PbxExtensionSubscriberEdit;
use NGCP::Panel::Form::Customer::PbxExtensionSubscriberEditAdmin;
use NGCP::Panel::Form::Customer::PbxExtensionSubscriberEditSubadmin;
@ -1765,6 +1766,24 @@ sub master :Chained('base') :PathPart('details') :CaptureArgs(0) {
attribute => 'lock',
prov_subscriber => $c->stash->{subscriber}->provisioning_voip_subscriber,
);
$c->stash->{contract} = $c->stash->{subscriber}->contract;
$c->stash->{subscribers} = $c->model('DB')->resultset('voip_subscribers')->search({
contract_id => $c->stash->{contract}->id,
status => { '!=' => 'terminated' },
'provisioning_voip_subscriber.is_pbx_group' => 0,
}, {
join => 'provisioning_voip_subscriber',
});
if($c->config->{features}->{cloudpbx}) {
$c->stash->{pbx_groups} = $c->model('DB')->resultset('voip_subscribers')->search({
contract_id => $c->stash->{contract}->id,
status => { '!=' => 'terminated' },
'provisioning_voip_subscriber.is_pbx_group' => 1,
}, {
join => 'provisioning_voip_subscriber',
});
}
}
sub details :Chained('master') :PathPart('') :Args(0) :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) :AllowedRole(reseller) :AllowedRole('subscriberadmin') {
@ -1814,15 +1833,25 @@ sub edit_master :Chained('master') :PathPart('edit') :Args(0) :Does(ACL) :ACLDet
my $form; my $pbx_ext; my $is_admin; my $subadmin_pbx;
if ($c->config->{features}->{cloudpbx} && $prov_subscriber->voip_pbx_group) {
if ($c->config->{features}->{cloudpbx}) {
$c->stash(customer_id => $subscriber->contract->id);
$pbx_ext = 1;
if($c->user->roles eq 'subscriberadmin') {
$subadmin_pbx = 1;
$form = NGCP::Panel::Form::Customer::PbxExtensionSubscriberEditSubadmin->new(ctx => $c);
if($subscriber->provisioning_voip_subscriber->admin) {
if($c->user->roles eq 'subscriberadmin') {
$subadmin_pbx = 1;
$form = NGCP::Panel::Form::Customer::PbxExtensionSubscriberEditSubadmin->new(ctx => $c);
} else {
$is_admin = 1;
$form = NGCP::Panel::Form::Customer::PbxSubscriberEdit->new(ctx => $c);
}
} else {
$is_admin = 1;
$form = NGCP::Panel::Form::Customer::PbxExtensionSubscriberEditAdmin->new(ctx => $c);
if($c->user->roles eq 'subscriberadmin') {
$subadmin_pbx = 1;
$form = NGCP::Panel::Form::Customer::PbxExtensionSubscriberEdit->new(ctx => $c);
} else {
$is_admin = 1;
$form = NGCP::Panel::Form::Customer::PbxExtensionSubscriberEditAdmin->new(ctx => $c);
}
$pbx_ext = 1;
}
} else {
if($c->user->roles eq 'subscriberadmin') {
@ -1841,15 +1870,12 @@ sub edit_master :Chained('master') :PathPart('edit') :Args(0) :Does(ACL) :ACLDet
my $lock = $c->stash->{prov_lock};
my $base_number;
if($pbx_ext) {
my $subs = NGCP::Panel::Utils::Subscriber::get_custom_subscriber_struct(
c => $c,
contract => $subscriber->contract,
show_locked => 0,
);
my $admin_subscribers = NGCP::Panel::Utils::Subscriber::get_admin_subscribers(
voip_subscribers => $subs->{subscribers}
);
$base_number = $admin_subscribers->[0]->{primary_number};
say ">>>>>>>>>>>>> check admin subscriber";
my $admin_subscribers = $c->stash->{subscribers}->search({
'provisioning_voip_subscriber.admin' => 1,
});
$c->stash->{admin_subscriber} = $admin_subscribers->first;
$base_number = $c->stash->{admin_subscriber}->primary_number;
}
# we don't change this on edit
@ -1864,30 +1890,31 @@ sub edit_master :Chained('master') :PathPart('edit') :Args(0) :Does(ACL) :ACLDet
$params->{profile}{id} = $prov_subscriber->voip_subscriber_profile ?
$prov_subscriber->voip_subscriber_profile->id : undef;
$params->{webusername} = $prov_subscriber->webusername;
$params->{webpassword} = $prov_subscriber->webpassword;
$params->{password} = $prov_subscriber->password;
$params->{administrative} = $prov_subscriber->admin;
say ">>>>>>>>>>>>> check primary number";
if($subscriber->primary_number) {
$params->{e164}->{cc} = $subscriber->primary_number->cc;
$params->{e164}->{ac} = $subscriber->primary_number->ac;
$params->{e164}->{sn} = $subscriber->primary_number->sn;
if($base_number && $pbx_ext) {
my $pbx_base_num = $base_number->{cc} .
($base_number->{ac} // '').
$base_number->{sn};
my $full = $subscriber->primary_number->cc .
($subscriber->primary_number->ac // '').
$subscriber->primary_number->sn;
if($full =~ s/^${pbx_base_num}(.+)$/$1/) {
$params->{extension} = $full;
}
}
}
if(defined $prov_subscriber->pbx_extension) {
$params->{pbx_extension} = $prov_subscriber->pbx_extension;
}
if($pbx_ext) {
$params->{group}{id} = $prov_subscriber->pbx_group_id;
# TODO: rework to store ext in sub
#$params->{extension} = $prov_subscriber->pbx_group_id;
}
=pod
my $display_pref = NGCP::Panel::Utils::Preferences::get_usr_preference_rs(
c => $c, attribute => 'display_name', prov_subscriber => $prov_subscriber);
if($display_pref->first) {
$params->{display_name} = $display_pref->first->value;
}
=cut
my @alias_options = ();
my @alias_nums = ();
my $num_rs = $c->model('DB')->resultset('voip_numbers')->search_rs({
@ -1935,13 +1962,17 @@ sub edit_master :Chained('master') :PathPart('edit') :Args(0) :Does(ACL) :ACLDet
try {
$schema->txn_do(sub {
my $prov_params = {};
$prov_params->{pbx_extension} = $form->params->{pbx_extension};
$prov_params->{webusername} = $form->params->{webusername};
$prov_params->{webpassword} = $form->params->{webpassword}
if($form->params->{webpassword});
$prov_params->{password} = $form->params->{password}
if($form->params->{password});
$prov_params->{admin} = $form->params->{administrative} // 0
if($is_admin);
if($is_admin) {
if(exists $form->params->{administrative}) {
$prov_params->{admin} = $form->params->{administrative} // 0;
}
}
$prov_params->{pbx_group_id} = $form->params->{group}{id}
if($pbx_ext);
my $old_group_id = $prov_subscriber->pbx_group_id;
@ -2057,10 +2088,15 @@ sub edit_master :Chained('master') :PathPart('edit') :Args(0) :Does(ACL) :ACLDet
}
if($subscriber->primary_number) {
my $old_number = {
cc => $subscriber->primary_number->cc,
ac => $subscriber->primary_number->ac,
sn => $subscriber->primary_number->sn,
};
if($pbx_ext) {
$form->params->{e164}{cc} = $subscriber->primary_number->cc;
$form->params->{e164}{ac} = $subscriber->primary_number->ac;
$form->params->{e164}{sn} = $base_number->{sn} . $form->params->{extension};
$form->params->{e164}{sn} = $base_number->sn . $form->params->{pbx_extension};
}
NGCP::Panel::Utils::Subscriber::update_subscriber_numbers(
@ -2070,6 +2106,49 @@ sub edit_master :Chained('master') :PathPart('edit') :Args(0) :Does(ACL) :ACLDet
primary_number => $form->params->{e164},
$subadmin_pbx ? () : (alias_numbers => $form->values->{alias_number}),
);
# update the primary number and the cloud_pbx_base_cli pref for all other subscribers
# if the primary number of the admin changed
$subscriber->discard_changes; # reload row because of potential new number
my $new_number = {
cc => $subscriber->primary_number->cc,
ac => $subscriber->primary_number->ac,
sn => $subscriber->primary_number->sn,
};
if($subscriber->provisioning_voip_subscriber->admin &&
!is_deeply($old_number, $new_number)) {
foreach my $sub($c->stash->{subscribers}->all, $c->stash->{pbx_groups}->all) {
my $base_pref = NGCP::Panel::Utils::Preferences::get_usr_preference_rs(
c => $c, attribute => 'cloud_pbx_base_cli',
prov_subscriber => $sub->provisioning_voip_subscriber);
my $val = $form->params->{e164}{cc} .
($form->params->{e164}{ac} // '') .
$form->params->{e164}{sn};
if($base_pref->first) {
$base_pref->first->update({ value => $val });
} else {
$base_pref->create({ value => $val });
}
if($sub->id == $subscriber->id) {
next;
}
unless(defined $sub->provisioning_voip_subscriber->pbx_extension) {
next;
}
my $num = {
cc => $form->params->{e164}{cc},
ac => $form->params->{e164}{ac},
sn => $form->params->{e164}{sn} . $sub->provisioning_voip_subscriber->pbx_extension,
};
NGCP::Panel::Utils::Subscriber::update_subscriber_numbers(
schema => $schema,
subscriber_id => $sub->id,
reseller_id => $sub->contract->contact->reseller_id,
primary_number => $num,
);
}
}
} else {
NGCP::Panel::Utils::Subscriber::update_subscriber_numbers(
schema => $schema,

@ -31,6 +31,8 @@ sub field_list {
my $c = $self->ctx;
return unless $c;
print "+++++++++++++++++++++++++++++ PbxExtensionSubscribert field_list\n";
my $group = $self->field('group');
$group->field('id')->ajax_src(
$c->uri_for_action('/customer/pbx_group_ajax', [$c->stash->{customer_id}])->as_string
@ -38,7 +40,7 @@ sub field_list {
if($c->stash->{admin_subscriber}) {
my $profile_set = $c->stash->{admin_subscriber}->provisioning_voip_subscriber->voip_subscriber_profile_set;
if($profile_set) {
if($profile_set && $self->field('profile')) {
$self->field('profile')->field('id')->ajax_src(
$c->uri_for_action('/subscriberprofile/profile_ajax', [$profile_set->id])->as_string
);

@ -10,7 +10,7 @@ has_field 'group' => (
validate_when_empty => 1,
);
has_field 'extension' => (
has_field 'pbx_extension' => (
type => '+NGCP::Panel::Field::PosInteger',
element_attr => {
rel => ['tooltip'],
@ -23,7 +23,7 @@ has_field 'extension' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/group extension display_name webusername webpassword password status external_id profile_set/ ],
render_list => [qw/group pbx_extension webusername webpassword password status external_id profile/ ],
);
sub update_fields {
@ -32,6 +32,8 @@ sub update_fields {
my $pkg = __PACKAGE__;
$c->log->debug("my form: $pkg");
print "+++++++++++++++++++++++++++++ PbxExtensionSubscriberEdit update_fields\n";
my $group = $self->field('group');
$group->field('id')->ajax_src(
$c->uri_for_action('/customer/pbx_group_ajax', [$c->stash->{customer_id}])->as_string

@ -27,7 +27,7 @@ has_field 'alias_number_add' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/group extension alias_number alias_number_add display_name webusername webpassword password status external_id profile_set profile/ ],
render_list => [qw/group pbx_extension alias_number alias_number_add webusername webpassword password status external_id profile/ ],
);
sub field_list {
@ -36,17 +36,23 @@ sub field_list {
my $c = $self->ctx;
return unless($c);
print "+++++++++++++++++++++++++++++ PbxExtensionSubscriberEditAdmin field_list\n";
my $profile_set = $self->field('profile_set');
$profile_set->field('id')->ajax_src(
$c->uri_for_action('/subscriberprofile/set_ajax_reseller', [$c->stash->{subscriber}->contract->contact->reseller_id])->as_string
);
if($profile_set) {
$profile_set->field('id')->ajax_src(
$c->uri_for_action('/subscriberprofile/set_ajax_reseller', [$c->stash->{subscriber}->contract->contact->reseller_id])->as_string
);
}
my $set_id = $c->stash->{subscriber}->provisioning_voip_subscriber->profile_set_id;
if($set_id) {
my $profile = $self->field('profile');
$profile->field('id')->ajax_src(
$c->uri_for_action('/subscriberprofile/profile_ajax', [$set_id])->as_string
);
if($profile) {
$profile->field('id')->ajax_src(
$c->uri_for_action('/subscriberprofile/profile_ajax', [$set_id])->as_string
);
}
}
}

@ -19,7 +19,7 @@ has_field 'alias_select' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/group extension display_name webusername webpassword password alias_select profile/ ],
render_list => [qw/group pbx_extension webusername webpassword password alias_select profile/ ],
);
sub update_fields {

@ -19,7 +19,7 @@ has_field 'alias_select' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/display_name webusername webpassword password external_id alias_select profile/ ],
render_list => [qw/webusername webpassword password external_id alias_select profile/ ],
);
sub update_fields {

@ -10,7 +10,7 @@ has_field 'group' => (
validate_when_empty => 1,
);
has_field 'extension' => (
has_field 'pbx_extension' => (
type => '+NGCP::Panel::Field::PosInteger',
element_attr => {
rel => ['tooltip'],
@ -23,7 +23,7 @@ has_field 'extension' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/group extension display_name webusername webpassword username password status profile/ ],
render_list => [qw/group pbx_extension display_name webusername webpassword username password status profile/ ],
);
sub field_list {

@ -13,6 +13,19 @@ has_field 'submitid' => ( type => 'Hidden' );
sub build_render_list {[qw/submitid fields actions/]}
sub build_form_element_class { [qw/form-horizontal/] }
has_field 'e164' => (
type => '+NGCP::Panel::Field::E164',
order => 99,
required => 0,
label => 'E164 Number',
do_label => 1,
do_wrapper => 1,
element_attr => {
rel => ['tooltip'],
title => ['The main E.164 number (containing a cc, ac and sn attribute) used for inbound and outbound calls.']
},
);
has_field 'display_name' => (
type => 'Text',
element_attr => {
@ -113,7 +126,7 @@ has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
#render_list => [qw/display_name webusername webpassword username password status external_id profile_set profile/ ],
render_list => [qw/display_name webusername webpassword username password status profile_set profile/ ],
render_list => [qw/e164 display_name webusername webpassword username password status profile_set profile/ ],
);
has_block 'actions' => (
@ -122,6 +135,23 @@ has_block 'actions' => (
render_list => [qw/save/],
);
sub field_list {
my ($self) = @_;
my $c = $self->ctx;
return unless($c);
print "++++++++++++++++++++++++++++++++++++++++ PbxSubscriber field_list\n";
my $profile_set = $self->field('profile_set');
if($profile_set) {
$profile_set->field('id')->ajax_src(
$c->uri_for_action('/subscriberprofile/set_ajax_reseller', [$c->stash->{contract}->contact->reseller_id])->as_string
);
}
}
1;
=head1 NAME

@ -0,0 +1,87 @@
package NGCP::Panel::Form::Customer::PbxSubscriberEdit;
use HTML::FormHandler::Moose;
extends 'NGCP::Panel::Form::Customer::PbxSubscriber';
use Moose::Util::TypeConstraints;
use HTML::FormHandler::Widget::Block::Bootstrap;
use NGCP::Panel::Field::PbxGroup;
has '+widget_wrapper' => ( default => 'Bootstrap' );
has_field 'submitid' => ( type => 'Hidden' );
sub build_render_list {[qw/submitid fields actions/]}
sub build_form_element_class { [qw/form-horizontal/] }
has_field 'alias_number' => (
type => '+NGCP::Panel::Field::AliasNumber',
setup_for_js => 1,
do_wrapper => 1,
do_label => 0,
tags => {
controls_div => 1,
},
wrapper_class => [qw/hfh-rep/],
);
has_field 'alias_number_add' => (
type => 'AddElement',
repeatable => 'alias_number',
value => 'Add another number',
element_class => [qw/btn btn-primary pull-right/],
);
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/e164 alias_number alias_number_add webusername webpassword password status profile_set profile/ ],
);
has_block 'actions' => (
tag => 'div',
class => [qw/modal-footer/],
render_list => [qw/save/],
);
sub update_fields {
my ($self) = @_;
my $c = $self->ctx;
return unless($c);
my $set_id = $c->stash->{subscriber}->provisioning_voip_subscriber->profile_set_id;
if($set_id) {
my $profile = $self->field('profile');
if($profile) {
$profile->field('id')->ajax_src(
$c->uri_for_action('/subscriberprofile/profile_ajax', [$set_id])->as_string
);
}
}
}
1;
=head1 NAME
NGCP::Panel::Form::Subscriber
=head1 DESCRIPTION
Form to modify a subscriber.
=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:

@ -205,6 +205,8 @@ sub create_subscriber {
is_pbx_group => $params->{is_pbx_group} // 0,
pbx_group_id => $params->{pbx_group_id},
pbx_extension => $params->{pbx_extension},
pbx_hunt_policy => $params->{pbx_hunt_policy},
pbx_hunt_timeout => $params->{pbx_hunt_timeout},
profile_set_id => $profile_set ? $profile_set->id : undef,
profile_id => $profile ? $profile->id : undef,
create_timestamp => NGCP::Panel::Utils::DateTime::current_local,

@ -41,7 +41,7 @@
<div class="accordion-inner">
[% UNLESS (c.user.roles == "admin" || c.user.roles == "reseller") && c.user.read_only -%]
<a class="btn btn-tertiary btn-large" href="[% c.uri_for_action('/subscriber/edit_master', [ subscriber.id ]) %]"><i class="icon-edit"></i> [% c.loc('Edit') %]</a>
<a class="btn btn-primary btn-large" href="[% c.uri_for_action('/subscriber/edit_master', [ subscriber.id ]) %]"><i class="icon-edit"></i> [% c.loc('Edit') %]</a>
[% END -%]
<div class="ngcp-separator"></div>
@ -71,8 +71,8 @@
IF (c.user.roles == "admin" || c.user.roles == "reseller") && c.user.show_passwords;
elements.push({ value = subscriber.provisioning_voip_subscriber.password, desc = c.loc('SIP Password') });
END;
IF subscriber.provisioning_voip_subscriber.voip_pbx_group.defined;
elements.push({ value = subscriber.provisioning_voip_subscriber.voip_pbx_group.name, desc = c.loc('PBX Group') });
IF subscriber.provisioning_voip_subscriber.pbx_group_id.defined;
elements.push({ value = subscriber.provisioning_voip_subscriber.voip_pbx_group.username, desc = c.loc('PBX Group') });
END;
IF c.user.roles == "admin" || c.user.roles == "reseller";
elements.push({ value = subscriber.provisioning_voip_subscriber.admin ? 'yes' : 'no', desc = c.loc('Administrative') });
@ -97,6 +97,12 @@
[% END -%]
</td>
</tr>
[% IF subscriber.provisioning_voip_subscriber.pbx_extension -%]
<tr>
<td>[% c.loc('Extension') %]</td>
<td>[% subscriber.provisioning_voip_subscriber.pbx_extension %]</td>
</tr>
[% END -%]
<tr>
<td>[% c.loc('Subscriber Profile Set') %]</td>
<td>

Loading…
Cancel
Save