From 837f7b85f7e74b69ddc74806efc948b06071ae8c Mon Sep 17 00:00:00 2001 From: Dyrkon Date: Thu, 2 Feb 2023 09:57:05 +0100 Subject: [PATCH] Drop append domain names setting --- app/assets/javascripts/host_edit_interfaces.js | 5 +---- app/models/host/base.rb | 9 +++++++++ app/services/name_synchronizer.rb | 2 +- app/views/api/v2/hosts/base.json.rabl | 10 +++++++++- app/views/hosts/_form.html.erb | 4 +--- test/models/lookup_value_test.rb | 13 ------------- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/host_edit_interfaces.js b/app/assets/javascripts/host_edit_interfaces.js index c74070d426fc..73fda80f901a 100644 --- a/app/assets/javascripts/host_edit_interfaces.js +++ b/app/assets/javascripts/host_edit_interfaces.js @@ -217,7 +217,6 @@ function update_interface_row(row, interface_form) { function update_interface_table() { $.each(active_interface_forms(), function(index, form) { var interface_id = $(form).data('interface-id'); - var interface_row = get_interface_row(interface_id); var interface_hidden = get_interface_hidden(interface_id); @@ -391,9 +390,7 @@ $(document).on('change', '.virtual', function() { function construct_host_name() { var host_name_el = $('#host_name') var host_name = host_name_el.val(); - if (host_name_el.data('appendDomainNameForHosts') === false || - host_name_el.data('managed') === false - ) { + if (host_name_el.data('managed') === false) { return host_name; } var domain_name = primary_nic_form() diff --git a/app/models/host/base.rb b/app/models/host/base.rb index 2398ef8d42f4..79cba0165052 100644 --- a/app/models/host/base.rb +++ b/app/models/host/base.rb @@ -115,6 +115,7 @@ def dup :domain=, :domain_id=, :domain_name=, :to => :primary_interface attr_writer :updated_virtuals + def updated_virtuals @updated_virtuals ||= [] end @@ -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) diff --git a/app/services/name_synchronizer.rb b/app/services/name_synchronizer.rb index dc00a585d5b4..91715c41c8bb 100644 --- a/app/services/name_synchronizer.rb +++ b/app/services/name_synchronizer.rb @@ -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 diff --git a/app/views/api/v2/hosts/base.json.rabl b/app/views/api/v2/hosts/base.json.rabl index 417623b70925..25558e49ebf6 100644 --- a/app/views/api/v2/hosts/base.json.rabl +++ b/app/views/api/v2/hosts/base.json.rabl @@ -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 diff --git a/app/views/hosts/_form.html.erb b/app/views/hosts/_form.html.erb index 3418ec259a55..54d4f26816da 100644 --- a/app/views/hosts/_form.html.erb +++ b/app/views/hosts/_form.html.erb @@ -32,9 +32,7 @@ <%= text_f f, :name, :size => "col-md-4", :value => name_field(@host), :input_group_btn => randomize_mac_link, :help_inline => _("This value is used also as the host's primary interface name."), - :data => { 'append_domain_name_for_hosts' => Setting[:append_domain_name_for_hosts], - 'managed' => @host.managed? - } + :data => {'managed' => @host.managed?} %> <% if show_organization_tab? %> diff --git a/test/models/lookup_value_test.rb b/test/models/lookup_value_test.rb index 1bfab0e68ab8..3a254e138abd 100644 --- a/test/models/lookup_value_test.rb +++ b/test/models/lookup_value_test.rb @@ -56,19 +56,6 @@ def valid_attrs2 end end - test "can create lookup value if match fqdn= does match existing host" do - as_admin do - Setting[:append_domain_name_for_hosts] = false - 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" - assert_difference('LookupValue.count') do - LookupValue.create!(attrs) - end - end - end - test "can create lookup value if user has matching hostgroup " do attrs = valid_attrs2 # create key outside as_user as_user :one do