Skip to content

Commit 448ac61

Browse files
committed
Merge branch 'master' into release
2 parents 753f639 + 8933179 commit 448ac61

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

app/Http/Controllers/BookController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function sort($bookSlug)
151151
{
152152
$book = $this->bookRepo->getBySlug($bookSlug);
153153
$this->checkOwnablePermission('book-update', $book);
154-
$bookChildren = $this->bookRepo->getChildren($book);
154+
$bookChildren = $this->bookRepo->getChildren($book, true);
155155
$books = $this->bookRepo->getAll(false);
156156
$this->setPageTitle('Sort Book ' . $book->getShortName());
157157
return view('books/sort', ['book' => $book, 'current' => $book, 'books' => $books, 'bookChildren' => $bookChildren]);

app/Repos/BookRepo.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,23 @@ public function findSuitableSlug($name, $currentId = false)
198198
* Returns a sorted collection of Pages and Chapters.
199199
* Loads the bookslug onto child elements to prevent access database access for getting the slug.
200200
* @param Book $book
201+
* @param bool $filterDrafts
201202
* @return mixed
202203
*/
203-
public function getChildren(Book $book)
204+
public function getChildren(Book $book, $filterDrafts = false)
204205
{
205206
$pageQuery = $book->pages()->where('chapter_id', '=', 0);
206207
$pageQuery = $this->restrictionService->enforcePageRestrictions($pageQuery, 'view');
208+
209+
if ($filterDrafts) {
210+
$pageQuery = $pageQuery->where('draft', '=', false);
211+
}
212+
207213
$pages = $pageQuery->get();
208214

209-
$chapterQuery = $book->chapters()->with(['pages' => function($query) {
215+
$chapterQuery = $book->chapters()->with(['pages' => function($query) use ($filterDrafts) {
210216
$this->restrictionService->enforcePageRestrictions($query, 'view');
217+
if ($filterDrafts) $query->where('draft', '=', false);
211218
}]);
212219
$chapterQuery = $this->restrictionService->enforceChapterRestrictions($chapterQuery, 'view');
213220
$chapters = $chapterQuery->get();

app/Repos/PageRepo.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ public function publishDraft(Page $draftPage, array $input)
154154
/**
155155
* Get a new draft page instance.
156156
* @param Book $book
157-
* @param Chapter|null $chapter
157+
* @param Chapter|bool $chapter
158158
* @return static
159159
*/
160-
public function getDraftPage(Book $book, $chapter)
160+
public function getDraftPage(Book $book, $chapter = false)
161161
{
162162
$page = $this->page->newInstance();
163163
$page->name = 'New Page';

resources/assets/js/pages/page-form.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var mceOptions = module.exports = {
1111
extended_valid_elements: 'pre[*]',
1212
automatic_uploads: false,
1313
valid_children: "-div[p|pre|h1|h2|h3|h4|h5|h6|blockquote]",
14-
plugins: "image table textcolor paste link fullscreen imagetools code hr autosave",
14+
plugins: "image table textcolor paste link fullscreen imagetools code hr autosave lists",
1515
imagetools_toolbar: 'imageoptions',
1616
toolbar: "undo redo | styleselect | bold italic underline strikethrough superscript subscript | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table image-insert link hr | removeformat code fullscreen",
1717
content_style: "body {padding-left: 15px !important; padding-right: 15px !important; margin:0!important; margin-left:auto!important;margin-right:auto!important;}",

tests/Entity/SortTest.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
class SortTest extends TestCase
4+
{
5+
protected $book;
6+
7+
public function setUp()
8+
{
9+
parent::setUp();
10+
$this->book = \BookStack\Book::first();
11+
}
12+
13+
public function test_drafts_do_not_show_up()
14+
{
15+
$this->asAdmin();
16+
$pageRepo = app('\BookStack\Repos\PageRepo');
17+
$draft = $pageRepo->getDraftPage($this->book);
18+
19+
$this->visit($this->book->getUrl())
20+
->see($draft->name)
21+
->visit($this->book->getUrl() . '/sort')
22+
->dontSee($draft->name);
23+
}
24+
25+
}

0 commit comments

Comments
 (0)