Skip to content

Commit

Permalink
Avoiding duplicated physical provider connection
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasgabriel committed Feb 5, 2018
1 parent 66bad00 commit 64732f5
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/models/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,16 @@ def self.supported_types_and_descriptions_hash
def hostname_uniqueness_valid?
return unless hostname_required?
return unless hostname.present? # Presence is checked elsewhere
# check uniqueness per provider type

existing_hostnames = (self.class.all - [self]).map(&:hostname).compact.map(&:downcase)

errors.add(:hostname, N_("has to be unique per provider type")) if existing_hostnames.include?(hostname.downcase)
hostname_without_slash = hostname.downcase.gsub(/\/$/, '')
# get all hostnames on database without '/' at the end
existing_hostnames = (self.class.all - [self]).map(&:hostname).compact.map { |hostname| hostname.downcase.gsub(/\/$/, '') }
errors.add(:hostname, N_("has to be unique per provider type")) if existing_hostnames.include?(hostname_without_slash)

# if hostname is ipaddress check against dicovered ipaddress in database too
if hostname.ipaddress?
existing_ipaddress = (self.class.all - [self]).map(&:ipaddress).compact.map { |ipaddress| ipaddress.gsub(/\/$/, '') }
errors.add(:ipaddress, N_("has to be unique per provider type")) if existing_ipaddress.include?(hostname_without_slash)
end
end

def hostname_format_valid?
Expand Down

0 comments on commit 64732f5

Please sign in to comment.