Fix address_add validation, missing scoped to zone. Change to use shortform of $request->post() in address_add()
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 37s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m43s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s

This commit is contained in:
Deon George 2024-05-05 22:47:33 +10:00
parent 7540ddf8f4
commit c8ef7d065b

View File

@ -86,27 +86,30 @@ class SystemController extends Controller
'zone_id' => 'required|exists:zones,id', 'zone_id' => 'required|exists:zones,id',
]); ]);
switch ($request->post('action')) { switch ($request->action) {
case 'region': case 'region':
$request->validate([ $request->validate([
'region_id_new' => [ 'region_id_new' => [
'required', 'required',
new TwoByteInteger, new TwoByteInteger,
function ($attribute,$value,$fail) { function ($attribute,$value,$fail) use ($request) {
// Check that the region doesnt already exist // Check that the region doesnt already exist
$o = Address::where(function($query) use ($value) { $o = Address::where(function($query) use ($value) {
return $query->where('region_id',$value) return $query->where(function($query) use ($value) {
->where('host_id',0) return $query
->where('node_id',0) ->where('region_id',$value)
->where('point_id',0)
->where('role',Address::NODE_RC); ->where('role',Address::NODE_RC);
}) })
// Check that a host doesnt already exist // Check that a host doesnt already exist
->orWhere(function($query) use ($value) { ->orWhere(function($query) use ($value) {
return $query->where('host_id',$value) return $query
->where('point_id',0) ->where('host_id',$value)
->where('role',Address::NODE_NC); ->where('role',Address::NODE_NC);
}); });
})
->where('zone_id',$request->zone_id)
->where('node_id',0)
->where('point_id',0);
if ($o->count()) { if ($o->count()) {
$fail('Region or host already exists'); $fail('Region or host already exists');
@ -116,9 +119,9 @@ class SystemController extends Controller
]); ]);
$oo = new Address; $oo = new Address;
$oo->zone_id = $request->post('zone_id'); $oo->zone_id = $request->zone_id;
$oo->region_id = $request->post('region_id_new'); $oo->region_id = $request->region_id_new;
$oo->host_id = 0; $oo->host_id = $request->region_id_new;
$oo->node_id = 0; $oo->node_id = 0;
$oo->point_id = 0; $oo->point_id = 0;
$oo->role = Address::NODE_RC; $oo->role = Address::NODE_RC;
@ -137,18 +140,19 @@ class SystemController extends Controller
// Check that the region doesnt already exist // Check that the region doesnt already exist
$o = Address::where(function($query) use ($value) { $o = Address::where(function($query) use ($value) {
return $query->where(function($query) use ($value) { return $query->where(function($query) use ($value) {
return $query->where('region_id',$value) return $query
->where('region_id',$value)
->where('role',Address::NODE_RC); ->where('role',Address::NODE_RC);
}) })
// Check that a host doesnt already exist // Check that a host doesnt already exist
->orWhere(function($query) use ($value) { ->orWhere(function($query) use ($value) {
return $query->where('host_id',$value) return $query
->where('host_id',$value)
->where('role',Address::NODE_NC); ->where('role',Address::NODE_NC);
}); });
}) })
->where('zone_id',$request->post('zone_id')) ->where('zone_id',$request->zone_id)
->where('point_id',0) ->where('point_id',0);
->where('active',TRUE);
if ($o->count()) { if ($o->count()) {
$fail('Region or host already exists'); $fail('Region or host already exists');
@ -162,7 +166,8 @@ class SystemController extends Controller
// Check that the region doesnt already exist // Check that the region doesnt already exist
$o = Address::where(function($query) use ($request,$value) { $o = Address::where(function($query) use ($request,$value) {
return $query return $query
->where('host_id',$request->post('host_id_new')) ->where('zone_id',$request->zone_id)
->where('host_id',$request->host_id_new)
->where('node_id',$value) ->where('node_id',$value)
->where('point_id',0) ->where('point_id',0)
->where('role',Address::NODE_RC); ->where('role',Address::NODE_RC);
@ -202,10 +207,10 @@ class SystemController extends Controller
$o->addresses()->save($oo); $o->addresses()->save($oo);
$oo = new Address; $oo = new Address;
$oo->zone_id = $request->post('zone_id'); $oo->zone_id = $request->zone_id;
$oo->region_id = $request->post('region_id'); $oo->region_id = $request->region_id;
$oo->host_id = $request->post('host_id_new'); $oo->host_id = $request->host_id_new;
$oo->node_id = $request->post('node_id_new'); $oo->node_id = $request->node_id_new;
$oo->point_id = 0; $oo->point_id = 0;
$oo->role = Address::NODE_ACTIVE; $oo->role = Address::NODE_ACTIVE;
$oo->active = TRUE; $oo->active = TRUE;
@ -226,11 +231,11 @@ class SystemController extends Controller
// Check that the host doesnt already exist // Check that the host doesnt already exist
$o = Address::where(function($query) use ($request,$value) { $o = Address::where(function($query) use ($request,$value) {
return $query return $query
->where('zone_id',$request->post('zone_id')) ->where('zone_id',$request->zone_id)
->where('host_id',$request->post('host_id')) ->where('host_id',$request->host_id)
->where('node_id',$value) ->where('node_id',$value)
->where('point_id',0) ->where('point_id',0)
->where('id','<>',$request->post('submit')); ->where('id','<>',$request->submit);
}); });
if ($o->count()) { if ($o->count()) {
@ -248,11 +253,11 @@ class SystemController extends Controller
// Check that the host doesnt already exist // Check that the host doesnt already exist
$o = Address::where(function($query) use ($request,$value) { $o = Address::where(function($query) use ($request,$value) {
return $query return $query
->where('zone_id',$request->post('zone_id')) ->where('zone_id',$request->zone_id)
->where('host_id',$request->post('host_id')) ->where('host_id',$request->host_id)
->where('node_id',$request->post('node_id')) ->where('node_id',$request->node_id)
->where('point_id',$value) ->where('point_id',$value)
->where('id','<>',$request->post('submit')); ->where('id','<>',$request->submit);
}); });
if ($o->count()) { if ($o->count()) {
@ -265,23 +270,23 @@ class SystemController extends Controller
'security' => 'required|integer|min:0|max:7', 'security' => 'required|integer|min:0|max:7',
]); ]);
$oo = Address::findOrNew($request->post('submit')); $oo = Address::findOrNew($request->submit);
$oo->zone_id = $request->post('zone_id'); $oo->zone_id = $request->zone_id;
$oo->region_id = $request->post('region_id'); $oo->region_id = $request->region_id;
$oo->host_id = $request->post('host_id'); $oo->host_id = $request->host_id;
$oo->node_id = $request->post('node_id'); $oo->node_id = $request->node_id;
$oo->point_id = $request->post('point_id'); $oo->point_id = $request->point_id;
$oo->hub_id = $request->post('hub_id') > 0 ? $request->post('hub_id') : NULL; $oo->hub_id = $request->hub_id > 0 ? $request->hub_id : NULL;
if (is_null($oo->role)) if (is_null($oo->role))
$oo->role = ((! $oo->point_id) && $request->post('hub')) ? Address::NODE_HC : ($request->post('point_id') ? Address::NODE_POINT : Address::NODE_ACTIVE); $oo->role = ((! $oo->point_id) && $request->hub) ? Address::NODE_HC : ($request->point_id ? Address::NODE_POINT : Address::NODE_ACTIVE);
$oo->security = $request->post('security'); $oo->security = $request->security;
$oo->active = TRUE; $oo->active = TRUE;
$o->addresses()->save($oo); $o->addresses()->save($oo);
break; break;
default: default:
return redirect()->back()->withErrors(['action'=>'Unknown action: '.$request->post('action')]); return redirect()->back()->withErrors(['action'=>'Unknown action: '.$request->action]);
} }
return redirect()->to(sprintf('system/addedit/%d',$o->id)); return redirect()->to(sprintf('system/addedit/%d',$o->id));