No longer use dns as a key into devices; cope with dupe dns
This commit is contained in:
@@ -154,20 +154,29 @@ hook 'before_template' => sub {
|
||||
|
||||
get '/device' => require_login sub {
|
||||
my $q = param('q');
|
||||
my $dev = schema('netdisco')->resultset('Device')->single({
|
||||
my $schema = schema('netdisco')->resultset('Device');
|
||||
|
||||
# we are passed either dns or ip
|
||||
my $dev = $schema->search({
|
||||
-or => [
|
||||
\[ 'host(me.ip) = ?' => [ bind_value => $q ] ],
|
||||
'me.dns' => $q,
|
||||
],
|
||||
});
|
||||
|
||||
if (!defined $dev) {
|
||||
if ($dev->count == 0) {
|
||||
return redirect uri_for('/', {nosuchdevice => 1})->path_query;
|
||||
}
|
||||
|
||||
# if passed dns, need to check for duplicates
|
||||
# and use only ip for q param, if there are duplicates.
|
||||
my $first = $dev->first;
|
||||
my $others = ($schema->search({dns => $first->dns})->count() - 1);
|
||||
|
||||
params->{'tab'} ||= 'details';
|
||||
template 'device', {
|
||||
d => $dev,
|
||||
display_name => ($others ? $first->ip : $first->dns),
|
||||
device => params->{'tab'},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -19,13 +19,15 @@ get '/ajax/content/search/device' => require_login sub {
|
||||
my $set;
|
||||
|
||||
if ($has_opt) {
|
||||
$set = schema('netdisco')->resultset('Device')->search_by_field(scalar params);
|
||||
$set = schema('netdisco')->resultset('Device')
|
||||
->with_times->search_by_field(scalar params);
|
||||
}
|
||||
else {
|
||||
my $q = param('q');
|
||||
send_error('Missing query', 400) unless $q;
|
||||
|
||||
$set = schema('netdisco')->resultset('Device')->search_fuzzy($q);
|
||||
$set = schema('netdisco')->resultset('Device')
|
||||
->with_times->search_fuzzy($q);
|
||||
}
|
||||
return unless $set->count;
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ get '/search' => require_login sub {
|
||||
# redirect to device details for the one device
|
||||
return redirect uri_for('/device', {
|
||||
tab => 'details',
|
||||
q => ($nd->first->dns || $nd->first->ip),
|
||||
q => $nd->first->ip,
|
||||
f => '',
|
||||
})->path_query;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user