TT#52989 Implement device alias provisioning logic

Change-Id: I7dc14a2f8fdcfa507a5e46872421923b44f133bc
changes/35/27435/9
Andreas Granig 6 years ago committed by Irina Peshinskaya
parent dae98217a4
commit d5ba7c11cb

@ -29,6 +29,18 @@ sub get_journal_methods{
return [qw/handle_item_base_journal handle_journals_get handle_journalsitem_get handle_journals_options handle_journalsitem_options handle_journals_head handle_journalsitem_head handle_journalsitem_put handle_journalsitem_patch/];
}
sub pre_process_form_resource {
my($self,$c, $item, $old_resource, $resource, $form, $process_extras) = @_;
if (!exists $resource->{is_devid} && defined $item->voip_dbalias) {
$resource->{is_devid} = $item->voip_dbalias->is_devid;
}
if (!exists $resource->{devid_alias} && defined $item->voip_dbalias) {
$resource->{devid_alias} = $item->voip_dbalias->devid_alias;
}
return 1;
}
sub update_item_model {
my ($self, $c, $item, $old_resource, $resource, $form) = @_;
my $schema = $c->model('DB');
@ -97,7 +109,17 @@ sub update_item_model {
();
} else {
# otherwise keep number
{ e164 => { cc => $_->cc, ac => $_->ac, sn => $_->sn } };
if (!defined $_->voip_dbalias) {
$c->log->debug("+++ no oldsub dbalias for sn " . $_->sn);
} else {
$c->log->debug("+++ oldsub dbalias for sn " . $_->sn . " is " . ($_->voip_dbalias->devid_alias//"undef"));
}
{ e164 => {
cc => $_->cc, ac => $_->ac, sn => $_->sn,
is_devid => (defined $_->voip_dbalias ? $_->voip_dbalias->is_devid : 0),
devid_alias => (defined $_->voip_dbalias ? $_->voip_dbalias->devid_alias : undef),
}
};
}
}
} @{ $oldalias } ];
@ -121,11 +143,28 @@ sub update_item_model {
();
} else {
# otherwise keep number
{ e164 => { cc => $_->cc, ac => $_->ac, sn => $_->sn } };
if (!defined $_->voip_dbalias) {
$c->log->debug("+++ no newsub dbalias for sn " . $_->sn);
} else {
$c->log->debug("+++ newsub dbalias for sn " . $_->sn . " is " . ($_->voip_dbalias->devid_alias//"undef"));
}
{ e164 => {
cc => $_->cc, ac => $_->ac, sn => $_->sn,
is_devid => (defined $_->voip_dbalias ? $_->voip_dbalias->is_devid : 0),
devid_alias => (defined $_->voip_dbalias ? $_->voip_dbalias->devid_alias : undef),
}
};
}
}
} @{ $newalias } ];
push @{ $newalias }, { e164 => { cc => $item->cc, ac => $item->ac, sn => $item->sn } };
use Data::Dumper; $c->log->debug(Dumper $resource);
push @{ $newalias }, { e164 => {
cc => $item->cc, ac => $item->ac, sn => $item->sn,
is_devid => $resource->{is_devid} // 0,
devid_alias => $resource->{devid_alias},
}
};
NGCP::Panel::Utils::Subscriber::update_subscriber_numbers(
c => $c,
@ -157,14 +196,20 @@ sub update_item_model {
return;
}
# reload item, in case the id changed (which shouldn't happen)
$item = $self->_item_rs($c)->find({
cc => $item->cc, ac => $item->ac, sn => $item->sn
cc => $item->cc, ac => $item->ac, sn => $item->sn,
});
return $item;
}
sub post_process_hal_resource {
my($self, $c, $item, $resource, $form) = @_;
$resource->{is_devid} = bool $item->voip_dbalias->is_devid;
$resource->{devid_alias} = $item->voip_dbalias->devid_alias;
return $resource;
}
1;

