From 27cdb02b06a56b7884d3441e213060a66f073c5b Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 3 Jun 2024 22:31:38 +1000 Subject: [PATCH] Fixes for saving a new system --- app/Http/Controllers/SystemController.php | 5 ++++- app/Http/Requests/SystemRegisterRequest.php | 7 ++----- resources/views/system/addedit.blade.php | 1 + resources/views/system/home.blade.php | 14 +++++++++----- resources/views/user/system/register.blade.php | 7 ++++++- resources/views/widgets/saved.blade.php | 1 + 6 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 resources/views/widgets/saved.blade.php diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index 5e35ac5..c9eee93 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -45,6 +45,7 @@ class SystemController extends Controller default: $o->pollmode = NULL; } + $o->active = (! is_null($x=$request->validated('active'))) && $x; $o->autohold = FALSE; $o->save(); @@ -60,7 +61,9 @@ class SystemController extends Controller $o->users()->detach(); } - return redirect()->to('system'); + return redirect() + ->to('system/addedit/'.$o->id) + ->with('saved',TRUE); } $o->load(['addresses.zone.domain','addresses.nodes_hub','addresses.system','sessions.domain','sessions.systems']); diff --git a/app/Http/Requests/SystemRegisterRequest.php b/app/Http/Requests/SystemRegisterRequest.php index 6d79482..aa77743 100644 --- a/app/Http/Requests/SystemRegisterRequest.php +++ b/app/Http/Requests/SystemRegisterRequest.php @@ -8,7 +8,6 @@ use Illuminate\Support\Facades\Gate; use Illuminate\Validation\Rule; use App\Classes\FTN\Packet; -use App\Models\Setup; class SystemRegisterRequest extends FormRequest { @@ -19,12 +18,10 @@ class SystemRegisterRequest extends FormRequest */ public function authorize(Request $request) { - if (! $request->post()) + if (! $request->post() || (! $this->route('o'))) return TRUE; - // Cannot claim this site - if ($this->route('o')->id === Setup::findOrFail(config('app.id'))->system_id) - return FALSE; + // @todo Also disallow claiming this hosts system return Gate::allows($this->route('o')->users->count() ? 'update_nn' : 'register',$this->route('o')); } diff --git a/resources/views/system/addedit.blade.php b/resources/views/system/addedit.blade.php index 4721f39..99ec9d0 100644 --- a/resources/views/system/addedit.blade.php +++ b/resources/views/system/addedit.blade.php @@ -14,6 +14,7 @@ use App\Models\Address;

{{ $o->name }}@if($o->setup)*@endif @if($o->setup)* This Host@endif + @includeWhen(session()->has('saved'),'widgets.saved')

@endif diff --git a/resources/views/system/home.blade.php b/resources/views/system/home.blade.php index 9b79890..00d4a31 100644 --- a/resources/views/system/home.blade.php +++ b/resources/views/system/home.blade.php @@ -3,6 +3,10 @@ Systems @endsection +@php +use App\Models\System; +@endphp + @section('content')
@@ -14,12 +18,12 @@

This system is aware of the following systems - @can('create',(new \App\Models\System))(you can register more):@endcan - @can('admin',(new \App\Models\System))(you can add more):@endcan + @can('create',(new System))(you can register more):@endcan + @can('admin',(new System))(you can add more):@endcan

- @if (\App\Models\System::active()->count() === 0) - @can('create',(new \App\Models\System)) + @if (System::active()->count() === 0) + @can('create',(new System))

There are no systems setup, to set up your first.

@else

There are no systems - you need to ask an admin to create one for you.

@@ -40,7 +44,7 @@ - @foreach (\App\Models\System::active()->with(['addresses.zone.domain'])->get() as $oo) + @foreach (System::active()->with(['addresses.zone.domain'])->get() as $oo) {{ $oo->id }} {{ $oo->name }} @if(! $oo->active)[i]@endif diff --git a/resources/views/user/system/register.blade.php b/resources/views/user/system/register.blade.php index 53d479c..f35a567 100644 --- a/resources/views/user/system/register.blade.php +++ b/resources/views/user/system/register.blade.php @@ -4,6 +4,10 @@ Register System @endsection +@php +use App\Models\{Setup,System}; +@endphp + @section('content')
@csrf @@ -22,8 +26,9 @@