// List of URIs that should not be collected
'except' => [
+ '/uploads/images/.*', // BookStack image requests
+
'/horizon/.*', // Laravel Horizon requests
'/telescope/.*', // Laravel Telescope requests
'/_debugbar/.*', // Laravel DebugBar requests
*/
public function list()
{
- $books = $this->queries->visibleForList();
+ $books = $this->queries
+ ->visibleForList()
+ ->addSelect(['created_by', 'updated_by']);
return $this->apiListingResponse($books, [
'id', 'name', 'slug', 'description', 'created_at', 'updated_at', 'created_by', 'updated_by', 'owned_by',
*/
public function list()
{
- $shelves = $this->queries->visibleForList();
+ $shelves = $this->queries
+ ->visibleForList()
+ ->addSelect(['created_by', 'updated_by']);
return $this->apiListingResponse($shelves, [
'id', 'name', 'slug', 'description', 'created_at', 'updated_at', 'created_by', 'updated_by', 'owned_by',
namespace BookStack\Entities\Controllers;
use BookStack\Entities\Models\Chapter;
-use BookStack\Entities\Queries\BookQueries;
use BookStack\Entities\Queries\ChapterQueries;
+use BookStack\Entities\Queries\EntityQueries;
use BookStack\Entities\Repos\ChapterRepo;
use BookStack\Exceptions\PermissionsException;
use BookStack\Http\ApiController;
public function __construct(
protected ChapterRepo $chapterRepo,
protected ChapterQueries $queries,
- protected BookQueries $bookQueries,
+ protected EntityQueries $entityQueries,
) {
}
*/
public function list()
{
- $chapters = $this->queries->visibleForList();
+ $chapters = $this->queries->visibleForList()
+ ->addSelect(['created_by', 'updated_by']);
return $this->apiListingResponse($chapters, [
'id', 'book_id', 'name', 'slug', 'description', 'priority',
$requestData = $this->validate($request, $this->rules['create']);
$bookId = $request->get('book_id');
- $book = $this->bookQueries->findVisibleByIdOrFail(intval($bookId));
+ $book = $this->entityQueries->books->findVisibleByIdOrFail(intval($bookId));
$this->checkOwnablePermission('chapter-create', $book);
$chapter = $this->chapterRepo->create($requestData, $book);
$chapter = $this->queries->findVisibleByIdOrFail(intval($id));
$chapter = $this->forJsonDisplay($chapter);
- $chapter->load([
- 'createdBy', 'updatedBy', 'ownedBy',
- 'pages' => function (HasMany $query) {
- $query->scopes('visible')->get(['id', 'name', 'slug']);
- }
- ]);
+ $chapter->load(['createdBy', 'updatedBy', 'ownedBy']);
+
+ // Note: More fields than usual here, for backwards compatibility,
+ // due to previously accidentally including more fields that desired.
+ $pages = $this->entityQueries->pages->visibleForChapterList($chapter->id)
+ ->addSelect(['created_by', 'updated_by', 'revision_count', 'editor'])
+ ->get();
+ $chapter->setRelation('pages', $pages);
return response()->json($chapter);
}
$this->checkOwnablePermission('chapter-view', $chapter);
$sidebarTree = (new BookContents($chapter->book))->getTree();
- $pages = $chapter->getVisiblePages();
+ $pages = $this->entityQueries->pages->visibleForChapterList($chapter->id)->get();
+
$nextPreviousLocator = new NextPreviousContentLocator($chapter, $sidebarTree);
View::incrementFor($chapter);
*/
public function list()
{
- $pages = $this->queries->visibleForList();
+ $pages = $this->queries->visibleForList()
+ ->addSelect(['created_by', 'updated_by', 'revision_count', 'editor']);
return $this->apiListingResponse($pages, [
'id', 'book_id', 'chapter_id', 'name', 'slug', 'priority',
->select($this->mergeBookSlugForSelect(static::$listAttributes));
}
+ public function visibleForChapterList(int $chapterId): Builder
+ {
+ return $this->visibleForList()
+ ->where('chapter_id', '=', $chapterId)
+ ->orderBy('draft', 'desc')
+ ->orderBy('priority', 'asc');
+ }
+
public function visibleWithContents(): Builder
{
return $this->start()
'id' => $firstBook->id,
'name' => $firstBook->name,
'slug' => $firstBook->slug,
+ 'owned_by' => $firstBook->owned_by,
+ 'created_by' => $firstBook->created_by,
+ 'updated_by' => $firstBook->updated_by,
],
]]);
}
'book_id' => $firstChapter->book->id,
'priority' => $firstChapter->priority,
'book_slug' => $firstChapter->book->slug,
+ 'owned_by' => $firstChapter->owned_by,
+ 'created_by' => $firstChapter->created_by,
+ 'updated_by' => $firstChapter->updated_by,
],
]]);
}
'id' => $page->id,
'slug' => $page->slug,
'name' => $page->name,
+ 'owned_by' => $page->owned_by,
+ 'created_by' => $page->created_by,
+ 'updated_by' => $page->updated_by,
+ 'book_id' => $page->id,
+ 'chapter_id' => $chapter->id,
+ 'priority' => $page->priority,
+ 'book_slug' => $chapter->book->slug,
+ 'draft' => $page->draft,
+ 'template' => $page->template,
+ 'editor' => $page->editor,
],
],
'default_template_id' => null,
'slug' => $firstPage->slug,
'book_id' => $firstPage->book->id,
'priority' => $firstPage->priority,
+ 'owned_by' => $firstPage->owned_by,
+ 'created_by' => $firstPage->created_by,
+ 'updated_by' => $firstPage->updated_by,
+ 'revision_count' => $firstPage->revision_count,
],
]]);
}
'id' => $firstBookshelf->id,
'name' => $firstBookshelf->name,
'slug' => $firstBookshelf->slug,
+ 'owned_by' => $firstBookshelf->owned_by,
+ 'created_by' => $firstBookshelf->created_by,
+ 'updated_by' => $firstBookshelf->updated_by,
],
]]);
}