More complete rework of packet parsing and packet generation with 29710c

This commit is contained in:
2024-05-19 23:28:45 +10:00
parent 46f52dd56d
commit f279d85b08
43 changed files with 412 additions and 291 deletions

View File

@@ -16,7 +16,7 @@ use Illuminate\Support\Facades\Notification;
use Illuminate\Support\ViewErrorBag;
use App\Classes\FTN\Message;
use App\Http\Requests\{AddressMerge,AreafixRequest,SystemRegister,SystemSessionRequest};
use App\Http\Requests\{AddressMerge,AreafixRequest,SystemEchoareaRequest,SystemRegister,SystemSessionRequest};
use App\Jobs\AddressPoll;
use App\Models\{Address,Echoarea,Echomail,Filearea,Netmail,Setup,System,Zone};
use App\Notifications\Netmails\AddressLink;
@@ -694,30 +694,20 @@ class SystemController extends Controller
/**
* Update the systems echoareas
*
* @param Request $request
* @param SystemEchoareaRequest $request
* @param System $o
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
*/
public function echoareas(Request $request,System $o)
public function echoareas(SystemEchoareaRequest $request,System $o)
{
$ao = $o->addresses->firstWhere('id',$request->address_id);
if (($request->method() === 'POST') && $request->post()) {
session()->flash('accordion','echoarea');
if ($ao->trashed() && collect($request->get('id'))->diff($ao->echoareas->pluck('id'))->count())
return redirect()->back()->withErrors(sprintf('Address [%s] has been deleted, cannot add additional echos',$ao->ftn3d));
// Ensure we have session details for this address.
if (! $ao->session('sespass'))
return redirect()->back()->withErrors('System doesnt belong to this network');
$ao->echoareas()->syncWithPivotValues($request->get('id',[]),['subscribed'=>Carbon::now()]);
if (($request->method() === 'POST') && $request->validated()) {
$ao->echoareas()->syncWithPivotValues($request->validated('id',[]),['subscribed'=>Carbon::now()]);
return redirect()->back()->with('success','Echoareas updated');
}
// @todo Allow a NC/RC/ZC to override
$eo = Echoarea::active()
->where('domain_id',$ao->zone->domain_id)
->where(function($query) use ($ao) {
@@ -869,7 +859,7 @@ class SystemController extends Controller
*/
public function session_del(System $o,Zone $zo)
{
$this->authorize('admin',$zo);
$this->authorize('update_nn',$o);
session()->flash('accordion','session');
$o->sessions()->detach($zo);

View File

@@ -0,0 +1,71 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use App\Models\Domain;
/**
* Validation to register echoareas for a system
* o = System::class
*
* @note This validation only expects to be used with POST
* Variables:
* + "address_id" => "address" // address_id that will receive the echos
* + "domain_id" => "domain" // Of the echoareas
* + "id" => array of IDs // The echos being subscribed (or if absent, are removed)
*
* Rules:
* @see AddressAdd::class for description of authorisation
*/
class SystemEchoareaRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return request()->isMethod('get')
|| Gate::allows('update_nn',$this->route('o'));
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(Request $request): array
{
if (request()->isMethod('get'))
return [];
session()->flash('accordion','echoarea');
return [
'address_id'=>[
'exists:addresses,id',
// Make sure we have session details for the area
function ($attribute,$value,$fail) use ($request) {
$ao = request()->route('o')->addresses->firstWhere('id',$request->address_id);
if ((! $ao) || (! $ao->active) || (! $ao->system->zones->pluck('domain_id')->contains($request->domain_id)))
$fail('Address must be ACTIVE, and have session details for the domain');
},
],
'domain_id'=>'exists:domains,id',
'id'=>[
'array',
'min:1',
// Make sure the echoareas are in the domain
function ($attribute,$value,$fail) use ($request) {
$do = Domain::findOrFail($request->domain_id);
if ($do->echoareas->pluck('id')->intersect($value)->count() !== count($value))
$fail('Some echaoreas dont exist in the domain?');
},
]
];
}
}