Missing display name for device when device has no DNS

This commit is contained in:
Oliver Gorwits
2016-10-03 16:34:53 +01:00
parent fef940ece5
commit efe7137cd8
2 changed files with 5 additions and 4 deletions

View File

@@ -22,6 +22,7 @@
* Improve security of REMOTE_USER handling (B. Marshall) * Improve security of REMOTE_USER handling (B. Marshall)
* portcontrol and power jobs using device instance instead of IP address * portcontrol and power jobs using device instance instead of IP address
* [#266] netdisco subnet utiiization report div by zero (V. Puchkov) * [#266] netdisco subnet utiiization report div by zero (V. Puchkov)
* Missing display name for device when device has no DNS
2.033006 - 2016-03-20 2.033006 - 2016-03-20

View File

@@ -157,10 +157,10 @@ hook 'before_template' => sub {
get '/device' => require_login sub { get '/device' => require_login sub {
my $q = param('q'); my $q = param('q');
my $schema = schema('netdisco')->resultset('Device'); my $devices = schema('netdisco')->resultset('Device');
# we are passed either dns or ip # we are passed either dns or ip
my $dev = $schema->search({ my $dev = $devices->search({
-or => [ -or => [
\[ 'host(me.ip) = ?' => [ bind_value => $q ] ], \[ 'host(me.ip) = ?' => [ bind_value => $q ] ],
'me.dns' => $q, 'me.dns' => $q,
@@ -174,11 +174,11 @@ get '/device' => require_login sub {
# if passed dns, need to check for duplicates # if passed dns, need to check for duplicates
# and use only ip for q param, if there are duplicates. # and use only ip for q param, if there are duplicates.
my $first = $dev->first; my $first = $dev->first;
my $others = ($schema->search({dns => $first->dns})->count() - 1); my $others = ($devices->search({dns => $first->dns})->count() - 1);
params->{'tab'} ||= 'details'; params->{'tab'} ||= 'details';
template 'device', { template 'device', {
display_name => ($others ? $first->ip : $first->dns), display_name => ($others ? $first->ip : ($first->dns || $first->ip)),
device => params->{'tab'}, device => params->{'tab'},
}; };
}; };