mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
API Fix error when no fdb are found (#10125)
* Fix error when no fdb are found * actually, it was totally broken... fix untested * missing device update * cleanup * Update api_functions.inc.php
This commit is contained in:
@@ -534,6 +534,11 @@ class Device extends BaseModel
|
||||
return $this->hasMany('App\Models\Port', 'device_id', 'device_id');
|
||||
}
|
||||
|
||||
public function portsFdb()
|
||||
{
|
||||
return $this->hasMany('App\Models\PortsFdb', 'device_id', 'device_id');
|
||||
}
|
||||
|
||||
public function portsNac()
|
||||
{
|
||||
return $this->hasMany('App\Models\PortsNac', 'device_id', 'device_id');
|
||||
|
||||
@@ -2050,8 +2050,13 @@ function get_fdb()
|
||||
}
|
||||
check_device_permission($device_id);
|
||||
|
||||
$fdb = \App\Models\PortsFdb::find($device_id);
|
||||
api_success($fdb, 'ports_fdb');
|
||||
$device = \App\Models\Device::find($device_id);
|
||||
if ($device) {
|
||||
$fdb = $device->portsFdb;
|
||||
api_success($fdb, 'ports_fdb');
|
||||
}
|
||||
|
||||
api_error(404, 'Device does not exist');
|
||||
}
|
||||
|
||||
|
||||
@@ -2063,13 +2068,13 @@ function list_fdb()
|
||||
$router = $app->router()->getCurrentRoute()->getParams();
|
||||
$mac = $router['mac'];
|
||||
|
||||
if (empty($mac)) {
|
||||
$fdb = \App\Models\PortsFdb::hasAccess(Auth::user())->get();
|
||||
} else {
|
||||
$fdb = \App\Models\PortsFdb::find($mac);
|
||||
}
|
||||
$total_fdb = $fdb->count();
|
||||
if ($total_fdb == 0) {
|
||||
$fdb = \App\Models\PortsFdb::hasAccess(Auth::user())
|
||||
->when(!empty($mac), function ($query) use ($mac) {
|
||||
return $query->where('mac_address', $mac);
|
||||
})
|
||||
->get();
|
||||
|
||||
if ($fdb->isEmpty()) {
|
||||
api_error(404, 'Fdb do not exist');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user