From e553bb4ce6cf9b50321bdb25acc3ad15fba942d0 Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 11 Sep 2023 22:57:29 +1000 Subject: [PATCH] Enable merging address in a domain that has flatten set --- app/Http/Controllers/SystemController.php | 9 +++++++++ app/Http/Requests/AddressMerge.php | 6 +++++- app/Models/Address.php | 1 - 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index 6aad27f..2642ad5 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -386,6 +386,15 @@ class SystemController extends Controller ->where('point_id',$o->point_id) ->get(); + if ($o->zone->domain->flatten) + $oo = $oo->merge(Address::withTrashed() + ->whereIn('zone_id',$o->zone->domain->zones->pluck('id')) + ->where('host_id',$o->host_id) + ->where('node_id',$o->node_id) + ->where('point_id',$o->point_id) + ->get() + ); + return view('system/address-merge') ->with('o',$o) ->with('oo',$oo); diff --git a/app/Http/Requests/AddressMerge.php b/app/Http/Requests/AddressMerge.php index 3949b42..7a3b9bf 100644 --- a/app/Http/Requests/AddressMerge.php +++ b/app/Http/Requests/AddressMerge.php @@ -42,7 +42,11 @@ class AddressMerge extends FormRequest $dst = Address::withTrashed()->findOrFail($value); $src = Address::withTrashed()->findOrFail($request->src); - if ($src->ftn !== $dst->ftn) + if ($src->zone->domain->flatten && $dst->zone->domain->flatten) { + if ((! $src->zone->domain->zones->pluck('id')->contains($dst->zone_id)) || (! $dst->zone->domain->zones->pluck('id')->contains($src->zone_id))) + $fail('Source must be Destination\'s domain zone'); + + } elseif ($src->ftn !== $dst->ftn) $fail('Source and Destination must be the same FTN'); }, ], diff --git a/app/Models/Address.php b/app/Models/Address.php index 44974f7..6e46df4 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -535,7 +535,6 @@ class Address extends Model $o = (new self) ->select('addresses.*') ->join('zones',['zones.id'=>'addresses.zone_id']) - //->join('domains',['domains.id'=>'zones.domain_id']) ->when($trashed,function($query) { $query->trashed(); },function($query) {