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(api): link to API settings where disabled API blocks a feature
Andras Bacsaie58e4900612a
diff --git a/resources/views/components/api-disabled-callout.blade.php b/resources/views/components/api-disabled-callout.blade.phpnew file mode 100644index 0000000000..1bc9dec11e--- /dev/null+++ b/resources/views/components/api-disabled-callout.blade.php@@ -0,0 +1,14 @@+@props(['message' => 'This feature uses the Coolify API.'])++@unless (instanceSettings()->is_api_enabled)+ <x-callout type="warning" title="API access is turned off" {{ $attributes }}>+ {{ $message }}+ @if (isInstanceAdmin())+ <div class="mt-2">+ <a href="{{ route('settings.advanced') }}" class="button" {{ wireNavigate() }}>Enable API access</a>+ </div>+ @else+ Ask an instance admin to enable API access.+ @endif+ </x-callout>+@endunlessdiff --git a/resources/views/livewire/project/shared/webhooks.blade.php b/resources/views/livewire/project/shared/webhooks.blade.phpindex 3e332bf440..8e5483b283 100644--- a/resources/views/livewire/project/shared/webhooks.blade.php+++ b/resources/views/livewire/project/shared/webhooks.blade.php@@ -43,6 +43,8 @@<x-external-link /></a></x-slot:actions>+ <x-api-disabled-callout class="mb-4"+ message="Enable API access before external services can call the deploy webhook." /><x-forms.copy-input label="Deploy webhook URL" :text="$deploywebhook ?? ''" /></x-application.settings-section>@@ -117,6 +119,8 @@<x-external-link /></a></x-slot:actions>+ <x-api-disabled-callout class="mb-4"+ message="Enable API access before external services can call the deploy webhook." /><x-forms.copy-input label="Deploy webhook URL" :text="$deploywebhook ?? ''" /></x-application.settings-section></div>diff --git a/resources/views/livewire/security/api-tokens.blade.php b/resources/views/livewire/security/api-tokens.blade.phpindex ddffd51094..8b05a0679b 100644--- a/resources/views/livewire/security/api-tokens.blade.php+++ b/resources/views/livewire/security/api-tokens.blade.php@@ -10,13 +10,15 @@<x-application.settings-section title="API disabled"description="Enable the Coolify API before creating access tokens."><x-empty title="API access is turned off"- description="Enable API access in instance settings to issue tokens." icon-name="keys"- size="sm">- <x-slot:actions>- <a href="{{ route('settings.advanced') }}" class="button" {{ wireNavigate() }}>- Open settings- </a>- </x-slot:actions>+ description="{{ isInstanceAdmin() ? 'Enable API access in instance settings to issue tokens.' : 'Ask an instance admin to enable API access.' }}"+ icon-name="keys" size="sm">+ @if (isInstanceAdmin())+ <x-slot:actions>+ <a href="{{ route('settings.advanced') }}" class="button" {{ wireNavigate() }}>+ Enable API access+ </a>+ </x-slot:actions>+ @endif</x-empty></x-application.settings-section></div>diff --git a/tests/Feature/ApiDisabledCalloutTest.php b/tests/Feature/ApiDisabledCalloutTest.phpnew file mode 100644index 0000000000..7f6ca8f6f8--- /dev/null+++ b/tests/Feature/ApiDisabledCalloutTest.php@@ -0,0 +1,79 @@+<?php++use App\Livewire\Project\Shared\Webhooks;+use App\Livewire\Security\ApiTokens;+use App\Models\Application;+use App\Models\Environment;+use App\Models\InstanceSettings;+use App\Models\Project;+use App\Models\Server;+use App\Models\StandaloneDocker;+use App\Models\Team;+use App\Models\User;+use Illuminate\Foundation\Testing\RefreshDatabase;+use Illuminate\Support\Once;+use Livewire\Livewire;++uses(RefreshDatabase::class);++beforeEach(function () {+ Server::flushIdentityMap();+ InstanceSettings::forceCreate(['id' => 0, 'is_api_enabled' => false]);++ $this->rootTeam = Team::factory()->create(['id' => 0]);+ $this->instanceAdmin = User::factory()->create();+ $this->rootTeam->members()->attach($this->instanceAdmin->id, ['role' => 'admin']);++ $this->team = Team::factory()->create();+ $this->teamAdmin = User::factory()->create();+ $this->team->members()->attach($this->teamAdmin->id, ['role' => 'admin']);++ $server = Server::factory()->create(['team_id' => $this->team->id]);+ $destination = StandaloneDocker::query()->where('server_id', $server->id)->firstOrFail();+ $project = Project::factory()->create(['team_id' => $this->team->id]);+ $environment = Environment::factory()->create(['project_id' => $project->id]);++ $this->application = Application::factory()->create([+ 'environment_id' => $environment->id,+ 'destination_id' => $destination->id,+ 'destination_type' => $destination->getMorphClass(),+ ]);+});++afterEach(function () {+ Server::flushIdentityMap();+});++it('links instance admins to the API settings when the API is disabled', function (string $component) {+ $this->actingAs($this->instanceAdmin);+ session(['currentTeam' => $this->rootTeam]);++ $params = $component === Webhooks::class ? ['resource' => $this->application] : [];++ Livewire::test($component, $params)+ ->assertSee('API access is turned off')+ ->assertSee(route('settings.advanced'))+ ->assertSee('Enable API access');+})->with(['webhooks' => Webhooks::class, 'api tokens' => ApiTokens::class]);++it('tells other users to ask an instance admin when the API is disabled', function (string $component) {+ $this->actingAs($this->teamAdmin);+ session(['currentTeam' => $this->team]);++ $params = $component === Webhooks::class ? ['resource' => $this->application] : [];++ Livewire::test($component, $params)+ ->assertSee('API access is turned off')+ ->assertSee('Ask an instance admin to enable API access.')+ ->assertDontSee(route('settings.advanced'));+})->with(['webhooks' => Webhooks::class, 'api tokens' => ApiTokens::class]);++it('does not show the API notice on the webhooks page when the API is enabled', function () {+ InstanceSettings::query()->whereKey(0)->update(['is_api_enabled' => true]);+ Once::flush();+ $this->actingAs($this->teamAdmin);+ session(['currentTeam' => $this->team]);++ Livewire::test(Webhooks::class, ['resource' => $this->application])+ ->assertDontSee('API access is turned off');+});