From 97b593aeee2b410565bc75ea7eb1aad44e6536a9 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Tue, 25 Feb 2014 22:35:24 +0000 Subject: [PATCH] Fix partial name match on Node search --- Netdisco/Changes | 1 + .../App/Netdisco/Web/Plugin/Search/Node.pm | 50 +++++++++---------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index d20a5e6b..809b93fc 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -4,6 +4,7 @@ * Fix NetBIOS report with search on blank domain * Fix database MAC lookup when MAC not returned by nbtstat + * Fix partial name match on Node search 2.024000 - 2014-02-22 diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm index fbba07b1..aea6d971 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm @@ -80,7 +80,6 @@ ajax '/ajax/content/search/node' => require_login sub { } else { my $set; - my $name = $node; if (param('partial')) { @@ -91,34 +90,35 @@ ajax '/ajax/content/search/node' => require_login sub { ->search_by_name({nbname => $name, @active, @times}); unless ( $set->has_rows ) { - if (my $ip = NetAddr::IP::Lite->new($node)) { - # search_by_ip() will extract cidr notation if necessary - $set = schema('netdisco')->resultset('NodeIp') - ->search_by_ip({ip => $ip, @active, @times}); - } - else { - - if ($name !~ m/%/ and setting('domain_suffix')) { - $name .= setting('domain_suffix') - if index($name, setting('domain_suffix')) == -1; - } - $set = schema('netdisco')->resultset('NodeIp') - ->search_by_dns({dns => $node, @active, @times}); - - # if the user selects Vendor search opt, then - # we'll try the OUI company name as a fallback - if (not $set->has_rows and param('show_vendor')) { - $node = param('q'); + if (my $ip = NetAddr::IP::Lite->new($node)) { + # search_by_ip() will extract cidr notation if necessary $set = schema('netdisco')->resultset('NodeIp') - ->with_times - ->search( - {'oui.company' => { -ilike => "\%$node\%"}, @times}, - {'prefetch' => 'oui'}, - ); + ->search_by_ip({ip => $ip, @active, @times}); + } + else { + if ($name !~ m/%/ and setting('domain_suffix')) { + $name .= setting('domain_suffix') + if index($name, setting('domain_suffix')) == -1; + } + + $set = schema('netdisco')->resultset('NodeIp') + ->search_by_dns({dns => $name, @active, @times}); + + # if the user selects Vendor search opt, then + # we'll try the OUI company name as a fallback + + if (not $set->has_rows and param('show_vendor')) { + $set = schema('netdisco')->resultset('NodeIp') + ->with_times + ->search( + {'oui.company' => { -ilike => "\%$node\%"}, @times}, + {'prefetch' => 'oui'}, + ); + } } } + return unless $set and $set->has_rows; - } $set = $set->search_rs({}, { order_by => 'me.mac' }); template 'ajax/search/node_by_ip.tt', {