]> BookStack Code Mirror - bookstack/commitdiff
Fixed settings redirect issue and custom head display
authorDan Brown <redacted>
Wed, 30 Mar 2022 18:15:24 +0000 (19:15 +0100)
committerDan Brown <redacted>
Wed, 30 Mar 2022 18:15:24 +0000 (19:15 +0100)
- Fixed issue where redirect for `/settings` view would not be ran
  through base url generator so would not create a correct path in some
  cases. Now routed through controller with normal redirect.
- Fixed custom head content being active on settings pages due to route
  name changes, for when viewing settings, in last release.

Fixes #3356 and #3355

app/Http/Controllers/SettingController.php
resources/views/common/custom-head.blade.php
routes/web.php
tests/Settings/CustomHeadContentTest.php
tests/Settings/SettingsTest.php

index 598058ef4822afd80a66a0e445e2bdc8ded2654d..2e46bbe409951ab082a0d47e2dd70132b51b1a65 100644 (file)
@@ -19,9 +19,17 @@ class SettingController extends Controller
     }
 
     /**
-     * Display a listing of the settings.
+     * Handle requests to the settings index path
      */
-    public function index(string $category)
+    public function index()
+    {
+        return redirect('/settings/features');
+    }
+
+    /**
+     * Display the settings for the given category.
+     */
+    public function category(string $category)
     {
         $this->ensureCategoryExists($category);
         $this->checkPermission('settings-manage');
index 7f2e93cdc993e4713d07cd17791e0b4094ac2464..a13215cf813c3d8e9673f2d6c2e4691cb60dfaa4 100644 (file)
@@ -1,6 +1,6 @@
 @inject('headContent', 'BookStack\Theming\CustomHtmlHeadContentProvider')
 
-@if(setting('app-custom-head') && \Route::currentRouteName() !== 'settings')
+@if(setting('app-custom-head') && !request()->routeIs('settings.category'))
 <!-- Start: custom user content -->
 {!! $headContent->forWeb() !!}
 <!-- End: custom user content -->
index 223d97c662d1457416c2c67e022806f086c16a77..37f59b9706e5caf1ce9917846fb136555e42ccf1 100644 (file)
@@ -265,8 +265,8 @@ Route::middleware('auth')->group(function () {
     Route::delete('/settings/webhooks/{id}', [WebhookController::class, 'destroy']);
 
     // Settings
-    Route::redirect('/settings', '/settings/features')->name('settings');
-    Route::get('/settings/{category}', [SettingController::class, 'index']);
+    Route::get('/settings', [SettingController::class, 'index'])->name('settings');
+    Route::get('/settings/{category}', [SettingController::class, 'category'])->name('settings.category');
     Route::post('/settings/{category}', [SettingController::class, 'update']);
 });
 
index eeeab3f45a062c023fa7a89ad8c6b1f56e049701..b2e21b91caeb13e0b5ee649cb501ea2f160568ad 100644 (file)
@@ -26,7 +26,7 @@ class CustomHeadContentTest extends TestCase
     public function test_configured_content_does_not_show_on_settings_page()
     {
         $this->setSettings(['app-custom-head' => '<script>console.log("cat");</script>']);
-        $resp = $this->asAdmin()->get('/settings');
+        $resp = $this->asAdmin()->get('/settings/features');
         $resp->assertDontSee('console.log("cat")', false);
     }
 
index bef354dacc79763d480c85d49e83ed06ac3a2bdb..48840fc0bcae93f5d6327289b8702c782174cc14 100644 (file)
@@ -10,7 +10,11 @@ class SettingsTest extends TestCase
     {
         $resp = $this->asAdmin()->get('/settings');
 
-        $resp->assertRedirect('/settings/features');
+        $resp->assertStatus(302);
+
+        // Manually check path to ensure it's generated as the full path
+        $location = $resp->headers->get('location');
+        $this->assertEquals(url('/settings/features'), $location);
     }
 
     public function test_settings_category_links_work_as_expected()