Skip to content

Commit

Permalink
Updated shelf-list view to enforce view permissions for child books
Browse files Browse the repository at this point in the history
- Aligned shelf-homepage behaviour to match
- Updated testing to cover.

For #2111
  • Loading branch information
ssddanbrown committed May 12, 2020
1 parent d3ec38b commit 9666c8c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
6 changes: 4 additions & 2 deletions app/Entities/Repos/BookshelfRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ public function __construct(BaseRepo $baseRepo)
*/
public function getAllPaginated(int $count = 20, string $sort = 'name', string $order = 'asc'): LengthAwarePaginator
{
return Bookshelf::visible()->with('visibleBooks')
->orderBy($sort, $order)->paginate($count);
return Bookshelf::visible()
->with('visibleBooks')
->orderBy($sort, $order)
->paginate($count);
}

/**
Expand Down
4 changes: 0 additions & 4 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ public function index()
}

if ($homepageOption === 'bookshelves') {
$shelfRepo = app(BookshelfRepo::class);
$shelves = app(BookshelfRepo::class)->getAllPaginated(18, $commonData['sort'], $commonData['order']);
foreach ($shelves as $shelf) {
$shelf->books = $shelf->visibleBooks;
}
$data = array_merge($commonData, ['shelves' => $shelves]);
return view('common.home-shelves', $data);
}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/shelves/list-item.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>
</a>
<div class="entity-shelf-books grid third gap-y-xs entity-list-item-children">
@foreach($shelf->books as $book)
@foreach($shelf->visibleBooks as $book)
<div>
<a href="{{ $book->getUrl('?shelf=' . $shelf->id) }}" class="entity-chip text-book">
@icon('book')
Expand Down
19 changes: 19 additions & 0 deletions tests/Entity/BookShelfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ public function test_shelves_page_contains_create_link()
$resp->assertElementContains('a', 'New Shelf');
}

public function test_book_not_visible_in_shelf_list_view_if_user_cant_view_shelf()
{
config()->set([
'app.views.bookshelves' => 'list',
]);
$shelf = Bookshelf::query()->first();
$book = $shelf->books()->first();

$resp = $this->asEditor()->get('/shelves');
$resp->assertSee($book->name);
$resp->assertSee($book->getUrl());

$this->setEntityRestrictions($book, []);

$resp = $this->asEditor()->get('/shelves');
$resp->assertDontSee($book->name);
$resp->assertDontSee($book->getUrl());
}

public function test_shelves_create()
{
$booksToInclude = Book::take(2)->get();
Expand Down

0 comments on commit 9666c8c

Please sign in to comment.