From f147b33b60d0b18184e2bd30c9cecd796f89061c Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 17 Jun 2023 19:14:16 +1000 Subject: [PATCH] Dont activate an address if another system has it active --- app/Http/Controllers/SystemController.php | 12 ++++++++++++ resources/views/system/addedit.blade.php | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index 307f637..636ae4c 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -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 [%s]',$o->ftn,url('ftn/system/addedit',$x->system_id),$x->system->name)]); + } + $o->active = (! $o->active); $o->save(); diff --git a/resources/views/system/addedit.blade.php b/resources/views/system/addedit.blade.php index 9b476b9..9c06670 100644 --- a/resources/views/system/addedit.blade.php +++ b/resources/views/system/addedit.blade.php @@ -131,6 +131,12 @@ @endforeach + + @error('susaddress') + + {!! $message !!} + + @enderror @endif @can('admin',$o) @@ -388,6 +394,13 @@ @include('widgets.modal_purge') @endsection +@section('page-css') + +@endsection @section('page-scripts')