From 628293c741303d683310efb9694f648a213c9696 Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 16 Aug 2021 22:26:33 +1000 Subject: [PATCH] Enable default zones for 4d systems --- app/Http/Controllers/ZoneController.php | 11 ++++- app/Models/Address.php | 4 +- .../2021_08_15_134329_default_zones.php | 42 ++++++++++++++++ resources/views/zone/addedit.blade.php | 48 +++++++++++++------ resources/views/zone/home.blade.php | 4 +- 5 files changed, 91 insertions(+), 18 deletions(-) create mode 100644 database/migrations/2021_08_15_134329_default_zones.php diff --git a/app/Http/Controllers/ZoneController.php b/app/Http/Controllers/ZoneController.php index 17babe0..97824e3 100644 --- a/app/Http/Controllers/ZoneController.php +++ b/app/Http/Controllers/ZoneController.php @@ -24,6 +24,15 @@ class ZoneController extends Controller $request->validate([ 'domain_id' => 'required|exists:domains,id', + 'default' => [ + 'required', + 'boolean', + Rule::unique('zones')->where(function ($query) use ($request,$o) { + return $query->where('zone_id',$request->post('zone_id')) + ->where('default',TRUE) + ->where('id','<>',$o->id);; + }) + ], 'zone_id' => [ 'required', 'digits_between:1,5', @@ -59,7 +68,7 @@ class ZoneController extends Controller 'active' => 'required|boolean', ]); - foreach (['zone_id','domain_id','system_id','active','notes','zt_id','zt_ipv4','zt_ipv4_mask','zt_ipv6','zt_ipv6_mask'] as $key) + foreach (['zone_id','default','domain_id','system_id','active','notes','zt_id','zt_ipv4','zt_ipv4_mask','zt_ipv6','zt_ipv6_mask'] as $key) $o->{$key} = $request->post($key); $o->save(); diff --git a/app/Models/Address.php b/app/Models/Address.php index a93e410..620d943 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -273,7 +273,7 @@ class Address extends Model $query->where('domains.name',$domain); }) ->when((! $ftn['d']),function($query) { - $query->where('domains.default',TRUE); + $query->where('zones.default',TRUE); }) ->single(); @@ -296,7 +296,7 @@ class Address extends Model $query->where('domains.name',$domain); }) ->when((! $ftn['d']),function($query) { - $query->where('domains.default',TRUE); + $query->where('zones.default',TRUE); }) ->single(); diff --git a/database/migrations/2021_08_15_134329_default_zones.php b/database/migrations/2021_08_15_134329_default_zones.php new file mode 100644 index 0000000..1d03a5a --- /dev/null +++ b/database/migrations/2021_08_15_134329_default_zones.php @@ -0,0 +1,42 @@ +dropColumn('default'); + }); + + Schema::table('zones', function (Blueprint $table) { + $table->boolean('default')->default(FALSE); + $table->unique(['zone_id','default']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('zones', function (Blueprint $table) { + $table->dropUnique(['zone_id','default']); + $table->dropColumn('default'); + }); + + Schema::table('zones', function (Blueprint $table) { + $table->boolean('default')->default(FALSE); + }); + } +} diff --git a/resources/views/zone/addedit.blade.php b/resources/views/zone/addedit.blade.php index 4ed1dec..367f5a9 100644 --- a/resources/views/zone/addedit.blade.php +++ b/resources/views/zone/addedit.blade.php @@ -50,7 +50,40 @@ -
+
+ +
+
+ default))checked @endif> + + + default))checked @endif> + +
+ + @error('default') + {{ $message }} + @enderror + +
+
+ +
+ +
+
+ active))checked @endif> + + + active))checked @endif> + +
+
+
+
+ +
+
@@ -70,19 +103,6 @@ Add a NEW System. This system is the primary mailer/tosser responsible for managing the zone.
- -
- -
-
- active))checked @endif> - - - active))checked @endif> - -
-
-
diff --git a/resources/views/zone/home.blade.php b/resources/views/zone/home.blade.php index f517693..19f7929 100644 --- a/resources/views/zone/home.blade.php +++ b/resources/views/zone/home.blade.php @@ -15,7 +15,7 @@
-
+
@if (\App\Models\Zone::count() == 0) @can('admin',(new \App\Models\Zone))

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

@@ -29,6 +29,7 @@ Domain Zone Active + Default Systems @@ -39,6 +40,7 @@ {{ $oo->domain->name }} {{ $oo->zone_id }} {{ $oo->active ? 'YES' : 'NO' }} + {{ $oo->default ? 'YES' : 'NO' }} {{ $oo->addresses->count() }} @endforeach