Skip to content

Commit

Permalink
Add striping to some channel settings values
Browse files Browse the repository at this point in the history
This should help a bit dealing with user entry errors while configuring
channels. Regarding #783, 2 out of 3 channels which fail to resolve the IP
address of the domain have a whitespace at the start/end of the domain, which
makes the DNS query fail. Plus, we've had authentication errors in the past due
to extra whitespace in the username and password.
  • Loading branch information
ggiraldez committed Jan 27, 2017
1 parent 55df248 commit cfcc3e4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/models/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class Channel < ActiveRecord::Base

broker_cached

def name=(value)
super(value.try(:strip))
end

def config
self[:config] ||= {}
end
Expand Down
8 changes: 4 additions & 4 deletions app/models/channels/sip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
class Channels::Sip < Channel
validate :server_username_uniqueness

config_accessor :username
config_accessor :password
config_accessor :domain
config_accessor :username, strip: true
config_accessor :password, strip: true
config_accessor :domain, strip: true
config_accessor :direction
config_accessor :register
config_accessor :number
config_accessor :number, strip: true

def register?
register == true || register == "1"
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ActiveRecord::Base
def self.config_accessor(*names)
options = names.extract_options!
default = options[:default]
strip = options[:strip]

names.each do |name|
self.config_attrs << name
Expand All @@ -31,6 +32,7 @@ def self.config_accessor(*names)
respond_to?(:encrypted_config_will_change!) ? encrypted_config_will_change! : config_will_change!

self.config ||= {}
value = value.try(:strip) if strip
self.config[name.to_s] = value

# this is needed so attr_encrypted encrypts the value correctly
Expand Down

0 comments on commit cfcc3e4

Please sign in to comment.