#925 implement ignore_deviceports and hide_deviceports
This commit is contained in:
@@ -4,6 +4,7 @@ use Dancer ':syntax';
|
||||
use Dancer::Plugin::DBIC;
|
||||
use Dancer::Plugin::Auth::Extensible;
|
||||
|
||||
use App::Netdisco::Util::Permission 'check_acl_no';
|
||||
use App::Netdisco::Util::Port 'port_reconfig_check';
|
||||
use App::Netdisco::Util::Web (); # for sort_port
|
||||
use App::Netdisco::Web::Plugin;
|
||||
@@ -214,6 +215,35 @@ get '/ajax/content/device/ports' => require_login sub {
|
||||
}
|
||||
}
|
||||
|
||||
# filter out hidden ones
|
||||
if (not param('p_include_hidden')) {
|
||||
my $device_ips = {};
|
||||
map { push @{ $device_ips->{$_->port} }, $_ }
|
||||
$device->device_ips(undef, {prefetch => 'device_port'})->all;
|
||||
|
||||
map { push @{ $device_ips->{$_->port} }, $_ }
|
||||
grep { ! exists $device_ips->{$_->port} }
|
||||
@results;
|
||||
|
||||
foreach my $map (@{ setting('hide_deviceports')}) {
|
||||
next unless ref {} eq ref $map;
|
||||
|
||||
foreach my $key (sort keys %$map) {
|
||||
# lhs matches device, rhs matches port
|
||||
next unless check_acl_no($device, $key);
|
||||
|
||||
PORT: foreach my $port (sort keys %$device_ips) {
|
||||
foreach my $thing (@{ $device_ips->{$port} }) {
|
||||
next unless check_acl_no($thing, $map->{$key});
|
||||
|
||||
@results = grep { $_->port ne $port } @results;
|
||||
next PORT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# sort ports
|
||||
@results = sort { &App::Netdisco::Util::Web::sort_port($a->port, $b->port) } @results;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user