Start of echomail subscribing

This commit is contained in:
Deon George
2021-08-25 22:13:49 +10:00
parent 97384ce3a0
commit 8306f4c3a3
8 changed files with 403 additions and 186 deletions

View File

@@ -2,10 +2,11 @@
namespace App\Http\Controllers;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use App\Models\{Address,System,SystemZone,Zone};
use App\Models\{Address,Echoarea,System,SystemZone,Zone};
use App\Rules\{FidoInteger,TwoByteInteger};
class SystemController extends Controller
@@ -27,7 +28,7 @@ class SystemController extends Controller
{
// @todo This should be admin of the zone
$this->authorize('admin',$o);
session()->flash('add_address',TRUE);
session()->flash('accordion','address');
$request->validate([
'action' => 'required|in:region,host,node',
@@ -222,7 +223,7 @@ class SystemController extends Controller
{
// @todo This should be admin of the zone
$this->authorize('admin',$o);
session()->flash('add_session',TRUE);
session()->flash('accordion','session');
$validate = $request->validate([
'zone_id' => 'required|exists:zones,id',
@@ -293,7 +294,7 @@ class SystemController extends Controller
{
// @todo This should be admin of the zone
$this->authorize('admin',$o);
session()->flash('add_address',TRUE);
session()->flash('accordion','address');
$sid = $o->system_id;
$o->active = FALSE;
@@ -313,13 +314,46 @@ class SystemController extends Controller
public function del_session(System $o,Zone $zo)
{
$this->authorize('admin',$zo);
session()->flash('add_session',TRUE);
session()->flash('accordion','session');
$o->sessions()->detach($zo);
return redirect()->to(sprintf('ftn/system/addedit/%d',$o->id));
}
/**
* Update the systems echoareas
*
* @param Request $request
* @param System $o
*/
public function echoareas(Request $request,System $o)
{
$ao = $o->addresses->filter(function($item) use ($request) { return $item->zone->domain_id == $request->domain_id; })->first();
if (($request->method() == 'POST') && $request->post()) {
session()->flash('accordion','echoarea');
// 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->id,['subscribed'=>Carbon::now()]);
return redirect()->back()->with('success','Echoareas updated');;
}
$eo = Echoarea::active()
->where('domain_id',$request->domain_id)
->orderBy('name')
->get();
return view('system.widget.echoarea')
->with('o',$o)
->with('ao',$ao)
->with('echoareas',$eo);
}
/**
* Move address to another system
*
@@ -331,6 +365,8 @@ class SystemController extends Controller
*/
public function mov_address(Request $request,System $so,Address $o)
{
session()->flash('accordion','address');
// Quick check that this address belongs to this system
if ($so->addresses->search(function($item) use ($o) { return $item->id == $o->id; }) === FALSE)
abort(404);
@@ -378,7 +414,7 @@ class SystemController extends Controller
{
// @todo This should be admin of the zone
$this->authorize('admin',$o);
session()->flash('add_address',TRUE);
session()->flash('accordion','address');
$o->active = (! $o->active);
$o->save();

View File

@@ -109,6 +109,12 @@ class Address extends Model
->with(['zone.domain']);
}
public function echoareas()
{
return $this->belongsToMany(Echoarea::class)
->withPivot(['subscribed']);
}
/**
* Who we send this systems mail to.
*

View File

@@ -72,6 +72,14 @@ class System extends Model
/* METHODS */
public function echoareas()
{
return Echoarea::select('echoareas.*')
->join('address_echoarea',['address_echoarea.echoarea_id'=>'echoareas.id'])
->join('addresses',['addresses.id'=>'address_echoarea.address_id'])
->where('addresses.system_id',$this->id);
}
/**
* Return the system's address in the same zone
*