Fixed settings redirect issue and custom head display

- 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
This commit is contained in:
Dan Brown 2022-03-30 19:15:24 +01:00
parent 135022136a
commit da4308bb0f
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
5 changed files with 19 additions and 7 deletions

View 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');

View 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 -->

View 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']);
});

View 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);
}

View 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()