Files
coolify/app/Livewire/Project/Shared/ConfigurationChecker.php
T
Andras BacsaiandClaude Opus 5.5 3452faec87 fix(livewire): bind team broadcast listeners to the mounted team
Livewire rebuilds listener names from the session team on every event
call. After a team switch in another tab, open pages still listen on the
old team channel, so events failed with EventHandlerDoesNotExist (500),
or ran handlers that load resources scoped to the new team (404).

Store the team at mount and build team channel listeners from it. Events
for a team that is no longer the session team are ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 10:31:32 +02:00

121 lines
4.1 KiB
PHP

<?php
namespace App\Livewire\Project\Shared;
use App\Models\Application;
use App\Models\Service;
use App\Models\StandaloneClickhouse;
use App\Models\StandaloneDragonfly;
use App\Models\StandaloneKeydb;
use App\Models\StandaloneMariadb;
use App\Models\StandaloneMongodb;
use App\Models\StandaloneMysql;
use App\Models\StandalonePostgresql;
use App\Models\StandaloneRedis;
use App\Models\StandaloneSqlite;
use App\Traits\ListensToTeamChannel;
use Illuminate\Contracts\View\View;
use Livewire\Component;
class ConfigurationChecker extends Component
{
use ListensToTeamChannel;
public bool $isConfigurationChanged = false;
public array $configurationDiff = [];
public int $missingRequiredEnvironmentVariableCount = 0;
public array $missingRequiredEnvironmentVariableNames = [];
public Application|Service|StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|StandaloneSqlite $resource;
public function getListeners(): array
{
return [
'configurationChanged' => 'configurationChanged',
'envsUpdated' => 'configurationChanged',
...$this->teamChannelListeners([
'ApplicationConfigurationChanged' => 'configurationChanged',
]),
];
}
public function mount(): void
{
$this->configurationChanged();
}
public function render(): View
{
return view('livewire.project.shared.configuration-checker');
}
/**
* Members must never see environment variable values or Compose content, so redact
* those changes before they are serialized to the browser.
*
* @param array<int, array<string, mixed>> $changes
* @return array<int, array<string, mixed>>
*/
private function redactHiddenChanges(array $changes, bool $redact): array
{
if (! $redact) {
return $changes;
}
return collect($changes)
->map(function (array $change): array {
$isHidden = data_get($change, 'section') === 'environment'
|| str((string) data_get($change, 'key'))->afterLast('.')->value() === 'docker_compose_raw';
if (! $isHidden) {
return $change;
}
$change['old_display_value'] = data_get($change, 'old_display_value') === '-' ? '-' : '••••••••';
$change['new_display_value'] = data_get($change, 'new_display_value') === '-' ? '-' : '••••••••';
$change['old_full_value'] = null;
$change['new_full_value'] = null;
$change['expandable'] = false;
$change['display_summary'] = data_get($change, 'type') === 'changed' ? 'Changed' : null;
return $change;
})
->all();
}
public function configurationChanged(): void
{
$this->loadConfigurationState();
}
private function loadConfigurationState(): void
{
$this->resource->refresh();
if ($this->resource instanceof Service) {
$missingVariables = $this->resource->missingRequiredEnvironmentVariables();
$this->missingRequiredEnvironmentVariableCount = $missingVariables->count();
$this->missingRequiredEnvironmentVariableNames = $missingVariables->pluck('key')->all();
}
if ($this->resource instanceof Application) {
$diff = $this->resource->pendingDeploymentConfigurationDiff();
$this->isConfigurationChanged = $diff->isChanged();
$array = $diff->toArray();
// Fail closed: only owners/admins may see unlocked env values.
$redactEnvironment = ! (bool) auth()->user()?->isAdmin();
$array['changes'] = $this->redactHiddenChanges($array['changes'] ?? [], $redactEnvironment);
$this->configurationDiff = $array;
return;
}
$this->isConfigurationChanged = $this->resource->isConfigurationChanged();
$this->configurationDiff = [];
}
}