MT#6871 Fix subscriber editing.

- Migrate from custom subscriber struct to normal resultset.
- Properly handle boolean input in form processing (convert to
int, otherwise formhandler fails while cloning when doing the
processing).
- Properly handle profile set editing in API
- Cleanup of log messages
ipeshinskaya/InvoiceTemplate5
Andreas Granig 11 years ago
parent 629f215dae
commit 4341a39cf6

@ -407,7 +407,6 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) {
$form->params->{max_subscribers} = undef; $form->params->{max_subscribers} = undef;
} }
my $old_bprof_id = $billing_mapping->billing_profile_id; my $old_bprof_id = $billing_mapping->billing_profile_id;
$c->log->debug(">>>>>>>>>>> old bprof_id=$old_bprof_id");
my $old_prepaid = $billing_mapping->billing_profile->prepaid; my $old_prepaid = $billing_mapping->billing_profile->prepaid;
my $old_ext_id = $contract->external_id // ''; my $old_ext_id = $contract->external_id // '';
$contract->update($form->params); $contract->update($form->params);

@ -32,18 +32,13 @@ sub update_fields {
my $pkg = __PACKAGE__; my $pkg = __PACKAGE__;
$c->log->debug("my form: $pkg"); $c->log->debug("my form: $pkg");
print "+++++++++++++++++++++++++++++ PbxExtensionSubscriberEdit update_fields\n";
my $group = $self->field('group'); my $group = $self->field('group');
$group->field('id')->ajax_src( $group->field('id')->ajax_src(
$c->uri_for_action('/customer/pbx_group_ajax', [$c->stash->{customer_id}])->as_string $c->uri_for_action('/customer/pbx_group_ajax', [$c->stash->{customer_id}])->as_string
); );
print ">>>>>>>>>>>>>>>>>>>>>> PbxExtensionSubscriberEdit update_fields\n";
my $profile_set = $c->stash->{subscriber}->provisioning_voip_subscriber->voip_subscriber_profile_set; my $profile_set = $c->stash->{subscriber}->provisioning_voip_subscriber->voip_subscriber_profile_set;
print ">>>>>>>>>>>>>>>>>>>>>> got profile set?\n";
if($profile_set && $self->field('profile')) { if($profile_set && $self->field('profile')) {
print ">>>>>>>>>>>>>>>>>>>>>> yes, got profile set\n";
$self->field('profile')->field('id')->ajax_src( $self->field('profile')->field('id')->ajax_src(
$c->uri_for_action('/subscriberprofile/profile_ajax', [$profile_set->id])->as_string $c->uri_for_action('/subscriberprofile/profile_ajax', [$profile_set->id])->as_string
); );

@ -181,15 +181,15 @@ sub validate_webpassword {
} }
sub update_fields { sub update_fields {
my $self = shift; my ($self) = @_;
my $c = $self->ctx; my $c = $self->ctx;
return unless $c; return unless $c;
if($c->config->{security}->{password_sip_autogenerate}) { if($c->config->{security}->{password_sip_autogenerate} && $self->field('password')) {
$self->field('password')->inactive(1); $self->field('password')->inactive(1);
$self->field('password')->required(0); $self->field('password')->required(0);
} }
if($c->config->{security}->{password_web_autogenerate}) { if($c->config->{security}->{password_web_autogenerate} && $self->field('webpassword')) {
$self->field('webpassword')->inactive(1); $self->field('webpassword')->inactive(1);
$self->field('webpassword')->required(0); $self->field('webpassword')->required(0);
} }
@ -203,6 +203,7 @@ sub update_fields {
); );
} }
=cut =cut
} }
1; 1;

