diff --git a/app/controllers/sms_settings_controller.rb b/app/controllers/sms_settings_controller.rb index a2163be6..6b7b7d5d 100644 --- a/app/controllers/sms_settings_controller.rb +++ b/app/controllers/sms_settings_controller.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class SmsSettingsController < ApplicationController + SECRET_KEYS = %w[basic_auth_token twilio_auth_token voipms_api_password signalwire_api_token].freeze + before_action :load_encrypted_config authorize_resource :encrypted_config, only: :index authorize_resource :encrypted_config, parent: false, only: %i[create test_message] @@ -46,8 +48,6 @@ class SmsSettingsController < ApplicationController key: EncryptedConfig::SMS_CONFIGS_KEY) end - SECRET_KEYS = %w[basic_auth_token twilio_auth_token voipms_api_password signalwire_api_token].freeze - def build_sms_value submitted = params.require(:encrypted_config).permit(value: {})[:value].to_h existing = @encrypted_config.value || {} diff --git a/app/views/sms_settings/index.html.erb b/app/views/sms_settings/index.html.erb index e41ad9b2..3e430a51 100644 --- a/app/views/sms_settings/index.html.erb +++ b/app/views/sms_settings/index.html.erb @@ -5,8 +5,7 @@ <% value = @encrypted_config.value || {} %> <% sms_live = Sms.enabled_for?(current_account) %> - <% - provider_labels = { + <% provider_labels = { 'bulkvs' => 'BulkVS', 'twilio' => 'Twilio', 'voipms' => 'VoIP.ms', @@ -185,7 +184,7 @@
-<%= javascript_tag nonce: true do %> + diff --git a/lib/sms/providers/signalwire.rb b/lib/sms/providers/signalwire.rb index 4d056f79..96381750 100644 --- a/lib/sms/providers/signalwire.rb +++ b/lib/sms/providers/signalwire.rb @@ -41,7 +41,7 @@ module Sms private def normalize_space_url(raw) - raw.to_s.strip.sub(%r{\Ahttps?://}, '').sub(%r{/\z}, '') + raw.to_s.strip.sub(%r{\Ahttps?://}, '').delete_suffix('/') end def format_e164(raw) @@ -70,9 +70,7 @@ module Sms { 'raw' => response.body.to_s } end - if response.is_a?(Net::HTTPSuccess) && body['error_code'].nil? - return body - end + return body if response.is_a?(Net::HTTPSuccess) && body['error_code'].nil? code = body['code'] || body['error_code'] message = body['message'] || body['error_message'] || body['raw'] || "HTTP #{response.code}" diff --git a/lib/sms/providers/twilio.rb b/lib/sms/providers/twilio.rb index 60c4c37e..1ac0c250 100644 --- a/lib/sms/providers/twilio.rb +++ b/lib/sms/providers/twilio.rb @@ -70,9 +70,7 @@ module Sms { 'raw' => response.body.to_s } end - if response.is_a?(Net::HTTPSuccess) && body['error_code'].nil? - return body - end + return body if response.is_a?(Net::HTTPSuccess) && body['error_code'].nil? code = body['code'] || body['error_code'] message = body['message'] || body['error_message'] || body['raw'] || "HTTP #{response.code}"