@ -11,7 +11,7 @@ has_field 'id' => (
has_field 'e164' => (
type => '+NGCP::Panel::Field::E164',
order => 99,
order => 97,
required => 0,
label => 'Alias Number',
do_label => 1,
@ -19,6 +19,36 @@ has_field 'e164' => (
wrapper_class => [qw/hfh-rep-field/],
);
has_field 'is_devid' => (
type => 'Boolean',
required => 0,
label => 'Is Device ID',
do_label => 1,
do_wrapper => 1,
wrapper_class => [qw/hfh-rep-field/],
order => 98,
element_attr => {
rel => ['tooltip'],
title => ['When selected, a call to this alias number is only sent to registered devices indicating either the alias number or the optional alternative device id during registration in the Display-Name.']
},
);
has_field 'devid_alias' => (
type => 'Text',
required => 0,
maxlength => 127,
label => 'Alternative Device ID',
do_label => 1,
do_wrapper => 1,
wrapper_class => [qw/hfh-rep-field/],
order => 99,
element_attr => {
rel => ['tooltip'],
title => ['An optional device id to be configured on a phone, which is associated with this alias number (e.g. "softphone").']
},
);
has_field 'rm' => (
type => 'RmElement',
value => 'Remove',
@ -26,6 +56,12 @@ has_field 'rm' => (
element_class => [qw/btn btn-primary pull-right/],
);
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/e164 is_devid devid_alias/ ],
);
no Moose;
1;

@ -0,0 +1,38 @@
package NGCP::Panel::Field::E164Alias;
use HTML::FormHandler::Moose;
use NGCP::Panel::Field::E164;
extends 'NGCP::Panel::Field::E164';
has_field 'is_devid' => (
type => 'Boolean',
required => 0,
label => 'Is Device ID',
do_label => 1,
do_wrapper => 1,
wrapper_class => [qw/hfh-rep-field/],
order => 98,
element_attr => {
rel => ['tooltip'],
title => ['When selected, a call to this alias number is only sent to registered devices indicating either the alias number or the optional alternative device id during registration in the Display-Name.']
},
);
has_field 'devid_alias' => (
type => 'Text',
required => 0,
maxlength => 127,
label => 'Alternative Device ID',
do_label => 1,
do_wrapper => 1,
wrapper_class => [qw/hfh-rep-field/],
order => 99,
element_attr => {
rel => ['tooltip'],
title => ['An optional device id to be configured on a phone, which is associated with this alias number (e.g. "softphone").']
},
);
no Moose;
1;
# vim: set tabstop=4 expandtab:

@ -44,5 +44,24 @@ has_field 'is_primary' => (
},
);
has_field 'is_devid' => (
type => 'Boolean',
element_attr => {
rel => ['tooltip'],
title => ['When selected, a call to this alias number is only sent to registered devices indicating either the alias number or the optional alternative device id during registration in the Display-Name.']
},
);
has_field 'devid_alias' => (
type => 'Text',
required => 0,
maxlength => 127,
element_attr => {
rel => ['tooltip'],
title => ['An optional device id to be configured on a phone, which is associated with this alias number (e.g. "softphone").']
},
);
1;
# vim: set tabstop=4 expandtab:

@ -38,7 +38,7 @@ has_field 'alias_numbers' => (
);
has_field 'alias_numbers.contains' => (
type => '+NGCP::Panel::Field::E164',
type => '+NGCP::Panel::Field::E164Alias',
);
has_field 'lock' => (

@ -47,7 +47,7 @@ has_field 'webpassword' => (
);
has_field 'e164' => (
type => '+NGCP::Panel::Field::E164',
type => '+NGCP::Panel::Field::E164Alias',
order => 99,
required => 0,
label => 'E164 Number',

@ -45,7 +45,7 @@ sub _item_rs {
},{
'+select' => [\'if(me.id=subscriber.primary_number_id,1,0)'],
'+as' => ['is_primary'],
join => 'subscriber'
join => 'subscriber',
});
if($c->user->roles eq "admin") {
} elsif($c->user->roles eq "reseller") {

@ -111,6 +111,10 @@ sub resource_from_item {
};
next if($resource{primary_number} &&
compare($resource{primary_number}, $alias));
if (defined $n->voip_dbalias) {
$alias->{is_devid} = bool $n->voip_dbalias->is_devid;
$alias->{devid_alias} = $n->voip_dbalias->devid_alias;
}
push @{ $resource{alias_numbers} }, $alias;
}
}
@ -688,6 +692,7 @@ sub update_item {
schema => $schema,
subscriber => $subscriber,
);
try {
NGCP::Panel::Utils::Subscriber::update_subscriber_numbers(
c => $c,

@ -1111,14 +1111,18 @@ sub update_subscriber_numbers {
username => $cli,
});
if($dbalias) {
if($dbalias->is_primary) {
$dbalias->update({ is_primary => 0 });
}
$dbalias->update({
is_primary => 0,
is_devid => $alias->{e164}->{is_devid} // 0,
devid_alias => $alias->{e164}->{devid_alias},
});
} else {
$dbalias = $prov_subs->voip_dbaliases->create({
username => $cli,
domain_id => $prov_subs->domain->id,
is_primary => 0,
is_devid => $alias->{e164}->{is_devid} // 0,
devid_alias => $alias->{e164}->{devid_alias},
});
}
if(defined $acli_pref) {

@ -301,6 +301,8 @@ if($remote_config->{config}->{features}->{cloudpbx}){
$pilot_local = $test_machine->get_item_hal('subscribers', '/api/subscribers/'.$pilot_local->{content}->{id}, 1);
$terminated_primary_number->{is_devid} = json_true;
$terminated_primary_number->{devid_alias} = 'something';
$test_machine->check_patch2get([ { op => 'replace', path => '/alias_numbers', value => [@{$pilot_local->{content}->{alias_numbers}}, $terminated_primary_number] } ] , $pilot_local->{location},$put2get_check_params);
$aliases = $test_machine->get_collection_hal('numbers', '/api/numbers/?type=alias&subscriber_id='.$pilot_local->{content}->{id}, 1)->{collection};

@ -22,7 +22,7 @@ use File::Temp qw(tempfile);
Moose::Exporter->setup_import_methods(
as_is => [ 'seq' ],
as_is => [ 'seq', 'json_true', 'json_false' ],
);
sub BUILD {
@ -924,6 +924,15 @@ sub seq{
return $number + $seq++;
}
my $json = '{"true": true, "false": false}';
my $perl = decode_json $json;
sub json_true {
return $perl->{true};
}
sub json_false {
return $perl->{false};
}
1;
__END__

Loading…
Cancel
Save