From 65b925252c74ab45418c248d13273ba4a8a4883a Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 18 Feb 2025 16:44:16 +0100 Subject: [PATCH] feat(core): prevent using servers with existing resources as build servers --- app/Livewire/Server/Show.php | 7 +++++++ app/Models/Server.php | 7 +++++++ resources/views/livewire/server/show.blade.php | 9 ++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/Livewire/Server/Show.php b/app/Livewire/Server/Show.php index 6d267b9c8..b0e6d8858 100644 --- a/app/Livewire/Server/Show.php +++ b/app/Livewire/Server/Show.php @@ -7,6 +7,7 @@ use App\Actions\Server\StopSentinel; use App\Events\ServerReachabilityChanged; use App\Models\Server; use Livewire\Attributes\Computed; +use Livewire\Attributes\Locked; use Livewire\Attributes\Validate; use Livewire\Component; @@ -50,6 +51,9 @@ class Show extends Component #[Validate(['required'])] public bool $isBuildServer; + #[Locked] + public bool $isBuildServerLocked = false; + #[Validate(['required'])] public bool $isMetricsEnabled; @@ -95,6 +99,9 @@ class Show extends Component try { $this->server = Server::ownedByCurrentTeam()->whereUuid($server_uuid)->firstOrFail(); $this->syncData(); + if (! $this->server->isEmpty()) { + $this->isBuildServerLocked = true; + } } catch (\Throwable $e) { return handleError($e, $this); } diff --git a/app/Models/Server.php b/app/Models/Server.php index f3edd82fb..187685d66 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -1341,4 +1341,11 @@ $schema://$host { throw new \Exception('Invalid proxy type.'); } } + + public function isEmpty() + { + return $this->applications()->count() == 0 && + $this->databases()->count() == 0 && + $this->services()->count() == 0; + } } diff --git a/resources/views/livewire/server/show.blade.php b/resources/views/livewire/server/show.blade.php index ac0d3a6df..77aebbc04 100644 --- a/resources/views/livewire/server/show.blade.php +++ b/resources/views/livewire/server/show.blade.php @@ -134,7 +134,14 @@
@if (!$server->isLocalhost())
- + @if ($isBuildServerLocked) + + @else + + @endif
@if (!$server->isBuildServer() && !$server->settings->is_cloudflare_tunnel)