From 9dd50e842715cf3298a0034326c57c20bd1c8d8c Mon Sep 17 00:00:00 2001 From: Kirill Solomko Date: Thu, 20 Jan 2022 16:42:52 +0100 Subject: [PATCH] TT#158003 make subscriber location mappings 'location' optional * 'location' field is now optional, if not filled it it will always default to an empty string instead of null. This is required for the new mode 'forward' that has no use for this field. If the field is empty in any other mode like 'add' or 'replace', the entry will be skiped by the logic. Change-Id: Ia964c3bb272c9772c51b836ac2418ee4cd7b7f42 --- lib/NGCP/Panel/Controller/API/SubscriberLocationMappings.pm | 4 ++++ lib/NGCP/Panel/Controller/Subscriber.pm | 6 +++--- lib/NGCP/Panel/Form/Subscriber/LocationMapping.pm | 2 +- lib/NGCP/Panel/Role/API/SubscriberLocationMappings.pm | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/NGCP/Panel/Controller/API/SubscriberLocationMappings.pm b/lib/NGCP/Panel/Controller/API/SubscriberLocationMappings.pm index ac76a10961..54637e7bf6 100644 --- a/lib/NGCP/Panel/Controller/API/SubscriberLocationMappings.pm +++ b/lib/NGCP/Panel/Controller/API/SubscriberLocationMappings.pm @@ -136,6 +136,10 @@ sub POST :Allow { } $resource->{subscriber_id} = $sub->provisioning_voip_subscriber->id; + $resource->{location} //= ''; + $resource->{caller_pattern} //= '.+'; + $resource->{callee_pattern} //= '.+'; + my $item; try { $item = $c->model('DB')->resultset('voip_subscriber_location_mappings')->create($resource); diff --git a/lib/NGCP/Panel/Controller/Subscriber.pm b/lib/NGCP/Panel/Controller/Subscriber.pm index 6dbe53c548..e39d2cde37 100644 --- a/lib/NGCP/Panel/Controller/Subscriber.pm +++ b/lib/NGCP/Panel/Controller/Subscriber.pm @@ -5824,7 +5824,7 @@ sub create_location_map :Chained('base') :PathPart('preferences/locationmap/crea try { $location_map_rs->create({ subscriber_id => $c->stash->{subscriber}->provisioning_voip_subscriber->id, - location => $form->field('location')->value, + location => $form->field('location')->value // '', caller_pattern => $form->field('caller_pattern')->value // '.+', callee_pattern => $form->field('callee_pattern')->value // '.+', mode => $form->field('mode')->value, @@ -5882,7 +5882,7 @@ sub edit_location_map :Chained('location_map_base') :PathPart('edit') { my $location_map = $c->stash->{location_map}; my $params = {}; - if(!$posted && $location_map) { + if (!$posted && $location_map) { $params = { 'location' => $location_map->location, 'caller_pattern' => $location_map->caller_pattern, @@ -5908,7 +5908,7 @@ sub edit_location_map :Chained('location_map_base') :PathPart('edit') { if($posted && $form->validated) { try { $location_map->update({ - location => $form->field('location')->value, + location => $form->field('location')->value // '', caller_pattern => $form->field('caller_pattern')->value // '.+', callee_pattern => $form->field('callee_pattern')->value // '.+', mode => $form->field('mode')->value, diff --git a/lib/NGCP/Panel/Form/Subscriber/LocationMapping.pm b/lib/NGCP/Panel/Form/Subscriber/LocationMapping.pm index 19404f7b88..242c538ded 100644 --- a/lib/NGCP/Panel/Form/Subscriber/LocationMapping.pm +++ b/lib/NGCP/Panel/Form/Subscriber/LocationMapping.pm @@ -19,7 +19,7 @@ has_field 'subscriber_id' => ( has_field 'location' => ( type => 'Text', label => 'Location URI', - required => 1, + required => 0, element_attr => { rel => ['tooltip'], title => ['Location entry SIP-URI.'] diff --git a/lib/NGCP/Panel/Role/API/SubscriberLocationMappings.pm b/lib/NGCP/Panel/Role/API/SubscriberLocationMappings.pm index 6530cf5e94..ddee83e1a7 100644 --- a/lib/NGCP/Panel/Role/API/SubscriberLocationMappings.pm +++ b/lib/NGCP/Panel/Role/API/SubscriberLocationMappings.pm @@ -110,7 +110,7 @@ sub update_item { return; } $resource->{subscriber_id} = $sub->provisioning_voip_subscriber->id; - + $resource->{location} //= ''; $resource->{caller_pattern} //= '.+'; $resource->{callee_pattern} //= '.+';