Dont activate an address if another system has it active

This commit is contained in:
2023-06-17 19:14:16 +10:00
parent e3f2d6cf15
commit f147b33b60
2 changed files with 25 additions and 0 deletions

View File

@@ -528,6 +528,18 @@ class SystemController extends Controller
$this->authorize('admin',$o);
session()->flash('accordion','address');
// Make sure that no other system has this address active.
if (! $o->active && ($x=Address::where([
'zone_id'=>$o->zone_id,
'host_id'=>$o->host_id,
'node_id'=>$o->node_id,
'point_id'=>$o->point_id,
'active'=>TRUE,
])->single())) {
return redirect()->back()->withErrors(['susaddress'=>sprintf('%s is already active on system [<a href="%s">%s</a>]',$o->ftn,url('ftn/system/addedit',$x->system_id),$x->system->name)]);
}
$o->active = (! $o->active);
$o->save();