feat(domains): implement domain conflict detection and user confirmation modal across application components

This commit is contained in:
Andras Bacsai
2025-08-28 10:52:41 +02:00
parent 643343785a
commit 80499a03d8
14 changed files with 390 additions and 26 deletions

View File

@@ -51,9 +51,16 @@ class General extends Component
public $parsedServiceDomains = [];
public $domainConflicts = [];
public $showDomainConflictModal = false;
public $forceSaveDomains = false;
protected $listeners = [
'resetDefaultLabels',
'configurationChanged' => '$refresh',
'confirmDomainUsage',
];
protected function rules(): array
@@ -485,10 +492,33 @@ class General extends Component
}
}
}
checkDomainUsage(resource: $this->application);
// Check for domain conflicts if not forcing save
if (! $this->forceSaveDomains) {
$result = checkDomainUsage(resource: $this->application);
if ($result['hasConflicts']) {
$this->domainConflicts = $result['conflicts'];
$this->showDomainConflictModal = true;
return false;
}
} else {
// Reset the force flag after using it
$this->forceSaveDomains = false;
}
$this->application->fqdn = $domains->implode(',');
$this->resetDefaultLabels(false);
}
return true;
}
public function confirmDomainUsage()
{
$this->forceSaveDomains = true;
$this->showDomainConflictModal = false;
$this->submit();
}
public function setRedirect()
@@ -536,7 +566,9 @@ class General extends Component
$this->application->parseHealthcheckFromDockerfile($this->application->dockerfile);
}
$this->checkFqdns();
if (! $this->checkFqdns()) {
return; // Stop if there are conflicts and user hasn't confirmed
}
$this->application->save();
if (! $this->customLabels && $this->application->destination->server->proxyType() !== 'NONE' && ! $this->application->settings->is_container_label_readonly_enabled) {
@@ -588,7 +620,20 @@ class General extends Component
}
}
}
checkDomainUsage(resource: $this->application);
// Check for domain conflicts if not forcing save
if (! $this->forceSaveDomains) {
$result = checkDomainUsage(resource: $this->application);
if ($result['hasConflicts']) {
$this->domainConflicts = $result['conflicts'];
$this->showDomainConflictModal = true;
return;
}
} else {
// Reset the force flag after using it
$this->forceSaveDomains = false;
}
$this->application->save();
$this->resetDefaultLabels();
}

View File

