Add server transfer cancellation

This commit is contained in:
Lance Pioch 2022-11-06 12:15:06 -05:00
parent aa40521055
commit f2215437a5
4 changed files with 57 additions and 1 deletions

View file

@ -79,6 +79,25 @@ class ServerTransferController extends Controller
return redirect()->route('admin.servers.view.manage', $server->id); return redirect()->route('admin.servers.view.manage', $server->id);
} }
/**
* Cancels the specified server's transfer.
*/
public function cancel(Request $request, Server $server): RedirectResponse
{
if (!$transfer = $server->transfer) {
$this->alert->danger(trans('admin/server.alerts.transfer_does_not_exist'))->flash();
return redirect()->route('admin.servers.view.manage', $server->id);
}
$transfer->successful = true;
$transfer->save();
$this->alert->success(trans('admin/server.alerts.transfer_cancelled'))->flash();
return redirect()->route('admin.servers.view.manage', $server->id);
}
/** /**
* Assigns the specified allocations to the specified server. * Assigns the specified allocations to the specified server.
*/ */

View file

@ -22,6 +22,8 @@ return [
'node_required' => 'You must have at least one node configured before you can add a server to this panel.', 'node_required' => 'You must have at least one node configured before you can add a server to this panel.',
'transfer_nodes_required' => 'You must have at least two nodes configured before you can transfer servers.', 'transfer_nodes_required' => 'You must have at least two nodes configured before you can transfer servers.',
'transfer_started' => 'Server transfer has been started.', 'transfer_started' => 'Server transfer has been started.',
'transfer_cancelled' => 'Server transfer has been cancelled.',
'transfer_not_viable' => 'The node you selected does not have the required disk space or memory available to accommodate this server.', 'transfer_not_viable' => 'The node you selected does not have the required disk space or memory available to accommodate this server.',
'transfer_does_not_exist' => 'There is no current transfers for this server.',
], ],
]; ];

View file

@ -129,7 +129,11 @@
</div> </div>
<div class="box-footer"> <div class="box-footer">
<button class="btn btn-success disabled">Transfer Server</button> <button class="btn btn-success" data-toggle="modal" data-target="#cancelTransferModal">Cancel Transfer</button>
<p style="padding-top: 1rem; font-style: italic;">
<span style="font-weight: bold;">Warning</span>, only use this in cases of last resort such as a connection failure.
This may allow you to successfully transfer your server again.
</p>
</div> </div>
</div> </div>
</div> </div>
@ -190,6 +194,36 @@
</div> </div>
</div> </div>
</div> </div>
<div class="modal fade" id="cancelTransferModal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form action="{{ route('admin.servers.view.manage.transfer.cancel', $server->id) }}" method="POST">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Cancel Transfer</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="form-group col-md-12">
This action will force the transfer to a successful state.
However, please try to allow some time for your transfer to finish normally.
This is a last resort action that can allow you to try to start the transfer again.
You will most likely need to manually reset the allocations for these servers.
</div>
</div>
</div>
<div class="modal-footer">
{!! csrf_field() !!}
<button type="button" class="btn btn-default btn-sm pull-left" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-danger btn-sm">Confirm</button>
</div>
</form>
</div>
</div>
</div>
@endsection @endsection
@section('footer-scripts') @section('footer-scripts')

View file

@ -129,6 +129,7 @@ Route::group(['prefix' => 'servers'], function () {
Route::post('/view/{server:id}/manage/suspension', [Admin\ServersController::class, 'manageSuspension'])->name('admin.servers.view.manage.suspension'); Route::post('/view/{server:id}/manage/suspension', [Admin\ServersController::class, 'manageSuspension'])->name('admin.servers.view.manage.suspension');
Route::post('/view/{server:id}/manage/reinstall', [Admin\ServersController::class, 'reinstallServer'])->name('admin.servers.view.manage.reinstall'); Route::post('/view/{server:id}/manage/reinstall', [Admin\ServersController::class, 'reinstallServer'])->name('admin.servers.view.manage.reinstall');
Route::post('/view/{server:id}/manage/transfer', [Admin\Servers\ServerTransferController::class, 'transfer'])->name('admin.servers.view.manage.transfer'); Route::post('/view/{server:id}/manage/transfer', [Admin\Servers\ServerTransferController::class, 'transfer'])->name('admin.servers.view.manage.transfer');
Route::post('/view/{server:id}/manage/transfer/cancel', [Admin\Servers\ServerTransferController::class, 'cancel'])->name('admin.servers.view.manage.transfer.cancel');
Route::post('/view/{server:id}/delete', [Admin\ServersController::class, 'delete']); Route::post('/view/{server:id}/delete', [Admin\ServersController::class, 'delete']);
Route::patch('/view/{server:id}/details', [Admin\ServersController::class, 'setDetails']); Route::patch('/view/{server:id}/details', [Admin\ServersController::class, 'setDetails']);