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 14, 2023
1 parent 9519609 commit 837f7b8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 22 deletions.
5 changes: 1 addition & 4 deletions app/assets/javascripts/host_edit_interfaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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()
Expand Down
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: 1 addition & 3 deletions app/views/hosts/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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? %>
Expand Down
13 changes: 0 additions & 13 deletions test/models/lookup_value_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 837f7b8

Please sign in to comment.