Fix CI lint failures in SMS provider work

Rubocop:
- lib/sms/providers/{signalwire,twilio}.rb: collapse the
  Net::HTTPSuccess success-path `if` into modifier form
  (Style/IfUnlessModifier).
- lib/sms/providers/signalwire.rb: `delete_suffix('/')` instead of
  `sub(%r{/\z}, '')` (Performance/DeleteSuffix).
- app/controllers/sms_settings_controller.rb: move SECRET_KEYS to
  the top of the class so it isn't sandwiched under `private`
  (Lint/UselessConstantScoping). Ruby constants aren't actually
  privatised by a preceding `private` keyword anyway.

Erblint:
- app/views/sms_settings/index.html.erb: replace `javascript_tag do`
  with a raw `<script nonce=...>` block so erblint's
  AvoidUsingJavascriptTag rule is satisfied. CSP nonce comes from
  Rails' content_security_policy_nonce helper, same source as before.
- Inline the ERB block-opener so Ruby doesn't see a leading empty
  line (Layout/LeadingEmptyLines).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
pull/687/head
Wabo 1 month ago
parent 521a4b78cd
commit 02b98fda3e

@ -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 || {}

@ -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 @@
<div class="w-0 md:w-52"></div>
</div>
<%= javascript_tag nonce: true do %>
<script nonce="<%= content_security_policy_nonce %>">
(function () {
const select = document.getElementById('sms_provider_select')
if (!select) return
@ -199,4 +198,4 @@
select.addEventListener('change', sync)
sync()
})()
<% end %>
</script>

@ -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}"

@ -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}"

Loading…
Cancel
Save