Revision a525db23
Added by Stephen Benjamin almost 6 years ago
app/models/nic/interface.rb | ||
---|---|---|
end
|
||
|
||
def fqdn_before_last_save
|
||
domain_before_last_save = Domain.find(domain_id_before_last_save) if domain_id_before_last_save.present?
|
||
domain_before_last_save = Domain.unscoped.find(domain_id_before_last_save) if domain_id_before_last_save.present?
|
||
return name_before_last_save if name_before_last_save.blank? || domain_before_last_save.blank?
|
||
name_before_last_save.include?('.') ? name_before_last_save : "#{name_before_last_save}.#{domain_before_last_save}"
|
||
end
|
||
... | ... | |
return if name.empty?
|
||
if domain_id.nil? && name.include?('.') && changed_attributes['domain_id'].blank?
|
||
# try to assign the domain automatically based on our existing domains from the host FQDN
|
||
self.domain = Domain.find_by(:name => name.partition('.')[2])
|
||
self.domain = Domain.unscoped.find_by(:name => name.partition('.')[2])
|
||
elsif persisted? && changed_attributes['domain_id'].present?
|
||
# if we've just updated the domain name, strip off the old one
|
||
old_domain = Domain.find(changed_attributes["domain_id"])
|
||
old_domain = Domain.unscoped.find(changed_attributes["domain_id"])
|
||
# Remove the old domain, until fqdn will be set as the full name
|
||
self.name = self.name.chomp('.' + old_domain.to_s)
|
||
end
|
Also available in: Unified diff
fixes #23232 - fix error when domain not in taxonomy
This ensures that if domain_id is set, but domain not found (for example
when domain is in another taxonomy), the shortname still removes the
domain from the host's FQDN.