mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-04-15 17:24:11 +00:00
Prevented "Recently Viewed" homepage list showing non-user-viewed items
Triggered when the user has no/limited views. Added a test to cover. Closes #2703
This commit is contained in:
parent
c4e31a0d5e
commit
83b576eb19
2 changed files with 14 additions and 0 deletions
|
@ -96,6 +96,7 @@ class ViewService
|
||||||
/** @var Entity $instance */
|
/** @var Entity $instance */
|
||||||
foreach ($this->entityProvider->all() as $name => $instance) {
|
foreach ($this->entityProvider->all() as $name => $instance) {
|
||||||
$items = $instance::visible()->withLastView()
|
$items = $instance::visible()->withLastView()
|
||||||
|
->having('last_viewed_at', '>', 0)
|
||||||
->orderBy('last_viewed_at', 'desc')
|
->orderBy('last_viewed_at', 'desc')
|
||||||
->skip($count * ($page - 1))
|
->skip($count * ($page - 1))
|
||||||
->take($count)
|
->take($count)
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
<?php namespace Tests;
|
<?php namespace Tests;
|
||||||
|
|
||||||
|
use BookStack\Auth\Role;
|
||||||
|
use BookStack\Auth\User;
|
||||||
use BookStack\Entities\Models\Bookshelf;
|
use BookStack\Entities\Models\Bookshelf;
|
||||||
|
use BookStack\Entities\Models\Page;
|
||||||
|
|
||||||
class HomepageTest extends TestCase
|
class HomepageTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -141,4 +144,14 @@ class HomepageTest extends TestCase
|
||||||
$homeVisit->assertElementContains('.content-wrap', $shelf->name);
|
$homeVisit->assertElementContains('.content-wrap', $shelf->name);
|
||||||
$homeVisit->assertElementContains('.content-wrap', $book->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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue