Rework address roles, making Address::role optional, rework determining uplink/downlinks/parent/children

This commit is contained in:
2024-05-09 21:22:30 +10:00
parent 2765a27db8
commit 23159d19d5
23 changed files with 667 additions and 421 deletions

View File

@@ -76,7 +76,6 @@ class SystemController extends Controller
*/
public function address_add(Request $request,System $o)
{
// @todo a point address is failing validation
// @todo This should be admin of the zone
$this->authorize('admin',$o);
session()->flash('accordion','address');
@@ -124,7 +123,6 @@ class SystemController extends Controller
$oo->host_id = $request->region_id_new;
$oo->node_id = 0;
$oo->point_id = 0;
$oo->role = Address::NODE_RC;
$oo->active = TRUE;
$o->addresses()->save($oo);
@@ -152,6 +150,7 @@ class SystemController extends Controller
});
})
->where('zone_id',$request->zone_id)
->where('node_id',$request->node_id_new)
->where('point_id',0);
if ($o->count()) {
@@ -212,7 +211,6 @@ class SystemController extends Controller
$oo->host_id = $request->host_id_new;
$oo->node_id = $request->node_id_new;
$oo->point_id = 0;
$oo->role = Address::NODE_ACTIVE;
$oo->active = TRUE;
$o->addresses()->save($oo);
@@ -276,9 +274,8 @@ class SystemController extends Controller
$oo->host_id = $request->host_id;
$oo->node_id = $request->node_id;
$oo->point_id = $request->point_id;
// @todo Validation should check that the hub is in the right region and net
$oo->hub_id = $request->hub_id > 0 ? $request->hub_id : NULL;
if (is_null($oo->role))
$oo->role = ((! $oo->point_id) && $request->hub) ? Address::NODE_HC : ($request->point_id ? Address::NODE_POINT : Address::NODE_ACTIVE);
$oo->security = $request->security;
$oo->active = TRUE;
@@ -327,10 +324,13 @@ class SystemController extends Controller
session()->flash('accordion','address');
// Make sure that no other system has this address active.
if ($o->role === Address::NODE_ACTIVE)
if ($o->role_id === Address::NODE_NN)
return redirect()->back()->withErrors(['address'=>sprintf('%s cannot be demoted any more',$o->ftn3D)]);
$o->role = ($o->role << 1);
$off = $o->role_id;
$o->role &= ~$off;
$o->role |= ($off << 1);
$o->save();
return redirect()->to(sprintf('system/addedit/%d',$o->system_id));
@@ -502,10 +502,13 @@ class SystemController extends Controller
session()->flash('accordion','address');
// Make sure that no other system has this address active.
if ($o->role === Address::NODE_NC)
if ($o->role_id === Address::NODE_NC)
return redirect()->back()->withErrors(['address'=>sprintf('%s cannot be promoted any more',$o->ftn3D)]);
$o->role = ($o->role >> 1);
$off = $o->role_id;
$o->role &= ~$off;
$o->role |= ($off >> 1);
$o->save();
return redirect()->to(sprintf('system/addedit/%d',$o->system_id));