From 4f26f5f84be11e7cc4eb94c0f7bd4a20e11c7775 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Thu, 14 Oct 2021 19:55:54 -0500 Subject: [PATCH] Set location when moving to v2 SIP From configure calls as well as from reset sip account. --- lib/bwmsgsv2_repo.rb | 12 +++++++++++- lib/customer_fwd.rb | 8 ++++++++ sgx_jmp.rb | 4 ---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/bwmsgsv2_repo.rb b/lib/bwmsgsv2_repo.rb index daf29e2..28480ba 100644 --- a/lib/bwmsgsv2_repo.rb +++ b/lib/bwmsgsv2_repo.rb @@ -44,11 +44,21 @@ class Bwmsgsv2Repo "catapult_fwd_timeout-#{sgx.from_jid}", customer_fwd.timeout.to_i ) - ]) + ]).then do + set_default_location(tel) if customer_fwd.v2_sip? + end end protected + def set_default_location(tel) + # Migrate location if needed + BandwidthIris::SipPeer.new( + site_id: CONFIG[:bandwidth_site], + id: CONFIG[:bandwidth_peer] + ).move_tns([tel]) + end + def set_or_delete(k, v) if v.nil? REDIS.del(k) diff --git a/lib/customer_fwd.rb b/lib/customer_fwd.rb index 7139ed3..fcb9659 100644 --- a/lib/customer_fwd.rb +++ b/lib/customer_fwd.rb @@ -52,6 +52,10 @@ class CustomerFwd BANDWIDTH_VOICE.create_call(account, body: request).data.call_id end + def v2_sip? + false + end + class Tel < CustomerFwd def to uri.sub(/^tel:/, "") @@ -59,6 +63,10 @@ class CustomerFwd end class SIP < CustomerFwd + def v2_sip? + uri.end_with?(CONFIG[:sip][:realm]) + end + def to uri end diff --git a/sgx_jmp.rb b/sgx_jmp.rb index eb2c349..0d86543 100644 --- a/sgx_jmp.rb +++ b/sgx_jmp.rb @@ -625,10 +625,6 @@ Command.new( reply.command << form }.then do |fwd| if ["1", "true"].include?(fwd.form.field("change_fwd")&.value.to_s) - # Migrate location if needed - BandwidthIris::SipPeer.new( - site_id: CONFIG[:bandwidth_site], id: CONFIG[:bandwidth_peer] - ).move_tns([customer.registered?.phone]) Command.execution.customer_repo.put_fwd( customer, customer.fwd.with(uri: sip_account.uri) -- 2.38.5