2023-11-06 11:31:02 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire\Server;
|
2023-11-06 11:31:02 +00:00
|
|
|
|
2024-10-17 12:56:36 +00:00
|
|
|
use App\Actions\Server\DeleteServer;
|
2024-10-22 10:29:48 +00:00
|
|
|
use App\Models\InstanceSettings;
|
2024-10-30 13:54:27 +00:00
|
|
|
use App\Models\Server;
|
2023-11-06 11:31:02 +00:00
|
|
|
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;
|
2023-11-06 11:31:02 +00:00
|
|
|
|
|
|
|
|
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)
|
2023-11-06 11:31:02 +00:00
|
|
|
{
|
2024-10-24 14:20:01 +00:00
|
|
|
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation')) {
|
2024-10-22 10:29:48 +00:00
|
|
|
if (! Hash::check($password, Auth::user()->password)) {
|
|
|
|
|
$this->addError('password', 'The provided password is incorrect.');
|
2024-09-23 17:51:31 +00:00
|
|
|
|
2024-10-22 10:29:48 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2024-09-04 18:06:22 +00:00
|
|
|
}
|
2023-11-06 11:31:02 +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
|
|
|
|
2023-11-06 11:31:02 +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');
|
2023-11-06 11:31:02 +00:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return handleError($e, $this);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-11-06 11:31:02 +00:00
|
|
|
public function render()
|
|
|
|
|
{
|
|
|
|
|
return view('livewire.server.delete');
|
|
|
|
|
}
|
|
|
|
|
}
|