coolify/app/Livewire/Server/Delete.php

58 lines
1.5 KiB
PHP
Raw Normal View History

<?php
2023-12-07 18:06:32 +00:00
namespace App\Livewire\Server;
2024-10-17 12:56:36 +00:00
use App\Actions\Server\DeleteServer;
use App\Models\InstanceSettings;
2024-10-30 13:54:27 +00:00
use App\Models\Server;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
2024-09-04 18:06:22 +00:00
use Illuminate\Support\Facades\Auth;
2024-09-23 17:51:31 +00:00
use Illuminate\Support\Facades\Hash;
use Livewire\Component;
class Delete extends Component
{
use AuthorizesRequests;
2024-10-30 13:54:27 +00:00
public Server $server;
public function mount(string $server_uuid)
{
try {
$this->server = Server::ownedByCurrentTeam()->whereUuid($server_uuid)->firstOrFail();
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
2024-06-10 20:43:34 +00:00
2024-09-04 18:06:22 +00:00
public function delete($password)
{
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation')) {
if (! Hash::check($password, Auth::user()->password)) {
$this->addError('password', 'The provided password is incorrect.');
2024-09-23 17:51:31 +00:00
return;
}
2024-09-04 18:06:22 +00:00
}
try {
$this->authorize('delete', $this->server);
2023-11-06 17:04:18 +00:00
if ($this->server->hasDefinedResources()) {
2023-12-07 18:06:32 +00:00
$this->dispatch('error', 'Server has defined resources. Please delete them first.');
2024-06-10 20:43:34 +00:00
return;
}
2024-10-17 12:56:36 +00:00
$this->server->delete();
DeleteServer::dispatch($this->server);
2024-10-17 20:08:23 +00:00
2024-01-07 15:23:41 +00:00
return redirect()->route('server.index');
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
2024-06-10 20:43:34 +00:00
public function render()
{
return view('livewire.server.delete');
}
}