refactor(terminal-access): streamline resource retrieval and enhance terminal access messaging in UI

This commit is contained in:
Andras Bacsai
2025-05-29 14:26:48 +02:00
parent 46b4cfac68
commit 9d71900952
2 changed files with 17 additions and 10 deletions

View File

@@ -55,7 +55,7 @@ class ExecuteContainerCommand extends Component
$this->servers = collect();
if (data_get($this->parameters, 'application_uuid')) {
$this->type = 'application';
$this->resource = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail();
$this->resource = Application::whereUuid($this->parameters['application_uuid'])->firstOrFail();
if ($this->resource->destination->server->isFunctional() && $this->resource->destination->server->isTerminalEnabled()) {
$this->servers = $this->servers->push($this->resource->destination->server);
}
@@ -78,14 +78,14 @@ class ExecuteContainerCommand extends Component
$this->loadContainers();
} elseif (data_get($this->parameters, 'service_uuid')) {
$this->type = 'service';
$this->resource = Service::where('uuid', $this->parameters['service_uuid'])->firstOrFail();
$this->resource = Service::whereUuid($this->parameters['service_uuid'])->firstOrFail();
if ($this->resource->server->isFunctional() && $this->resource->server->isTerminalEnabled()) {
$this->servers = $this->servers->push($this->resource->server);
}
$this->loadContainers();
} elseif (data_get($this->parameters, 'server_uuid')) {
$this->type = 'server';
$this->resource = Server::where('uuid', $this->parameters['server_uuid'])->firstOrFail();
$this->resource = Server::ownedByCurrentTeam()->whereUuid($this->parameters['server_uuid'])->firstOrFail();
$this->server = $this->resource;
}
}
@@ -175,6 +175,9 @@ class ExecuteContainerCommand extends Component
if ($this->server->isForceDisabled()) {
throw new \RuntimeException('Server is disabled.');
}
if (! $this->server->isTerminalEnabled()) {
throw new \RuntimeException('Terminal access is disabled on this server.');
}
$this->hasShell = true;
$this->dispatch(
'send-terminal-command',

View File

@@ -35,6 +35,7 @@
</div>
@else
@if ($type === 'server')
@if ($server->isTerminalEnabled())
<form class="w-full" wire:submit="$dispatchSelf('connectToServer')"
wire:init="$dispatchSelf('connectToServer')">
<x-forms.button class="w-full" type="submit">Reconnect</x-forms.button>
@@ -42,6 +43,9 @@
<div class="mx-auto w-full">
<livewire:project.shared.terminal />
</div>
@else
<div>Terminal access is disabled on this server.</div>
@endif
@else
@if (count($containers) === 0)
<div class="pt-4">No containers are running on this server or terminal access is disabled.</div>