Enable default zones for 4d systems

This commit is contained in:
Deon George 2021-08-16 22:26:33 +10:00
parent 111461e515
commit 628293c741
5 changed files with 91 additions and 18 deletions

View File

@ -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();

View File

@ -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();

View File

@ -0,0 +1,42 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class DefaultZones extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('domains', function (Blueprint $table) {
$table->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);
});
}
}

View File

@ -50,7 +50,40 @@
</div>
</div>
<div class="col-5">
<div class="offset-1 col-2">
<label for="default" class="form-label">Default</label>
<div class="input-group has-validation">
<div class="btn-group @error('default') is-invalid @enderror" role="group">
<input type="radio" class="btn-check " name="default" id="default_yes" value="1" required @cannot('admin',$o)disabled @endcannot @if(old('default',$o->default))checked @endif>
<label class="btn btn-outline-success" for="default_yes">Yes</label>
<input type="radio" class="btn-check btn-danger" name="default" id="default_no" value="0" required @cannot('admin',$o)disabled @endcannot @if(! old('default',$o->default))checked @endif>
<label class="btn btn-outline-danger" for="default_no">No</label>
</div>
<span class="invalid-feedback" role="alert">
@error('default')
{{ $message }}
@enderror
</span>
</div>
</div>
<div class="col-2">
<label for="active" class="form-label">Active</label>
<div class="input-group">
<div class="btn-group" role="group">
<input type="radio" class="btn-check" name="active" id="active_yes" value="1" required @cannot('admin',$o)disabled @endcannot @if(old('active',$o->active))checked @endif>
<label class="btn btn-outline-success" for="active_yes">Yes</label>
<input type="radio" class="btn-check btn-danger" name="active" id="active_no" value="0" required @cannot('admin',$o)disabled @endcannot @if(! old('active',$o->active))checked @endif>
<label class="btn btn-outline-danger" for="active_no">No</label>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-4">
<label for="system" class="form-label">System</label>
<div class="input-group has-validation">
<span class="input-group-text"><i class="bi bi-laptop-fill"></i></span>
@ -70,19 +103,6 @@
<span class="input-helper">Add a <a href="{{ url('ftn/system/addedit') }}">NEW System</a>. This system is the primary mailer/tosser responsible for managing the zone.</span>
</div>
</div>
<div class="col-2">
<label for="active" class="form-label">Active</label>
<div class="input-group">
<div class="btn-group" role="group">
<input type="radio" class="btn-check" name="active" id="active_yes" value="1" required @cannot('admin',$o)disabled @endcannot @if(old('active',$o->active))checked @endif>
<label class="btn btn-outline-success" for="active_yes">Yes</label>
<input type="radio" class="btn-check btn-danger" name="active" id="active_no" value="0" required @cannot('admin',$o)disabled @endcannot @if(! old('active',$o->active))checked @endif>
<label class="btn btn-outline-danger" for="active_no">No</label>
</div>
</div>
</div>
</div>
<div class="row">

View File

@ -15,7 +15,7 @@
</div>
<div class="row">
<div class="col-6">
<div class="col-9">
@if (\App\Models\Zone::count() == 0)
@can('admin',(new \App\Models\Zone))
<p>There are no zones setup, to <a href="{{ url('ftn/zone/addedit') }}">set up your first</a>.</p>
@ -29,6 +29,7 @@
<th>Domain</th>
<th>Zone</th>
<th>Active</th>
<th>Default</th>
<th>Systems</th>
</tr>
</thead>
@ -39,6 +40,7 @@
<td>{{ $oo->domain->name }}</td>
<td><a href="{{ url('ftn/zone/addedit',[$oo->id]) }}">{{ $oo->zone_id }}</a></td>
<td>{{ $oo->active ? 'YES' : 'NO' }}</td>
<td>{{ $oo->default ? 'YES' : 'NO' }}</td>
<td>{{ $oo->addresses->count() }}</td>
</tr>
@endforeach