mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-10-12 02:01:37 +00:00
Books: On delete, redirect to shelf if in context
For #6029 Added tests to cover
This commit is contained in:
@@ -224,9 +224,14 @@ class BookController extends Controller
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
|
||||
$this->checkOwnablePermission(Permission::BookDelete, $book);
|
||||
$contextShelf = $this->shelfContext->getContextualShelfForBook($book);
|
||||
|
||||
$this->bookRepo->destroy($book);
|
||||
|
||||
if ($contextShelf) {
|
||||
return redirect($contextShelf->getUrl());
|
||||
}
|
||||
|
||||
return redirect('/books');
|
||||
}
|
||||
|
||||
|
||||
@@ -154,6 +154,20 @@ class BookTest extends TestCase
|
||||
$this->assertNotificationContains($redirectReq, 'Book Successfully Deleted');
|
||||
}
|
||||
|
||||
public function test_delete_with_shelf_context_returns_to_shelf_view_after_delete()
|
||||
{
|
||||
$shelf = $this->entities->shelfHasBooks();
|
||||
/** @var Book $book */
|
||||
$book = $shelf->books()->first();
|
||||
|
||||
$this->asEditor()->get($shelf->getUrl());
|
||||
$this->get($book->getUrl());
|
||||
$this->get($book->getUrl('/delete'));
|
||||
$resp = $this->delete($book->getUrl());
|
||||
|
||||
$resp->assertRedirect($shelf->getUrl());
|
||||
}
|
||||
|
||||
public function test_cancel_on_create_page_leads_back_to_books_listing()
|
||||
{
|
||||
$resp = $this->asEditor()->get('/create-book');
|
||||
|
||||
@@ -110,6 +110,14 @@ class EntityProvider
|
||||
return $shelf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a shelf that has books assigned.
|
||||
*/
|
||||
public function shelfHasBooks(): Bookshelf
|
||||
{
|
||||
return $this->shelf(fn(Builder $query) => $query->whereHas('books'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all entity types from the system.
|
||||
* @return array{page: Page, chapter: Chapter, book: Book, bookshelf: Bookshelf}
|
||||
|
||||
Reference in New Issue
Block a user