@@ -25,6 +25,14 @@ class Previews extends Component
public int $rate_limit_remaining;
public $domainConflicts = [];
public $showDomainConflictModal = false;
public $forceSaveDomains = false;
public $pendingPreviewId = null;
protected $rules = [
'application.previews.*.fqdn' => 'string|nullable',
];
@@ -49,6 +57,16 @@ class Previews extends Component
}
}
public function confirmDomainUsage()
{
$this->forceSaveDomains = true;
$this->showDomainConflictModal = false;
if ($this->pendingPreviewId) {
$this->save_preview($this->pendingPreviewId);
$this->pendingPreviewId = null;
}
}
public function save_preview($preview_id)
{
try {
@@ -63,7 +81,20 @@ class Previews extends Component
$this->dispatch('error', 'Validating DNS failed.', "Make sure you have added the DNS records correctly.<br><br>$preview->fqdn->{$this->application->destination->server->ip}<br><br>Check this <a target='_blank' class='underline dark:text-white' href='https://coolify.io/docs/knowledge-base/dns-configuration'>documentation</a> for further help.");
$success = false;
}
checkDomainUsage(resource: $this->application, domain: $preview->fqdn);
// Check for domain conflicts if not forcing save
if (! $this->forceSaveDomains) {
$result = checkDomainUsage(resource: $this->application, domain: $preview->fqdn);
if ($result['hasConflicts']) {
$this->domainConflicts = $result['conflicts'];
$this->showDomainConflictModal = true;
$this->pendingPreviewId = $preview_id;
return;
}
} else {
// Reset the force flag after using it
$this->forceSaveDomains = false;
}
}
if (! $preview) {

View File

@@ -12,6 +12,12 @@ class EditDomain extends Component
public ServiceApplication $application;
public $domainConflicts = [];
public $showDomainConflictModal = false;
public $forceSaveDomains = false;
protected $rules = [
'application.fqdn' => 'nullable',
'application.required_fqdn' => 'required|boolean',
@@ -22,6 +28,13 @@ class EditDomain extends Component
$this->application = ServiceApplication::find($this->applicationId);
}
public function confirmDomainUsage()
{
$this->forceSaveDomains = true;
$this->showDomainConflictModal = false;
$this->submit();
}
public function submit()
{
try {
@@ -37,7 +50,20 @@ class EditDomain extends Component
if ($warning) {
$this->dispatch('warning', __('warning.sslipdomain'));
}
checkDomainUsage(resource: $this->application);
// Check for domain conflicts if not forcing save
if (! $this->forceSaveDomains) {
$result = checkDomainUsage(resource: $this->application);
if ($result['hasConflicts']) {
$this->domainConflicts = $result['conflicts'];
$this->showDomainConflictModal = true;
return;
}
} else {
// Reset the force flag after using it
$this->forceSaveDomains = false;
}
$this->validate();
$this->application->save();
updateCompose($this->application);

View File

@@ -23,6 +23,12 @@ class ServiceApplicationView extends Component
public $delete_volumes = true;
public $domainConflicts = [];
public $showDomainConflictModal = false;
public $forceSaveDomains = false;
protected $rules = [
'application.human_name' => 'nullable',
'application.description' => 'nullable',
@@ -129,6 +135,13 @@ class ServiceApplicationView extends Component
}
}
public function confirmDomainUsage()
{
$this->forceSaveDomains = true;
$this->showDomainConflictModal = false;
$this->submit();
}
public function submit()
{
try {
@@ -145,7 +158,20 @@ class ServiceApplicationView extends Component
if ($warning) {
$this->dispatch('warning', __('warning.sslipdomain'));
}
checkDomainUsage(resource: $this->application);
// Check for domain conflicts if not forcing save
if (! $this->forceSaveDomains) {
$result = checkDomainUsage(resource: $this->application);
if ($result['hasConflicts']) {
$this->domainConflicts = $result['conflicts'];
$this->showDomainConflictModal = true;
return;
}
} else {
// Reset the force flag after using it
$this->forceSaveDomains = false;
}
$this->validate();
$this->application->save();
updateCompose($this->application);

View File

@@ -33,9 +33,6 @@ class ExecuteContainerCommand extends Component
public function mount()
{
if (! auth()->user()->isAdmin()) {
abort(403);
}
$this->parameters = get_route_parameters();
$this->containers = collect();
$this->servers = collect();

View File

@@ -35,6 +35,12 @@ class Index extends Component
#[Validate('required|string|timezone')]
public string $instance_timezone;
public array $domainConflicts = [];
public bool $showDomainConflictModal = false;
public bool $forceSaveDomains = false;
public function render()
{
return view('livewire.settings.index');
@@ -81,6 +87,13 @@ class Index extends Component
}
}
public function confirmDomainUsage()
{
$this->forceSaveDomains = true;
$this->showDomainConflictModal = false;
$this->submit();
}
public function submit()
{
try {
@@ -108,7 +121,18 @@ class Index extends Component
}
}
if ($this->fqdn) {
checkDomainUsage(domain: $this->fqdn);
if (! $this->forceSaveDomains) {
$result = checkDomainUsage(domain: $this->fqdn);
if ($result['hasConflicts']) {
$this->domainConflicts = $result['conflicts'];
$this->showDomainConflictModal = true;
return;
}
} else {
// Reset the force flag after using it
$this->forceSaveDomains = false;
}
}
$this->instantSave(isSave: false);