mirror of
https://github.com/ershisan99/coolify.git
synced 2026-02-02 12:34:49 +00:00
fix: separate delete with validation of server
This commit is contained in:
31
app/Http/Livewire/Server/Delete.php
Normal file
31
app/Http/Livewire/Server/Delete.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Livewire\Server;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||||
|
use Livewire\Component;
|
||||||
|
|
||||||
|
class Delete extends Component
|
||||||
|
{
|
||||||
|
use AuthorizesRequests;
|
||||||
|
|
||||||
|
public $server;
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->authorize('delete', $this->server);
|
||||||
|
if (!$this->server->isEmpty()) {
|
||||||
|
$this->emit('error', 'Server has defined resources. Please delete them first.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->server->delete();
|
||||||
|
return redirect()->route('server.all');
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return handleError($e, $this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
return view('livewire.server.delete');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,12 +4,10 @@ namespace App\Http\Livewire\Server;
|
|||||||
|
|
||||||
use App\Actions\Server\InstallDocker;
|
use App\Actions\Server\InstallDocker;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
class Form extends Component
|
class Form extends Component
|
||||||
{
|
{
|
||||||
use AuthorizesRequests;
|
|
||||||
public Server $server;
|
public Server $server;
|
||||||
public bool $isValidConnection = false;
|
public bool $isValidConnection = false;
|
||||||
public bool $isValidDocker = false;
|
public bool $isValidDocker = false;
|
||||||
@@ -106,23 +104,9 @@ class Form extends Component
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$this->authorize('delete', $this->server);
|
|
||||||
if (!$this->server->isEmpty()) {
|
|
||||||
$this->emit('error', 'Server has defined resources. Please delete them first.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->server->delete();
|
|
||||||
return redirect()->route('server.all');
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
return handleError($e, $this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public function submit()
|
public function submit()
|
||||||
{
|
{
|
||||||
if(isCloud() && !isDev()) {
|
if (isCloud() && !isDev()) {
|
||||||
$this->validate();
|
$this->validate();
|
||||||
$this->validate([
|
$this->validate([
|
||||||
'server.ip' => 'required',
|
'server.ip' => 'required',
|
||||||
|
|||||||
18
resources/views/livewire/server/delete.blade.php
Normal file
18
resources/views/livewire/server/delete.blade.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<div>
|
||||||
|
<x-modal yesOrNo modalId="deleteServer" modalTitle="Delete Server">
|
||||||
|
<x-slot:modalBody>
|
||||||
|
<p>This server will be deleted. It is not reversible. <br>Please think again..</p>
|
||||||
|
</x-slot:modalBody>
|
||||||
|
</x-modal>
|
||||||
|
@if ($server->id !== 0)
|
||||||
|
<h2 class="pt-4">Danger Zone</h2>
|
||||||
|
<div class="">Woah. I hope you know what are you doing.</div>
|
||||||
|
<h4 class="pt-4">Delete Server</h4>
|
||||||
|
<div class="pb-4">This will remove this server from Coolify. Beware! There is no coming
|
||||||
|
back!
|
||||||
|
</div>
|
||||||
|
<x-forms.button isError isModal modalId="deleteServer">
|
||||||
|
Delete
|
||||||
|
</x-forms.button>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
@@ -1,9 +1,4 @@
|
|||||||
<div x-init="$wire.validateServer(false)">
|
<div x-init="$wire.validateServer(false)">
|
||||||
<x-modal yesOrNo modalId="deleteServer" modalTitle="Delete Server">
|
|
||||||
<x-slot:modalBody>
|
|
||||||
<p>This server will be deleted. It is not reversible. <br>Please think again..</p>
|
|
||||||
</x-slot:modalBody>
|
|
||||||
</x-modal>
|
|
||||||
<x-modal yesOrNo modalId="changeLocalhost" modalTitle="Change Localhost" action="submit">
|
<x-modal yesOrNo modalId="changeLocalhost" modalTitle="Change Localhost" action="submit">
|
||||||
<x-slot:modalBody>
|
<x-slot:modalBody>
|
||||||
<p>You could lost a lot of functionalities if you change the server details of the server where Coolify is
|
<p>You could lost a lot of functionalities if you change the server details of the server where Coolify is
|
||||||
@@ -47,7 +42,8 @@
|
|||||||
label="Is it part of a Swarm cluster?" /> --}}
|
label="Is it part of a Swarm cluster?" /> --}}
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col w-full gap-2 lg:flex-row">
|
<div class="flex flex-col w-full gap-2 lg:flex-row">
|
||||||
<x-forms.input id="server.ip" label="IP Address/Domain" helper="An IP Address (127.0.0.1) or domain (example.com)." required />
|
<x-forms.input id="server.ip" label="IP Address/Domain"
|
||||||
|
helper="An IP Address (127.0.0.1) or domain (example.com)." required />
|
||||||
<div class="flex gap-2">
|
<div class="flex gap-2">
|
||||||
<x-forms.input id="server.user" label="User" required />
|
<x-forms.input id="server.user" label="User" required />
|
||||||
<x-forms.input type="number" id="server.port" label="Port" required />
|
<x-forms.input type="number" id="server.port" label="Port" required />
|
||||||
@@ -66,21 +62,9 @@
|
|||||||
helper="Disk cleanup job will be executed if disk usage is more than this number." />
|
helper="Disk cleanup job will be executed if disk usage is more than this number." />
|
||||||
@endif
|
@endif
|
||||||
</form>
|
</form>
|
||||||
@if ($server->id !== 0)
|
<livewire:server.delete :server="$server" />
|
||||||
<h2 class="pt-4">Danger Zone</h2>
|
|
||||||
<div class="">Woah. I hope you know what are you doing.</div>
|
|
||||||
<h4 class="pt-4">Delete Server</h4>
|
|
||||||
<div class="pb-4">This will remove this server from Coolify. Beware! There is no coming
|
|
||||||
back!
|
|
||||||
</div>
|
|
||||||
<x-forms.button isError isModal modalId="deleteServer">
|
|
||||||
Delete
|
|
||||||
</x-forms.button>
|
|
||||||
@endif
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
Livewire.on('installDocker', () => {
|
Livewire.on('installDocker', () => {
|
||||||
console.log('asd');
|
|
||||||
installDocker.showModal();
|
installDocker.showModal();
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user