Skip to content

Commit

Permalink
Drop append domain names setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Dyrkon committed Feb 13, 2023
1 parent 9519609 commit b48c11c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
9 changes: 9 additions & 0 deletions app/models/host/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def dup
:domain=, :domain_id=, :domain_name=, :to => :primary_interface

attr_writer :updated_virtuals

def updated_virtuals
@updated_virtuals ||= []
end
Expand Down Expand Up @@ -351,6 +352,14 @@ def render_template(template:, **params)
template.render(host: self, **params)
end

def to_label
if Setting[:append_domain_name_for_hosts]
name
else
name.split('.')[0]
end
end

private

def parse_ip_address(address, ignore_link_local: true)
Expand Down
2 changes: 1 addition & 1 deletion app/services/name_synchronizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ def sync_required?
private

def interface_name
Setting[:append_domain_name_for_hosts] ? @interface.name : @interface.shortname
@interface.name
end
end
10 changes: 9 additions & 1 deletion app/views/api/v2/hosts/base.json.rabl
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
object @host

attributes :name, :id
attributes :id

node :name do |name|
if Setting[:append_domain_name_for_hosts]
name.split('.')[0]
else
name
end
end
4 changes: 2 additions & 2 deletions test/models/lookup_value_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def valid_attrs2

test "can create lookup value if match fqdn= does match existing host" do
as_admin do
Setting[:append_domain_name_for_hosts] = false
Setting[:append_domain_name_for_hosts] = false # This affects the view only
domain = FactoryBot.create(:domain)
host = FactoryBot.create(:host, interfaces: [FactoryBot.build(:nic_managed, identifier: 'fqdn_test', primary: true, domain: domain)])
attrs = { :match => "fqdn=#{host.primary_interface.fqdn}", :value => "123", :lookup_key_id => lookup_key.id }
refute_match /#{domain.name}/, host.name, "#{host.name} shouldn't be FQDN"
refute_match /#{domain.name}/, host.name.split('.')[0], "#{host.name} shouldn't be FQDN"
assert_difference('LookupValue.count') do
LookupValue.create!(attrs)
end
Expand Down

0 comments on commit b48c11c

Please sign in to comment.