]> BookStack Code Mirror - bookstack/commitdiff
Prevented "Recently Viewed" homepage list showing non-user-viewed items
authorDan Brown <redacted>
Tue, 27 Apr 2021 20:05:01 +0000 (21:05 +0100)
committerDan Brown <redacted>
Tue, 27 Apr 2021 20:05:01 +0000 (21:05 +0100)
Triggered when the user has no/limited views. Added a test to cover.
Closes #2703

app/Actions/ViewService.php
tests/HomepageTest.php

index f04384536ec8586a7a15153523b0196a1f3c3d95..a4e620d4be9dfd2761863bc784a5ef0a798f5f3a 100644 (file)
@@ -96,6 +96,7 @@ class ViewService
         /** @var Entity $instance */
         foreach ($this->entityProvider->all() as $name => $instance) {
             $items = $instance::visible()->withLastView()
+                ->having('last_viewed_at', '>', 0)
                 ->orderBy('last_viewed_at', 'desc')
                 ->skip($count * ($page - 1))
                 ->take($count)
index 943a3160a1915af2a803ed88cd82411e67f2336d..a8e33465d108b1b9ad5000ef796ce761789b3db4 100644 (file)
@@ -1,6 +1,9 @@
 <?php namespace Tests;
 
+use BookStack\Auth\Role;
+use BookStack\Auth\User;
 use BookStack\Entities\Models\Bookshelf;
+use BookStack\Entities\Models\Page;
 
 class HomepageTest extends TestCase
 {
@@ -141,4 +144,14 @@ class HomepageTest extends TestCase
         $homeVisit->assertElementContains('.content-wrap', $shelf->name);
         $homeVisit->assertElementContains('.content-wrap', $book->name);
     }
+
+    public function test_new_users_dont_have_any_recently_viewed()
+    {
+        $user = factory(User::class)->create();
+        $viewRole = Role::getRole('Viewer');
+        $user->attachRole($viewRole);
+
+        $homeVisit = $this->actingAs($user)->get('/');
+        $homeVisit->assertElementContains('#recently-viewed', 'You have not viewed any pages');
+    }
 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.