Added an address merge UI page
This commit is contained in:
parent
234be677f9
commit
ed7dc2ab8b
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
@ -13,7 +14,7 @@ use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Support\ViewErrorBag;
|
||||
|
||||
use App\Classes\FTN\Message;
|
||||
use App\Http\Requests\{AreafixRequest,SystemRegister};
|
||||
use App\Http\Requests\{AddressMerge,AreafixRequest,SystemRegister};
|
||||
use App\Jobs\AddressPoll;
|
||||
use App\Models\{Address,Echoarea,Filearea,Netmail,Setup,System,SystemZone,Zone};
|
||||
use App\Notifications\Netmails\AddressLink;
|
||||
@ -315,6 +316,81 @@ class SystemController extends Controller
|
||||
->with('o',$o);
|
||||
}
|
||||
|
||||
public function address_merge(AddressMerge $request,int $id)
|
||||
{
|
||||
if ($request->validated()) {
|
||||
DB::beginTransaction();
|
||||
|
||||
// Find all echomail seenbys
|
||||
$x = DB::update('update echomail_seenby set address_id=? where address_id=?',[$request->dst,$request->src]);
|
||||
|
||||
// Find all echomail paths
|
||||
$x = DB::update('update echomail_path set address_id=? where address_id=?',[$request->dst,$request->src]);
|
||||
|
||||
// Find all echomails
|
||||
$x = DB::update('update echomails set fftn_id=? where fftn_id=?',[$request->dst,$request->src]);
|
||||
|
||||
// Find all netmails
|
||||
$x = DB::update('update netmails set fftn_id=? where fftn_id=?',[$request->dst,$request->src]);
|
||||
|
||||
// Find all netmails
|
||||
$x = DB::update('update netmails set tftn_id=? where tftn_id=?',[$request->dst,$request->src]);
|
||||
|
||||
// Find all nodelist
|
||||
$x = DB::update('update address_nodelist set address_id=? where address_id=?',[$request->dst,$request->src]);
|
||||
|
||||
// Find all file seenbys
|
||||
$x = DB::update('update file_seenby set address_id=? where address_id=?',[$request->dst,$request->src]);
|
||||
|
||||
// Find all files
|
||||
$x = DB::update('update files set fftn_id=? where fftn_id=?',[$request->dst,$request->src]);
|
||||
|
||||
$src = Address::withTrashed()->findOrFail($request->src);
|
||||
|
||||
// Resubscribe echoareas
|
||||
try {
|
||||
$x = DB::update('update address_echoarea set address_id=? where address_id=?',[$request->dst,$request->src]);
|
||||
|
||||
} catch (QueryException $e) {
|
||||
DB::rollback();
|
||||
|
||||
return back()->withInput()->withErrors('error',sprintf('You may need to remove %s:%s (%d) from echoareas',$src->ftn,$src->system->name,$src->id));
|
||||
}
|
||||
|
||||
// Resubscribe fileareas
|
||||
try {
|
||||
$x = DB::update('update address_filearea set address_id=? where address_id=?',[$request->dst,$request->src]);
|
||||
|
||||
} catch (QueryException $e) {
|
||||
DB::rollback();
|
||||
|
||||
return back()->withInput()->withErrors('error',sprintf('You may need to remove %s:%s (%d) from fileareas',$src->ftn,$src->system->name,$src->id));
|
||||
}
|
||||
|
||||
if ($src->forceDelete()) {
|
||||
DB::commit();
|
||||
return redirect()->to('address/merge/'.$request->dst);
|
||||
|
||||
} else {
|
||||
return back()->withInput()->withErrors('error',sprintf('Address [%s] didnt delete?',$src->ftn));
|
||||
DB::rollBack();
|
||||
}
|
||||
}
|
||||
$o = Address::withTrashed()
|
||||
->findOrFail($id);
|
||||
|
||||
$oo = Address::withTrashed()
|
||||
->where('zone_id',$o->zone_id)
|
||||
->where('host_id',$o->host_id)
|
||||
->where('node_id',$o->node_id)
|
||||
->where('point_id',$o->point_id)
|
||||
->get();
|
||||
|
||||
return view('system/address-merge')
|
||||
->with('o',$o)
|
||||
->with('oo',$oo);
|
||||
}
|
||||
|
||||
public function api_address(Request $request,System $o): Collection
|
||||
{
|
||||
return Address::select(['addresses.id','addresses.zone_id','region_id','host_id','node_id','point_id'])
|
||||
|
51
app/Http/Requests/AddressMerge.php
Normal file
51
app/Http/Requests/AddressMerge.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
use App\Models\Address;
|
||||
|
||||
class AddressMerge extends FormRequest
|
||||
{
|
||||
protected $stopOnFirstFailure = TRUE;
|
||||
|
||||
public function authorize()
|
||||
{
|
||||
return Gate::allows( 'admin');
|
||||
}
|
||||
|
||||
public function rules(Request $request)
|
||||
{
|
||||
if (! $request->isMethod('post'))
|
||||
return [];
|
||||
|
||||
return [
|
||||
'src' => [
|
||||
'required',
|
||||
'exists:addresses,id',
|
||||
],
|
||||
'dst' => [
|
||||
'required',
|
||||
'exists:addresses,id',
|
||||
'different:src',
|
||||
function ($attribute,$value,$fail) use ($request) {
|
||||
$dst = Address::withTrashed()->findOrFail($value);
|
||||
$src = Address::withTrashed()->findOrFail($request->src);
|
||||
|
||||
if ((! $dst->active) && ($dst->system_id !== $src->system_id) && ($src->system->name !== 'Discovered System'))
|
||||
$fail('Destination must be active, or be from the system system');
|
||||
},
|
||||
function ($attribute,$value,$fail) use ($request) {
|
||||
$dst = Address::withTrashed()->findOrFail($value);
|
||||
$src = Address::withTrashed()->findOrFail($request->src);
|
||||
|
||||
if ($src->ftn !== $dst->ftn)
|
||||
$fail('Source and Destination must be the same FTN');
|
||||
},
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
12
resources/views/error.blade.php
Normal file
12
resources/views/error.blade.php
Normal file
@ -0,0 +1,12 @@
|
||||
<span class="col-6 mt-auto mx-auto text-center align-bottom">
|
||||
@if($errors->count())
|
||||
<span class="btn btn-sm btn-danger" role="alert">
|
||||
There were errors with the submission.
|
||||
<ul>
|
||||
@foreach($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</span>
|
||||
@endif
|
||||
</span>
|
70
resources/views/system/address-merge.blade.php
Normal file
70
resources/views/system/address-merge.blade.php
Normal file
@ -0,0 +1,70 @@
|
||||
<!-- $o=Address::class -->
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('htmlheader_title')
|
||||
Address Merge
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="row pt-0">
|
||||
<div class="col-12">
|
||||
<h2>Merge Address {{ $o->ftn }}</h2>
|
||||
<p>{{ $o->system->sysop }} : {{ $o->system->name }}</p>
|
||||
</div>
|
||||
|
||||
<div class="col-12">
|
||||
<form method="POST">
|
||||
@csrf
|
||||
|
||||
<table class="table monotable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>F</th>
|
||||
<th>T</th>
|
||||
<th>ID</th>
|
||||
<th>FTN</th>
|
||||
<th>ACTIVE</th>
|
||||
<th>Messages</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
@foreach ($oo as $ao)
|
||||
<tr>
|
||||
<td><input type="radio" name="src" value="{{ $ao->id }}"></td>
|
||||
<td><input type="radio" name="dst" value="{{ $ao->id }}"></td>
|
||||
<th>{{ $ao->id }} {{ $ao->system_id }}:<a href="{{ url('ftn/system/addedit',$ao->system_id) }}">{{ $ao->system->name }}</a></th>
|
||||
<th>{{ $ao->ftn }}</th>
|
||||
<td>
|
||||
@if($ao->trashed())
|
||||
<a href="{{ url('ftn/system/recaddress',[$ao->id]) }}" title="Restore Address"><i class="bi bi-bandaid"></i></a>
|
||||
<a href="{{ url('ftn/system/puraddress',[$ao->id]) }}" title="Purge Address" class="purge"><i class="bi bi-scissors"></i></a>
|
||||
@else
|
||||
<a href="{{ url('ftn/system/susaddress',[$ao->id]) }}" title="@if($ao->active)Pause @else Activate @endif Address"><i class="bi @if($ao->active)bi-pause-circle @else bi-play-circle @endif"></i></a>
|
||||
<a href="{{ url('ftn/system/movaddress',[$ao->system_id,$ao->id]) }}" title="Move Address to another System"><i class="bi bi-arrow-right-square"></i></a>
|
||||
<a href="{{ url('ftn/system/deladdress',[$ao->id]) }}" title="Delete Address"><i class="bi bi-trash"></i></a>
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
<ul>
|
||||
@foreach(\App\Models\Echomail::select(['id','msgid','from','msg'])
|
||||
->where('fftn_id',$ao->id)
|
||||
->orderBy('created_at','DESC')
|
||||
->limit(5)
|
||||
->get() as $eo)
|
||||
<li class="pb-4">{{ sprintf('%04d: %s (%s) %s',$eo->id,$eo->from,$eo->msgid,$eo->msg) }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<button type="submit" name="submit" class="btn btn-success float-end">Merge</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@include('error')
|
||||
</div>
|
||||
@endsection
|
@ -129,6 +129,7 @@ Route::middleware(['auth','verified','activeuser'])->group(function () {
|
||||
});
|
||||
|
||||
Route::middleware(['auth','can:admin'])->group(function () {
|
||||
Route::match(['get','post'],'address/merge/{id}',[SystemController::class,'address_merge']);
|
||||
Route::get('echomail/view/{o}',[EchomailController::class,'view']);
|
||||
Route::get('netmail/view/{o}',[NetmailController::class,'view']);
|
||||
Route::get('user/list',[UserController::class,'home']);
|
||||
|
Loading…
Reference in New Issue
Block a user