diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index f12ca08..d46afb2 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -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 * diff --git a/resources/views/system/addedit.blade.php b/resources/views/system/addedit.blade.php index d2f4652..9468a54 100644 --- a/resources/views/system/addedit.blade.php +++ b/resources/views/system/addedit.blade.php @@ -127,6 +127,12 @@ + @if ((\App\Models\Address::NODE_HC|\App\Models\Address::NODE_ACTIVE) & $oo->role) + + @endif + @if ((\App\Models\Address::NODE_NC|\App\Models\Address::NODE_HC) & $oo->role) + + @endif @endif @endcan @@ -140,6 +146,18 @@ {!! $message !!} @enderror + + @error('demaddress') + + {!! $message !!} + + @enderror + + @error('proaddress') + + {!! $message !!} + + @enderror @endif @can('admin',$o) diff --git a/routes/web.php b/routes/web.php index e8bb1c1..c6ebac7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -77,9 +77,13 @@ Route::middleware(['auth','verified','activeuser'])->group(function () { ->where('o','[0-9]+'); Route::get('ftn/system/deladdress/{o}',[SystemController::class,'del_address']) ->where('o','[0-9]+'); + Route::get('ftn/system/demaddress/{o}',[SystemController::class,'dem_address']) + ->where('o','[0-9]+'); Route::get('ftn/system/delsession/{o}/{zo}',[SystemController::class,'del_session']) ->where('o','[0-9]+') ->where('zo','[0-9]+'); + Route::get('ftn/system/proaddress/{o}',[SystemController::class,'pro_address']) + ->where('o','[0-9]+'); Route::match(['get','post'],'ftn/system/echoarea/{o}',[SystemController::class,'echoareas']) ->where('o','[0-9]+'); Route::match(['get','post'],'ftn/system/filearea/{o}',[SystemController::class,'fileareas'])