From f6a595807d059922cbd28efafada2b1f14c8cfdf Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Tue, 25 Mar 2025 13:02:53 +0100 Subject: [PATCH] Fix ScanForNewRelease event triggering whereas checkForUpdate is disabled - Fixes #462 --- app/Http/Controllers/SinglePageController.php | 8 +++++--- tests/Feature/ViewTest.php | 12 ++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/SinglePageController.php b/app/Http/Controllers/SinglePageController.php index 035f672a..b5e499f0 100644 --- a/app/Http/Controllers/SinglePageController.php +++ b/app/Http/Controllers/SinglePageController.php @@ -5,7 +5,6 @@ namespace App\Http\Controllers; use App\Events\ScanForNewReleaseCalled; use App\Facades\Settings; use Illuminate\Support\Facades\App; -use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Vite; class SinglePageController extends Controller @@ -17,12 +16,15 @@ class SinglePageController extends Controller */ public function index() { - event(new ScanForNewReleaseCalled); + $appSettings = Settings::all(); + + if ($appSettings['checkForUpdate'] == true) { + event(new ScanForNewReleaseCalled); + } // We only share necessary and acceptable values with the HTML front-end. // But all the properties have to be pushed to init the appSetting store state correctly, // so we set them to null, they will be fed later by the front-end - $appSettings = Settings::all(); $publicSettings = $appSettings->only([ 'disableRegistration', 'enableSso', diff --git a/tests/Feature/ViewTest.php b/tests/Feature/ViewTest.php index b78b3ab9..3f8d96cc 100644 --- a/tests/Feature/ViewTest.php +++ b/tests/Feature/ViewTest.php @@ -3,6 +3,7 @@ namespace Tests\Feature; use App\Events\ScanForNewReleaseCalled; +use App\Facades\Settings; use App\Http\Controllers\SinglePageController; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Http; @@ -60,4 +61,15 @@ class ViewTest extends FeatureTestCase Event::assertDispatched(ScanForNewReleaseCalled::class); } + + #[Test] + public function test_calling_index_does_not_fire_ScanForNewReleaseCalled_event() + { + Event::fake(); + Settings::set('checkForUpdate', false); + + $this->get('/'); + + Event::assertNotDispatched(ScanForNewReleaseCalled::class); + } }