From 4156ba89087c79d0b622ed20ce912bc31a490ddf Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 16 May 2023 17:09:50 +0200 Subject: [PATCH] fix instanceSettings --- app/Actions/Fortify/CreateNewUser.php | 2 +- app/Actions/Proxy/InstallProxy.php | 2 +- app/Http/Livewire/Source/Github/Change.php | 2 +- app/Jobs/DeployApplicationJob.php | 4 ++-- app/Models/Application.php | 2 -- app/Models/InstanceSettings.php | 4 ++++ app/Providers/FortifyServiceProvider.php | 4 ++-- routes/web.php | 6 +++--- 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/Actions/Fortify/CreateNewUser.php b/app/Actions/Fortify/CreateNewUser.php index 6f99fee43..90f1bacb4 100644 --- a/app/Actions/Fortify/CreateNewUser.php +++ b/app/Actions/Fortify/CreateNewUser.php @@ -23,7 +23,7 @@ class CreateNewUser implements CreatesNewUsers */ public function create(array $input): User { - $settings = InstanceSettings::find(0); + $settings = InstanceSettings::get(); if (!$settings->is_registration_enabled) { Log::info('Registration is disabled'); abort(403); diff --git a/app/Actions/Proxy/InstallProxy.php b/app/Actions/Proxy/InstallProxy.php index 460727514..5b61118cd 100644 --- a/app/Actions/Proxy/InstallProxy.php +++ b/app/Actions/Proxy/InstallProxy.php @@ -63,7 +63,7 @@ class InstallProxy protected function getEnvContents() { - $instance_fqdn = InstanceSettings::find(1)->fqdn ?? config('app.url'); + $instance_fqdn = InstanceSettings::get()->fqdn ?? config('app.url'); $url = Url::fromString($instance_fqdn); $data = [ 'TRAEFIK_DASHBOARD_HOST' => $url->getHost(), diff --git a/app/Http/Livewire/Source/Github/Change.php b/app/Http/Livewire/Source/Github/Change.php index 488c6fd10..0121d73db 100644 --- a/app/Http/Livewire/Source/Github/Change.php +++ b/app/Http/Livewire/Source/Github/Change.php @@ -48,7 +48,7 @@ class Change extends Component } public function mount() { - $settings = InstanceSettings::first(); + $settings = InstanceSettings::get(); if ($settings->fqdn) { $this->host = $settings->fqdn; } diff --git a/app/Jobs/DeployApplicationJob.php b/app/Jobs/DeployApplicationJob.php index 941077ec2..1f949a59a 100644 --- a/app/Jobs/DeployApplicationJob.php +++ b/app/Jobs/DeployApplicationJob.php @@ -43,6 +43,7 @@ class DeployApplicationJob implements ShouldQueue public string $application_uuid, public bool $force_rebuild = false, ) { + $this->application = Application::query() ->where('uuid', $this->application_uuid) ->firstOrFail(); @@ -100,8 +101,7 @@ class DeployApplicationJob implements ShouldQueue public function handle(): void { try { - $coolify_instance_settings = InstanceSettings::find(0); - $deployment_type = $this->application->deploymentType(); + $coolify_instance_settings = InstanceSettings::get(); if ($this->application->deploymentType() === 'source') { $this->source = $this->application->source->getMorphClass()::where('id', $this->application->source->id)->first(); } diff --git a/app/Models/Application.php b/app/Models/Application.php index 58e92ddc3..df4b47c9d 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -48,8 +48,6 @@ class Application extends BaseModel { return $this->previews->modelScope(); } - - public function publishDirectory(): Attribute { return Attribute::make( diff --git a/app/Models/InstanceSettings.php b/app/Models/InstanceSettings.php index 8f8936b1f..c2394a008 100644 --- a/app/Models/InstanceSettings.php +++ b/app/Models/InstanceSettings.php @@ -6,4 +6,8 @@ use Illuminate\Database\Eloquent\Model; class InstanceSettings extends Model { + public static function get() + { + return InstanceSettings::findOrFail(0); + } } diff --git a/app/Providers/FortifyServiceProvider.php b/app/Providers/FortifyServiceProvider.php index 5969ed20c..2a8a22d18 100644 --- a/app/Providers/FortifyServiceProvider.php +++ b/app/Providers/FortifyServiceProvider.php @@ -31,7 +31,7 @@ class FortifyServiceProvider extends ServiceProvider public function boot(): void { Fortify::registerView(function () { - $settings = InstanceSettings::find(0); + $settings = InstanceSettings::get(); if (!$settings->is_registration_enabled) { return redirect()->route('login'); } @@ -39,7 +39,7 @@ class FortifyServiceProvider extends ServiceProvider }); Fortify::loginView(function () { - $settings = InstanceSettings::find(0); + $settings = InstanceSettings::get(); return view('auth.login', [ 'is_registration_enabled' => $settings->is_registration_enabled ]); diff --git a/routes/web.php b/routes/web.php index 746c9619b..5c4c27acb 100644 --- a/routes/web.php +++ b/routes/web.php @@ -135,7 +135,7 @@ Route::middleware(['auth'])->group(function () { Route::get('/settings', function () { $isRoot = auth()->user()->isRoot(); if ($isRoot) { - $settings = InstanceSettings::find(0); + $settings = InstanceSettings::get(); return view('settings', [ 'settings' => $settings ]); @@ -165,7 +165,7 @@ Route::middleware(['auth'])->group(function () { $private_key = PrivateKey::where('uuid', request()->private_key_uuid)->first(); return view('private-key.show', [ 'private_key' => $private_key, - ]); + ]);G })->name('private-key.show'); }); Route::middleware(['auth'])->group(function () { @@ -173,7 +173,7 @@ Route::middleware(['auth'])->group(function () { Route::get('/source/github/{github_app_uuid}', function (Request $request) { $github_app = GithubApp::where('uuid', request()->github_app_uuid)->first(); $name = Str::of(Str::kebab($github_app->name))->start('coolify-'); - $settings = InstanceSettings::first(); + $settings = InstanceSettings::get(); $host = $request->schemeAndHttpHost(); if ($settings->fqdn) { $host = $settings->fqdn;