~singpolyma/sgx-jmp

c3cc02aa44bbf6c25e5e34e0c021ff6e3de004b1 — Stephen Paul Weber 11 months ago 1d81fc9 + 4f26f5f
Merge branch 'configure-calls-change-location'

* configure-calls-change-location:
  Set location when moving to v2 SIP
3 files changed, 19 insertions(+), 5 deletions(-)

M lib/bwmsgsv2_repo.rb
M lib/customer_fwd.rb
M sgx_jmp.rb
M lib/bwmsgsv2_repo.rb => lib/bwmsgsv2_repo.rb +11 -1
@@ 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)

M lib/customer_fwd.rb => lib/customer_fwd.rb +8 -0
@@ 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

M sgx_jmp.rb => sgx_jmp.rb +0 -4
@@ 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)