mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-14 08:42:38 -04:00
Add audit events for account actions, server and application settings, services, destinations, storage, backup schedules, and scheduled tasks. Track changed fields and skip unchanged saves without logging file content. Add regression coverage for audit events and changed-field detection.
84 lines
2.6 KiB
PHP
84 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Project\Application;
|
|
|
|
use App\Models\Application;
|
|
use App\Traits\AuditsApplicationSettings;
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
use Livewire\Attributes\Validate;
|
|
use Livewire\Component;
|
|
|
|
class Swarm extends Component
|
|
{
|
|
use AuditsApplicationSettings, AuthorizesRequests;
|
|
|
|
public Application $application;
|
|
|
|
#[Validate('required')]
|
|
public int $swarmReplicas;
|
|
|
|
#[Validate(['nullable'])]
|
|
public ?string $swarmPlacementConstraints = null;
|
|
|
|
#[Validate('required')]
|
|
public bool $isSwarmOnlyWorkerNodes;
|
|
|
|
public function mount()
|
|
{
|
|
try {
|
|
$this->syncData();
|
|
} catch (\Throwable $e) {
|
|
return handleError($e, $this);
|
|
}
|
|
}
|
|
|
|
private function syncData(bool $toModel = false): void
|
|
{
|
|
if ($toModel) {
|
|
$this->validate();
|
|
$this->application->swarm_replicas = $this->swarmReplicas;
|
|
$this->application->swarm_placement_constraints = $this->swarmPlacementConstraints ? base64_encode($this->swarmPlacementConstraints) : null;
|
|
$this->application->settings->is_swarm_only_worker_nodes = $this->isSwarmOnlyWorkerNodes;
|
|
$this->application->save();
|
|
$this->saveApplicationSettingsWithAudit($this->application);
|
|
} else {
|
|
$this->swarmReplicas = $this->application->swarm_replicas;
|
|
if ($this->application->swarm_placement_constraints) {
|
|
$this->swarmPlacementConstraints = base64_decode($this->application->swarm_placement_constraints);
|
|
} else {
|
|
$this->swarmPlacementConstraints = null;
|
|
}
|
|
$this->isSwarmOnlyWorkerNodes = $this->application->settings->is_swarm_only_worker_nodes;
|
|
}
|
|
}
|
|
|
|
public function instantSave()
|
|
{
|
|
try {
|
|
$this->authorize('update', $this->application);
|
|
$this->syncData(true);
|
|
$this->dispatch('success', 'Swarm settings updated.');
|
|
$this->dispatch('configurationChanged');
|
|
} catch (\Throwable $e) {
|
|
return handleError($e, $this);
|
|
}
|
|
}
|
|
|
|
public function submit()
|
|
{
|
|
try {
|
|
$this->authorize('update', $this->application);
|
|
$this->syncData(true);
|
|
$this->dispatch('success', 'Swarm settings updated.');
|
|
$this->dispatch('configurationChanged');
|
|
} catch (\Throwable $e) {
|
|
return handleError($e, $this);
|
|
}
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.project.application.swarm');
|
|
}
|
|
}
|