Enable demoting and promoting address role

This commit is contained in:
2023-07-06 18:43:32 +10:00
parent 7073fece94
commit 6c75659395
3 changed files with 68 additions and 0 deletions

View File

@@ -373,6 +373,29 @@ class SystemController extends Controller
return redirect()->to(sprintf('ftn/system/addedit/%d',$sid));
}
/**
* Demo an address NC -> node
*
* @param Address $o
* @return \Illuminate\Http\RedirectResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function dem_address(Address $o)
{
// @todo This should be admin of the zone
$this->authorize('admin',$o);
session()->flash('accordion','address');
// Make sure that no other system has this address active.
if ($o->role === Address::NODE_ACTIVE)
return redirect()->back()->withErrors(['demaddress'=>sprintf('%s cannot be demoted any more',$o->ftn3D)]);
$o->role = ($o->role << 1);
$o->save();
return redirect()->to(sprintf('ftn/system/addedit/%d',$o->system_id));
}
/**
* Delete address assigned to a host
*
@@ -515,6 +538,29 @@ class SystemController extends Controller
return view('system.ours');
}
/**
* Promote an address node -> NC
*
* @param Address $o
* @return \Illuminate\Http\RedirectResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function pro_address(Address $o)
{
// @todo This should be admin of the zone
$this->authorize('admin',$o);
session()->flash('accordion','address');
// Make sure that no other system has this address active.
if ($o->role === Address::NODE_NC)
return redirect()->back()->withErrors(['proaddress'=>sprintf('%s cannot be promoted any more',$o->ftn3D)]);
$o->role = ($o->role >> 1);
$o->save();
return redirect()->to(sprintf('ftn/system/addedit/%d',$o->system_id));
}
/**
* Suspend address assigned to a host
*