An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix(livewire): refresh service config after required variable updates
Andras Bacsai50913dc40967
diff --git a/app/Livewire/Project/Service/Configuration.php b/app/Livewire/Project/Service/Configuration.phpindex caa19042b8..f3ec3ba4df 100644--- a/app/Livewire/Project/Service/Configuration.php+++ b/app/Livewire/Project/Service/Configuration.php@@ -26,10 +26,17 @@ class Configuration extends Componentpublic array $parameters;- protected $listeners = [- 'refreshServices' => 'refreshServices',- 'refresh' => 'refreshServices',- ];+ public function getListeners(): array+ {+ $teamId = auth()->user()->currentTeam()->id;++ return [+ 'refreshServices' => 'refreshServices',+ 'refresh' => 'refreshServices',+ 'configurationChanged' => 'refreshServices',+ "echo-private:team.{$teamId},ApplicationConfigurationChanged" => 'refreshServices',+ ];+ }public function render(){diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php b/app/Livewire/Project/Shared/EnvironmentVariable/Show.phpindex 7f37b1fc4d..cd86d8670f 100644--- a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php+++ b/app/Livewire/Project/Shared/EnvironmentVariable/Show.php@@ -2,6 +2,7 @@namespace App\Livewire\Project\Shared\EnvironmentVariable;+use App\Events\ApplicationConfigurationChanged;use App\Models\Application;use App\Models\Environment;use App\Models\EnvironmentVariable as ModelsEnvironmentVariable;@@ -298,6 +299,10 @@ class Show extends Component$this->dispatch('success', 'Environment variable updated.');$this->dispatch('envsUpdated');$this->dispatch('configurationChanged');++ if ($this->is_required && $this->resource instanceof Service) {+ event(new ApplicationConfigurationChanged($this->resource->team()->id));+ }} catch (\Exception $e) {return handleError($e);}diff --git a/tests/Feature/Livewire/ConfigurationCheckerTest.php b/tests/Feature/Livewire/ConfigurationCheckerTest.phpindex ff1400847c..3b80ed209c 100644--- a/tests/Feature/Livewire/ConfigurationCheckerTest.php+++ b/tests/Feature/Livewire/ConfigurationCheckerTest.php@@ -1,22 +1,29 @@<?php+use App\Events\ApplicationConfigurationChanged;+use App\Livewire\Project\Service\Configuration;use App\Livewire\Project\Shared\ConfigurationChecker;+use App\Livewire\Project\Shared\EnvironmentVariable\Show;use App\Models\Application;use App\Models\ApplicationDeploymentQueue;use App\Models\Environment;use App\Models\EnvironmentVariable;+use App\Models\InstanceSettings;use App\Models\LocalFileVolume;use App\Models\Project;+use App\Models\Server;use App\Models\Service;use App\Models\Team;use App\Models\User;use Illuminate\Foundation\Testing\RefreshDatabase;+use Illuminate\Support\Facades\Event;use Illuminate\Support\Str;use Livewire\Livewire;uses(RefreshDatabase::class);beforeEach(function () {+ InstanceSettings::forceCreate(['id' => 0]);$this->team = Team::factory()->create();$this->user = User::factory()->create();$this->team->members()->attach($this->user->id, ['role' => 'owner']);@@ -121,6 +128,39 @@ it('warns when a service has missing required environment variables', function (});+it('broadcasts a configuration update after a required service variable is set', function () {+ Event::fake([ApplicationConfigurationChanged::class]);++ $server = Server::factory()->create(['team_id' => $this->team->id]);+ $service = Service::factory()->create([+ 'environment_id' => $this->environment->id,+ 'server_id' => $server->id,+ ]);+ $environmentVariable = $service->environment_variables()->create([+ 'key' => 'PLUNK_API_KEY',+ 'value' => '',+ 'is_required' => true,+ ]);++ Livewire::test(Show::class, ['env' => $environmentVariable, 'type' => 'service'])+ ->call('loadValues')+ ->set('value', 'secret')+ ->call('submit');++ Event::assertDispatched(+ ApplicationConfigurationChanged::class,+ fn (ApplicationConfigurationChanged $event): bool => $event->teamId === $this->team->id,+ );+});++it('refreshes the service configuration when a websocket configuration event arrives', function () {+ $listeners = app(Configuration::class)->getListeners();++ expect($listeners)+ ->toHaveKey("echo-private:team.{$this->team->id},ApplicationConfigurationChanged", 'refreshServices')+ ->toHaveKey('configurationChanged', 'refreshServices');+});+it('marks the service environment variables menu when required values are missing', function () {$configuration = file_get_contents(resource_path('views/livewire/project/service/configuration.blade.php'));$sidebar = file_get_contents(resource_path('views/components/service/configuration-sidebar.blade.php'));