diff --git a/app/Http/Controllers/ServerController.php b/app/Http/Controllers/ServerController.php index 27ed7a200..7d361acf5 100644 --- a/app/Http/Controllers/ServerController.php +++ b/app/Http/Controllers/ServerController.php @@ -354,7 +354,7 @@ private function handleServerDeletion(Server $server): void Cache::forget('user_credits_left:' . $server->user_id); } - public function cancel(Server $server): RedirectResponse + public function cancel(Server $server): \Illuminate\Http\Response|RedirectResponse { if ($server->user_id !== Auth::id()) { return back()->with('error', __('This is not your Server!')); @@ -362,11 +362,49 @@ public function cancel(Server $server): RedirectResponse try { $server->update(['canceled' => now()]); + + if (request()->expectsJson()) { + return response()->noContent(); + } + return redirect()->route('servers.index') ->with('success', __('Server canceled')); } catch (Exception $e) { + report($e); + + if (request()->expectsJson()) { + return response()->json(['error' => __('Server cancellation failed')], 500); + } + + return redirect()->route('servers.index') + ->with('error', __('Server cancellation failed')); + } + } + + public function uncancel(Server $server): \Illuminate\Http\Response|RedirectResponse + { + if ($server->user_id !== Auth::id()) { + return back()->with('error', __('This is not your Server!')); + } + + try { + $server->update(['canceled' => null]); + + if (request()->expectsJson()) { + return response()->noContent(); + } + + return redirect()->route('servers.index') + ->with('success', __('Server cancellation has been revoked')); + } catch (Exception $e) { + report($e); + + if (request()->expectsJson()) { + return response()->json(['error' => __('Server cancellation revoke failed')], 500); + } + return redirect()->route('servers.index') - ->with('error', __('Server cancellation failed: ') . $e->getMessage()); + ->with('error', __('Server cancellation revoke failed')); } } diff --git a/routes/web.php b/routes/web.php index 6b9f97f06..1e9f80fbd 100644 --- a/routes/web.php +++ b/routes/web.php @@ -65,6 +65,7 @@ Route::get('notifications/readAll', [NotificationController::class, 'readAll'])->name('notifications.readAll'); Route::resource('notifications', NotificationController::class); Route::patch('/servers/cancel/{server}', [ServerController::class, 'cancel'])->name('servers.cancel'); + Route::patch('/servers/{server}/uncancel', [ServerController::class, 'uncancel'])->name('servers.uncancel'); Route::post('/servers/validateDeploymentVariables', [ServerController::class, 'validateDeploymentVariables'])->name('servers.validateDeploymentVariables'); Route::patch('/servers/{server}/billing_priority', [ServerController::class, 'updateBillingPriority'])->name('servers.updateBillingPriority'); Route::delete('/servers/{server}', [ServerController::class, 'destroy'])->name('servers.destroy'); diff --git a/themes/default/views/servers/index.blade.php b/themes/default/views/servers/index.blade.php index 9f388bc62..f96c72129 100644 --- a/themes/default/views/servers/index.blade.php +++ b/themes/default/views/servers/index.blade.php @@ -221,7 +221,6 @@ class="float-right mr-2 text-center btn btn-danger"