From 4c4c44fdb3702fc80672da638a4e8d166f8c1c1f 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/models/host/base.rb | 9 +++++++++ app/views/api/v2/hosts/base.json.rabl | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/models/host/base.rb b/app/models/host/base.rb index 2398ef8d42f4..01a0a511002e 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.to_s + else + name.to_s.split('.')[0] + end + end + private def parse_ip_address(address, ignore_link_local: true) diff --git a/app/views/api/v2/hosts/base.json.rabl b/app/views/api/v2/hosts/base.json.rabl index 417623b70925..b3412d283e0e 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 \ No newline at end of file