From 9827b8b48336d249637f88d6921d613ad12b16f1 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 18 Apr 2022 13:44:19 -0500 Subject: [PATCH 1/3] Allow finishing adming command --- lib/admin_command.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/admin_command.rb b/lib/admin_command.rb index 0b8e02821a574adca161b5cb68b044ee38e792b8..c408998c8a59300273650f64c7a209ed375dfb30 100644 --- a/lib/admin_command.rb +++ b/lib/admin_command.rb @@ -11,30 +11,32 @@ class AdminCommand end def start - action_info.then { menu } + action_info.then { menu_or_done } end def reply(form) Command.reply { |reply| - reply.allowed_actions = [:next] + reply.allowed_actions = [:next, :complete] reply.command << form } end - def menu + def menu_or_done(command_action=:execute) + return Command.finish("Done") if command_action == :complete + reply(FormTemplate.render("admin_menu")).then do |response| if response.form.field("action") - handle(response.form.field("action").value) + handle(response.form.field("action").value, response.action) end end end - def handle(action) + def handle(action, command_action) if respond_to?("action_#{action}") send("action_#{action}") else new_context(action) - end.then { menu } + end.then { menu_or_done(command_action) } end def new_context(q) From 016d8c4b04f63bc792ab772f841682cb8ebead95 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 18 Apr 2022 14:34:38 -0500 Subject: [PATCH 2/3] v1 is dead and everyone has been moved --- lib/bwmsgsv2_repo.rb | 12 +----------- lib/customer_fwd.rb | 16 ---------------- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/lib/bwmsgsv2_repo.rb b/lib/bwmsgsv2_repo.rb index 429ea6ff25eb930f094abc82ee481f30512b033d..e59c80a771cc78e95f7cbf175e3556dd2390b501 100644 --- a/lib/bwmsgsv2_repo.rb +++ b/lib/bwmsgsv2_repo.rb @@ -50,21 +50,11 @@ class Bwmsgsv2Repo "catapult_fwd_timeout-#{sgx.from_jid}", customer_fwd.timeout.to_i ) - ]).then do - set_default_location(tel) if customer_fwd.v2_safe? - 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 fbf33631b8d7f2b697d988215b8609d22a5450e0..0151250ae4c789170473c4dc0eaf2aec02640d07 100644 --- a/lib/customer_fwd.rb +++ b/lib/customer_fwd.rb @@ -57,15 +57,7 @@ class CustomerFwd BANDWIDTH_VOICE.create_call(account, body: request).data.call_id end - def v2_safe? - false - end - class Tel < CustomerFwd - def v2_safe? - true - end - def initialize(values) super raise "Bad tel format: #{uri}" unless uri.match?(/\Atel:\+1\d{10}\Z/) @@ -77,20 +69,12 @@ class CustomerFwd end class SIP < CustomerFwd - def v2_safe? - uri.end_with?(CONFIG[:sip][:realm]) - end - def to uri end end class XMPP < CustomerFwd - def v2_safe? - true - end - def to jid = uri.sub(/^xmpp:/, "") "sip:#{ERB::Util.url_encode(jid)}@sip.cheogram.com" From 18258dd4fe0cbf048cc0fd96494461bef0964cb1 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 18 Apr 2022 14:41:00 -0500 Subject: [PATCH 3/3] Try to classify URI before saving, even if timeout.zero? --- .rubocop.yml | 3 +++ lib/customer_fwd.rb | 16 ++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index d0b95af5f9199af7fff5b3fa40e6d4e650f97c7e..ca9ec06b0c96f156ee1685df2e895d9c483439cf 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -55,6 +55,9 @@ Layout/LineLength: Exclude: - Gemfile +Layout/EndAlignment: + EnforcedStyleAlignWith: start_of_line + Layout/SpaceAroundEqualsInParameterDefault: EnforcedStyle: no_space diff --git a/lib/customer_fwd.rb b/lib/customer_fwd.rb index 0151250ae4c789170473c4dc0eaf2aec02640d07..bee076d3acf7b65b6fdd6cd618d364a6a366981f 100644 --- a/lib/customer_fwd.rb +++ b/lib/customer_fwd.rb @@ -7,14 +7,18 @@ require "uri" class CustomerFwd def self.for(uri:, timeout:) timeout = Timeout.new(timeout) - return None.new(uri: uri, timeout: timeout) if !uri || timeout.zero? - if uri =~ /\Asip:(.*)@sip.cheogram.com\Z/ - uri = "xmpp:#{$1.gsub(/%([0-9A-F]{2})/i) { $1.to_i(16).chr }}" + fwd = if uri + if uri =~ /\Asip:(.*)@sip.cheogram.com\Z/ + uri = "xmpp:#{$1.gsub(/%([0-9A-F]{2})/i) { $1.to_i(16).chr }}" + end + + URIS.fetch(uri.split(":", 2).first.to_sym) { + raise "Unknown forward URI: #{uri}" + }.new(uri: uri, timeout: timeout) end - URIS.fetch(uri.split(":", 2).first.to_sym) { - raise "Unknown forward URI: #{uri}" - }.new(uri: uri, timeout: timeout) + + fwd && !timeout.zero? ? fwd : None.new(uri: uri, timeout: timeout) end class Timeout