@ -58,6 +58,16 @@ has_field 'pbx_group' => (
}, },
); );
has_field 'profile' => (
type => '+NGCP::Panel::Field::SubscriberProfile',
label => 'Subscriber Profile',
validate_when_empty => 0,
element_attr => {
rel => ['tooltip'],
title => ['The profile defining the actual feature set for this subscriber.']
},
);
has_field 'save' => ( has_field 'save' => (
type => 'Submit', type => 'Submit',
value => 'Save', value => 'Save',
@ -69,7 +79,7 @@ has_field 'save' => (
has_block 'fields' => ( has_block 'fields' => (
tag => 'div', tag => 'div',
class => [qw/modal-body/], class => [qw/modal-body/],
render_list => [qw/contract domain e164 alias_number webusername webpassword username password status lock external_id administrative is_pbx_group pbx_group display_name/ ], render_list => [qw/contract domain e164 alias_number webusername webpassword username password status lock external_id administrative is_pbx_group pbx_group display_name profile_set profile/ ],
); );
has_block 'actions' => ( has_block 'actions' => (
@ -78,6 +88,11 @@ has_block 'actions' => (
render_list => [qw/save/], render_list => [qw/save/],
); );
# override parent here to prevent any password magic
sub update_fields {
my $self = shift;
}
1; 1;
# vim: set tabstop=4 expandtab: # vim: set tabstop=4 expandtab:

@ -90,6 +90,10 @@ sub validate_form {
# remove unknown keys # remove unknown keys
my %fields = map { $_->name => undef } $form->fields; my %fields = map { $_->name => undef } $form->fields;
for my $k (keys %{ $resource }) { for my $k (keys %{ $resource }) {
#if($resource->{$k}->$_isa('JSON::XS::Boolean') || $resource->{$k}->$_isa('JSON::PP::Boolean')) {
if($resource->{$k}->$_isa('JSON::PP::Boolean')) {
$resource->{$k} = $resource->{$k} ? 1 : 0;
}
unless(exists $fields{$k}) { unless(exists $fields{$k}) {
delete $resource->{$k}; delete $resource->{$k};
} }

@ -21,7 +21,7 @@ use NGCP::Panel::Utils::Subscriber;
sub get_form { sub get_form {
my ($self, $c) = @_; my ($self, $c) = @_;
return NGCP::Panel::Form::Subscriber::SubscriberAPI->new; return NGCP::Panel::Form::Subscriber::SubscriberAPI->new(ctx => $c);
} }
sub transform_resource { sub transform_resource {
@ -244,18 +244,24 @@ sub prepare_resource {
my $preferences = {}; my $preferences = {};
my $admin = 0; my $admin = 0;
unless($customer->get_column('product_class') eq 'pbxaccount') { unless($customer->get_column('product_class') eq 'pbxaccount') {
delete $resource->{is_pbx_group}; for my $pref(qw/is_pbx_group pbx_group_id pbx_extension pbx_hunt_policy pbx_hunt_timeout/) {
delete $resource->{pbx_group_id}; delete $resource->{$pref};
}
$admin = $resource->{admin} // 0; $admin = $resource->{admin} // 0;
} elsif($c->config->{features}->{cloudpbx}) { } elsif($c->config->{features}->{cloudpbx}) {
my $subs = NGCP::Panel::Utils::Subscriber::get_custom_subscriber_struct( my $subs = $c->model('DB')->resultset('voip_subscribers')->search({
c => $c, contract_id => $customer->id,
contract => $customer, status => { '!=' => 'terminated' },
show_locked => 1, 'provisioning_voip_subscriber.is_pbx_group' => 0,
); }, {
my $admin_subscribers = NGCP::Panel::Utils::Subscriber::get_admin_subscribers( join => 'provisioning_voip_subscriber',
voip_subscribers => $subs->{subscribers}); });
unless(@{ $admin_subscribers }) { my $admin_subscribers = $subs->search({
'provisioning_voip_subscriber.admin' => 1,
});
my $admin_subscriber = $admin_subscribers->first;
unless($admin_subscriber) {
$admin = $resource->{admin} // 1; $admin = $resource->{admin} // 1;
} else { } else {
$admin = $resource->{admin} // 0; $admin = $resource->{admin} // 0;
@ -271,10 +277,9 @@ sub prepare_resource {
$preferences->{contract_sound_set} = $default_sound_set->id; $preferences->{contract_sound_set} = $default_sound_set->id;
} }
my $admin_subscriber = $admin_subscribers->[0]; my $base_number = $admin_subscriber->primary_number;
my $base_number = $admin_subscriber->{primary_number};
if($base_number) { if($base_number) {
$preferences->{cloud_pbx_base_cli} = $base_number->{cc} . $base_number->{ac} . $base_number->{sn}; $preferences->{cloud_pbx_base_cli} = $base_number->cc . ($base_number->ac // '') . $base_number->sn;
} }
} }
if(exists $resource->{external_id}) { if(exists $resource->{external_id}) {
@ -381,6 +386,59 @@ sub update_item {
} }
} }
my ($profile_set, $profile);
if($resource->{profile_set_id}) {
my $profile_set_rs = $c->model('DB')->resultset('voip_subscriber_profile_sets');
if($c->user->roles eq "admin") {
} elsif($c->user->roles eq "reseller") {
$profile_set_rs = $profile_set_rs->search({
reseller_id => $c->user->reseller_id,
});
}
$profile_set = $profile_set_rs->find($resource->{profile_set_id});
unless($profile_set) {
$c->log->error("invalid subscriber profile set id '" . $resource->{profile_set_id} . "'");
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Invalid profile_set_id parameter");
return;
}
}
if($profile_set && $resource->{profile_id}) {
$profile = $profile_set->voip_subscriber_profiles->find({
id => $resource->{profile_id},
});
}
if($profile_set && !$profile) {
$profile = $profile_set->voip_subscriber_profiles->find({
set_default => 1,
});
}
# if the profile changed, clear any preferences which are not in the new profile
if($subscriber->provisioning_voip_subscriber->voip_subscriber_profile) {
my %old_profile_attributes = map { $_ => 1 }
$subscriber->provisioning_voip_subscriber->voip_subscriber_profile
->profile_attributes->get_column('attribute_id')->all;
if($profile) {
foreach my $attr_id($profile->profile_attributes->get_column('attribute_id')->all) {
delete $old_profile_attributes{$attr_id};
}
}
if(keys %old_profile_attributes) {
my $cfs = $c->model('DB')->resultset('voip_preferences')->search({
id => { -in => [ keys %old_profile_attributes ] },
attribute => { -in => [qw/cfu cfb cft cfna/] },
});
$subscriber->provisioning_voip_subscriber->voip_usr_preferences->search({
attribute_id => { -in => [ keys %old_profile_attributes ] },
})->delete;
$subscriber->provisioning_voip_subscriber->voip_cf_mappings->search({
type => { -in => [ map { $_->attribute } $cfs->all ] },
})->delete;
}
}
NGCP::Panel::Utils::Subscriber::update_subscriber_numbers( NGCP::Panel::Utils::Subscriber::update_subscriber_numbers(
schema => $c->model('DB'), schema => $c->model('DB'),
primary_number => $resource->{e164}, primary_number => $resource->{e164},
@ -401,8 +459,14 @@ sub update_item {
is_pbx_group => $resource->{is_pbx_group}, is_pbx_group => $resource->{is_pbx_group},
pbx_group_id => $resource->{pbx_group_id}, pbx_group_id => $resource->{pbx_group_id},
modify_timestamp => NGCP::Panel::Utils::DateTime::current_local, modify_timestamp => NGCP::Panel::Utils::DateTime::current_local,
profile_set_id => $profile_set ? $profile_set->id : undef,
profile_id => $profile ? $profile->id : undef,
}; };
if($resource->{is_pbx_group}) {
$provisioning_res->{pbx_hunt_policy} = $resource->{pbx_hunt_policy};
$provisioning_res->{pbx_hunt_timeout} = $resource->{pbx_hunt_timeout};
$provisioning_res->{pbx_group_id} = undef;
}
$subscriber->update($billing_res); $subscriber->update($billing_res);
$subscriber->provisioning_voip_subscriber->update($provisioning_res); $subscriber->provisioning_voip_subscriber->update($provisioning_res);

@ -356,8 +356,6 @@ sub update_pbx_group_prefs {
sub update_subscriber_numbers { sub update_subscriber_numbers {
my %params = @_; my %params = @_;
print ">>>>>>>>>>>>>>>>>>> update_subscriber_numbers\n";
my $schema = $params{schema}; my $schema = $params{schema};
my $subscriber_id = $params{subscriber_id}; my $subscriber_id = $params{subscriber_id};
my $reseller_id = $params{reseller_id}; my $reseller_id = $params{reseller_id};
@ -371,13 +369,11 @@ sub update_subscriber_numbers {
my @nums = (); my @dbnums = (); my @nums = (); my @dbnums = ();
if(exists $params{primary_number} && !defined $primary_number) { if(exists $params{primary_number} && !defined $primary_number) {
print ">>>>>>>>>>>>>>>>> discard primary number\n";
$billing_subs->update({ $billing_subs->update({
primary_number_id => undef, primary_number_id => undef,
}); });
} }
elsif(defined $primary_number) { elsif(defined $primary_number) {
print ">>>>>>>>>>>>>>>>> update primary number\n";
my $old_cc; my $old_cc;
my $old_ac; my $old_ac;

Loading…
Cancel
Save