diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index c55cc9ab8..839590c95 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -13,6 +13,8 @@ class Kernel extends HttpKernel */ protected $middleware = [ \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, + \Illuminate\Session\Middleware\StartSession::class, + \Illuminate\View\Middleware\ShareErrorsFromSession::class, ]; /** @@ -24,8 +26,6 @@ class Kernel extends HttpKernel 'web' => [ \BookStack\Http\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, - \Illuminate\Session\Middleware\StartSession::class, - \Illuminate\View\Middleware\ShareErrorsFromSession::class, \BookStack\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, \BookStack\Http\Middleware\Localization::class diff --git a/app/helpers.php b/app/helpers.php index f69f2c174..153f1e49f 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -37,6 +37,15 @@ function user() return auth()->user() ?: \BookStack\User::getDefault(); } +/** + * Check if current user is a signed in user. + * @return bool + */ +function signedInUser() +{ + return auth()->user() && !auth()->user()->isDefault(); +} + /** * Check if the current user has a permission. * If an ownable element is passed in the jointPermissions are checked against diff --git a/resources/views/base.blade.php b/resources/views/base.blade.php index 43f22d89a..a98a37131 100644 --- a/resources/views/base.blade.php +++ b/resources/views/base.blade.php @@ -55,15 +55,15 @@
- @if(isset($signedIn) && $signedIn) - @include('partials._header-dropdown', ['currentUser' => $currentUser]) + @if(signedInUser()) + @include('partials._header-dropdown', ['currentUser' => user()]) @endif
diff --git a/resources/views/errors/404.blade.php b/resources/views/errors/404.blade.php index c9e600ceb..a0e34e83d 100644 --- a/resources/views/errors/404.blade.php +++ b/resources/views/errors/404.blade.php @@ -10,22 +10,24 @@

{{ trans('errors.sorry_page_not_found') }}

{{ trans('errors.return_home') }}

-
+ @if (setting('app-public') || !user()->isDefault()) +
-
-
-

{{ trans('entities.pages_popular') }}

- @include('partials.entity-list', ['entities' => Views::getPopular(10, 0, [\BookStack\Page::class]), 'style' => 'compact']) +
+
+

{{ trans('entities.pages_popular') }}

+ @include('partials.entity-list', ['entities' => Views::getPopular(10, 0, [\BookStack\Page::class]), 'style' => 'compact']) +
+
+

{{ trans('entities.books_popular') }}

+ @include('partials.entity-list', ['entities' => Views::getPopular(10, 0, [\BookStack\Book::class]), 'style' => 'compact']) +
+
+

{{ trans('entities.chapters_popular') }}

+ @include('partials.entity-list', ['entities' => Views::getPopular(10, 0, [\BookStack\Chapter::class]), 'style' => 'compact']) +
-
-

{{ trans('entities.books_popular') }}

- @include('partials.entity-list', ['entities' => Views::getPopular(10, 0, [\BookStack\Book::class]), 'style' => 'compact']) -
-
-

{{ trans('entities.chapters_popular') }}

- @include('partials.entity-list', ['entities' => Views::getPopular(10, 0, [\BookStack\Chapter::class]), 'style' => 'compact']) -
-
+ @endif
@stop \ No newline at end of file diff --git a/tests/PublicActionTest.php b/tests/PublicActionTest.php index 422511dbf..62a321b5e 100644 --- a/tests/PublicActionTest.php +++ b/tests/PublicActionTest.php @@ -80,4 +80,14 @@ class PublicActionTest extends BrowserKitTest ]); } + public function test_content_not_listed_on_404_for_public_users() + { + $page = \BookStack\Page::first(); + $this->asAdmin()->visit($page->getUrl()); + Auth::logout(); + view()->share('pageTitle', ''); + $this->forceVisit('/cats/dogs/hippos'); + $this->dontSee($page->name); + } + } \ No newline at end of file