mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-07 23:03:00 +03:00
Queries: Extracted PageRepo queries to own class
Started new class for PageRevisions too as part of these changes
This commit is contained in:
@@ -124,7 +124,7 @@ class BookController extends Controller
|
||||
*/
|
||||
public function show(Request $request, ActivityQueries $activities, string $slug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlug($slug);
|
||||
$book = $this->queries->findVisibleBySlugOrFail($slug);
|
||||
$bookChildren = (new BookContents($book))->getTree(true);
|
||||
$bookParentShelves = $book->shelves()->scopes('visible')->get();
|
||||
|
||||
@@ -151,7 +151,7 @@ class BookController extends Controller
|
||||
*/
|
||||
public function edit(string $slug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlug($slug);
|
||||
$book = $this->queries->findVisibleBySlugOrFail($slug);
|
||||
$this->checkOwnablePermission('book-update', $book);
|
||||
$this->setPageTitle(trans('entities.books_edit_named', ['bookName' => $book->getShortName()]));
|
||||
|
||||
@@ -167,7 +167,7 @@ class BookController extends Controller
|
||||
*/
|
||||
public function update(Request $request, string $slug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlug($slug);
|
||||
$book = $this->queries->findVisibleBySlugOrFail($slug);
|
||||
$this->checkOwnablePermission('book-update', $book);
|
||||
|
||||
$validated = $this->validate($request, [
|
||||
@@ -194,7 +194,7 @@ class BookController extends Controller
|
||||
*/
|
||||
public function showDelete(string $bookSlug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlug($bookSlug);
|
||||
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
|
||||
$this->checkOwnablePermission('book-delete', $book);
|
||||
$this->setPageTitle(trans('entities.books_delete_named', ['bookName' => $book->getShortName()]));
|
||||
|
||||
@@ -208,7 +208,7 @@ class BookController extends Controller
|
||||
*/
|
||||
public function destroy(string $bookSlug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlug($bookSlug);
|
||||
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
|
||||
$this->checkOwnablePermission('book-delete', $book);
|
||||
|
||||
$this->bookRepo->destroy($book);
|
||||
@@ -223,7 +223,7 @@ class BookController extends Controller
|
||||
*/
|
||||
public function showCopy(string $bookSlug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlug($bookSlug);
|
||||
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
|
||||
$this->checkOwnablePermission('book-view', $book);
|
||||
|
||||
session()->flashInput(['name' => $book->name]);
|
||||
@@ -240,7 +240,7 @@ class BookController extends Controller
|
||||
*/
|
||||
public function copy(Request $request, Cloner $cloner, string $bookSlug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlug($bookSlug);
|
||||
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
|
||||
$this->checkOwnablePermission('book-view', $book);
|
||||
$this->checkPermission('book-create-all');
|
||||
|
||||
@@ -256,7 +256,7 @@ class BookController extends Controller
|
||||
*/
|
||||
public function convertToShelf(HierarchyTransformer $transformer, string $bookSlug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlug($bookSlug);
|
||||
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
|
||||
$this->checkOwnablePermission('book-update', $book);
|
||||
$this->checkOwnablePermission('book-delete', $book);
|
||||
$this->checkPermission('bookshelf-create-all');
|
||||
|
@@ -23,7 +23,7 @@ class BookExportController extends Controller
|
||||
*/
|
||||
public function pdf(string $bookSlug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlug($bookSlug);
|
||||
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
|
||||
$pdfContent = $this->exportFormatter->bookToPdf($book);
|
||||
|
||||
return $this->download()->directly($pdfContent, $bookSlug . '.pdf');
|
||||
@@ -36,7 +36,7 @@ class BookExportController extends Controller
|
||||
*/
|
||||
public function html(string $bookSlug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlug($bookSlug);
|
||||
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
|
||||
$htmlContent = $this->exportFormatter->bookToContainedHtml($book);
|
||||
|
||||
return $this->download()->directly($htmlContent, $bookSlug . '.html');
|
||||
@@ -47,7 +47,7 @@ class BookExportController extends Controller
|
||||
*/
|
||||
public function plainText(string $bookSlug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlug($bookSlug);
|
||||
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
|
||||
$textContent = $this->exportFormatter->bookToPlainText($book);
|
||||
|
||||
return $this->download()->directly($textContent, $bookSlug . '.txt');
|
||||
@@ -58,7 +58,7 @@ class BookExportController extends Controller
|
||||
*/
|
||||
public function markdown(string $bookSlug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlug($bookSlug);
|
||||
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
|
||||
$textContent = $this->exportFormatter->bookToMarkdown($book);
|
||||
|
||||
return $this->download()->directly($textContent, $bookSlug . '.md');
|
||||
|
@@ -22,7 +22,7 @@ class BookSortController extends Controller
|
||||
*/
|
||||
public function show(string $bookSlug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlug($bookSlug);
|
||||
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
|
||||
$this->checkOwnablePermission('book-update', $book);
|
||||
|
||||
$bookChildren = (new BookContents($book))->getTree(false);
|
||||
@@ -38,7 +38,7 @@ class BookSortController extends Controller
|
||||
*/
|
||||
public function showItem(string $bookSlug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlug($bookSlug);
|
||||
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
|
||||
$bookChildren = (new BookContents($book))->getTree();
|
||||
|
||||
return view('books.parts.sort-box', ['book' => $book, 'bookChildren' => $bookChildren]);
|
||||
@@ -49,7 +49,7 @@ class BookSortController extends Controller
|
||||
*/
|
||||
public function update(Request $request, string $bookSlug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlug($bookSlug);
|
||||
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
|
||||
$this->checkOwnablePermission('book-update', $book);
|
||||
|
||||
// Return if no map sent
|
||||
|
@@ -103,7 +103,7 @@ class BookshelfController extends Controller
|
||||
*/
|
||||
public function show(Request $request, ActivityQueries $activities, string $slug)
|
||||
{
|
||||
$shelf = $this->queries->findVisibleBySlug($slug);
|
||||
$shelf = $this->queries->findVisibleBySlugOrFail($slug);
|
||||
$this->checkOwnablePermission('bookshelf-view', $shelf);
|
||||
|
||||
$listOptions = SimpleListOptions::fromRequest($request, 'shelf_books')->withSortOptions([
|
||||
@@ -141,7 +141,7 @@ class BookshelfController extends Controller
|
||||
*/
|
||||
public function edit(string $slug)
|
||||
{
|
||||
$shelf = $this->queries->findVisibleBySlug($slug);
|
||||
$shelf = $this->queries->findVisibleBySlugOrFail($slug);
|
||||
$this->checkOwnablePermission('bookshelf-update', $shelf);
|
||||
|
||||
$shelfBookIds = $shelf->books()->get(['id'])->pluck('id');
|
||||
@@ -164,7 +164,7 @@ class BookshelfController extends Controller
|
||||
*/
|
||||
public function update(Request $request, string $slug)
|
||||
{
|
||||
$shelf = $this->queries->findVisibleBySlug($slug);
|
||||
$shelf = $this->queries->findVisibleBySlugOrFail($slug);
|
||||
$this->checkOwnablePermission('bookshelf-update', $shelf);
|
||||
$validated = $this->validate($request, [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
@@ -190,7 +190,7 @@ class BookshelfController extends Controller
|
||||
*/
|
||||
public function showDelete(string $slug)
|
||||
{
|
||||
$shelf = $this->queries->findVisibleBySlug($slug);
|
||||
$shelf = $this->queries->findVisibleBySlugOrFail($slug);
|
||||
$this->checkOwnablePermission('bookshelf-delete', $shelf);
|
||||
|
||||
$this->setPageTitle(trans('entities.shelves_delete_named', ['name' => $shelf->getShortName()]));
|
||||
@@ -205,7 +205,7 @@ class BookshelfController extends Controller
|
||||
*/
|
||||
public function destroy(string $slug)
|
||||
{
|
||||
$shelf = $this->queries->findVisibleBySlug($slug);
|
||||
$shelf = $this->queries->findVisibleBySlugOrFail($slug);
|
||||
$this->checkOwnablePermission('bookshelf-delete', $shelf);
|
||||
|
||||
$this->shelfRepo->destroy($shelf);
|
||||
|
@@ -37,7 +37,7 @@ class ChapterController extends Controller
|
||||
*/
|
||||
public function create(string $bookSlug)
|
||||
{
|
||||
$book = $this->entityQueries->books->findVisibleBySlug($bookSlug);
|
||||
$book = $this->entityQueries->books->findVisibleBySlugOrFail($bookSlug);
|
||||
$this->checkOwnablePermission('chapter-create', $book);
|
||||
|
||||
$this->setPageTitle(trans('entities.chapters_create'));
|
||||
@@ -62,7 +62,7 @@ class ChapterController extends Controller
|
||||
'default_template_id' => ['nullable', 'integer'],
|
||||
]);
|
||||
|
||||
$book = $this->entityQueries->books->findVisibleBySlug($bookSlug);
|
||||
$book = $this->entityQueries->books->findVisibleBySlugOrFail($bookSlug);
|
||||
$this->checkOwnablePermission('chapter-create', $book);
|
||||
|
||||
$chapter = $this->chapterRepo->create($validated, $book);
|
||||
@@ -75,7 +75,7 @@ class ChapterController extends Controller
|
||||
*/
|
||||
public function show(string $bookSlug, string $chapterSlug)
|
||||
{
|
||||
$chapter = $this->queries->findVisibleBySlugs($bookSlug, $chapterSlug);
|
||||
$chapter = $this->queries->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
|
||||
$this->checkOwnablePermission('chapter-view', $chapter);
|
||||
|
||||
$sidebarTree = (new BookContents($chapter->book))->getTree();
|
||||
@@ -103,7 +103,7 @@ class ChapterController extends Controller
|
||||
*/
|
||||
public function edit(string $bookSlug, string $chapterSlug)
|
||||
{
|
||||
$chapter = $this->queries->findVisibleBySlugs($bookSlug, $chapterSlug);
|
||||
$chapter = $this->queries->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
|
||||
$this->checkOwnablePermission('chapter-update', $chapter);
|
||||
|
||||
$this->setPageTitle(trans('entities.chapters_edit_named', ['chapterName' => $chapter->getShortName()]));
|
||||
@@ -125,7 +125,7 @@ class ChapterController extends Controller
|
||||
'default_template_id' => ['nullable', 'integer'],
|
||||
]);
|
||||
|
||||
$chapter = $this->queries->findVisibleBySlugs($bookSlug, $chapterSlug);
|
||||
$chapter = $this->queries->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
|
||||
$this->checkOwnablePermission('chapter-update', $chapter);
|
||||
|
||||
$this->chapterRepo->update($chapter, $validated);
|
||||
@@ -140,7 +140,7 @@ class ChapterController extends Controller
|
||||
*/
|
||||
public function showDelete(string $bookSlug, string $chapterSlug)
|
||||
{
|
||||
$chapter = $this->queries->findVisibleBySlugs($bookSlug, $chapterSlug);
|
||||
$chapter = $this->queries->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
|
||||
$this->checkOwnablePermission('chapter-delete', $chapter);
|
||||
|
||||
$this->setPageTitle(trans('entities.chapters_delete_named', ['chapterName' => $chapter->getShortName()]));
|
||||
@@ -156,7 +156,7 @@ class ChapterController extends Controller
|
||||
*/
|
||||
public function destroy(string $bookSlug, string $chapterSlug)
|
||||
{
|
||||
$chapter = $this->queries->findVisibleBySlugs($bookSlug, $chapterSlug);
|
||||
$chapter = $this->queries->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
|
||||
$this->checkOwnablePermission('chapter-delete', $chapter);
|
||||
|
||||
$this->chapterRepo->destroy($chapter);
|
||||
@@ -171,7 +171,7 @@ class ChapterController extends Controller
|
||||
*/
|
||||
public function showMove(string $bookSlug, string $chapterSlug)
|
||||
{
|
||||
$chapter = $this->queries->findVisibleBySlugs($bookSlug, $chapterSlug);
|
||||
$chapter = $this->queries->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
|
||||
$this->setPageTitle(trans('entities.chapters_move_named', ['chapterName' => $chapter->getShortName()]));
|
||||
$this->checkOwnablePermission('chapter-update', $chapter);
|
||||
$this->checkOwnablePermission('chapter-delete', $chapter);
|
||||
@@ -189,7 +189,7 @@ class ChapterController extends Controller
|
||||
*/
|
||||
public function move(Request $request, string $bookSlug, string $chapterSlug)
|
||||
{
|
||||
$chapter = $this->queries->findVisibleBySlugs($bookSlug, $chapterSlug);
|
||||
$chapter = $this->queries->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
|
||||
$this->checkOwnablePermission('chapter-update', $chapter);
|
||||
$this->checkOwnablePermission('chapter-delete', $chapter);
|
||||
|
||||
@@ -218,7 +218,7 @@ class ChapterController extends Controller
|
||||
*/
|
||||
public function showCopy(string $bookSlug, string $chapterSlug)
|
||||
{
|
||||
$chapter = $this->queries->findVisibleBySlugs($bookSlug, $chapterSlug);
|
||||
$chapter = $this->queries->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
|
||||
$this->checkOwnablePermission('chapter-view', $chapter);
|
||||
|
||||
session()->flashInput(['name' => $chapter->name]);
|
||||
@@ -237,7 +237,7 @@ class ChapterController extends Controller
|
||||
*/
|
||||
public function copy(Request $request, Cloner $cloner, string $bookSlug, string $chapterSlug)
|
||||
{
|
||||
$chapter = $this->queries->findVisibleBySlugs($bookSlug, $chapterSlug);
|
||||
$chapter = $this->queries->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
|
||||
$this->checkOwnablePermission('chapter-view', $chapter);
|
||||
|
||||
$entitySelection = $request->get('entity_selection') ?: null;
|
||||
@@ -263,7 +263,7 @@ class ChapterController extends Controller
|
||||
*/
|
||||
public function convertToBook(HierarchyTransformer $transformer, string $bookSlug, string $chapterSlug)
|
||||
{
|
||||
$chapter = $this->queries->findVisibleBySlugs($bookSlug, $chapterSlug);
|
||||
$chapter = $this->queries->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
|
||||
$this->checkOwnablePermission('chapter-update', $chapter);
|
||||
$this->checkOwnablePermission('chapter-delete', $chapter);
|
||||
$this->checkPermission('book-create-all');
|
||||
|
@@ -25,7 +25,7 @@ class ChapterExportController extends Controller
|
||||
*/
|
||||
public function pdf(string $bookSlug, string $chapterSlug)
|
||||
{
|
||||
$chapter = $this->queries->findVisibleBySlugs($bookSlug, $chapterSlug);
|
||||
$chapter = $this->queries->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
|
||||
$pdfContent = $this->exportFormatter->chapterToPdf($chapter);
|
||||
|
||||
return $this->download()->directly($pdfContent, $chapterSlug . '.pdf');
|
||||
@@ -39,7 +39,7 @@ class ChapterExportController extends Controller
|
||||
*/
|
||||
public function html(string $bookSlug, string $chapterSlug)
|
||||
{
|
||||
$chapter = $this->queries->findVisibleBySlugs($bookSlug, $chapterSlug);
|
||||
$chapter = $this->queries->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
|
||||
$containedHtml = $this->exportFormatter->chapterToContainedHtml($chapter);
|
||||
|
||||
return $this->download()->directly($containedHtml, $chapterSlug . '.html');
|
||||
@@ -52,7 +52,7 @@ class ChapterExportController extends Controller
|
||||
*/
|
||||
public function plainText(string $bookSlug, string $chapterSlug)
|
||||
{
|
||||
$chapter = $this->queries->findVisibleBySlugs($bookSlug, $chapterSlug);
|
||||
$chapter = $this->queries->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
|
||||
$chapterText = $this->exportFormatter->chapterToPlainText($chapter);
|
||||
|
||||
return $this->download()->directly($chapterText, $chapterSlug . '.txt');
|
||||
@@ -65,7 +65,7 @@ class ChapterExportController extends Controller
|
||||
*/
|
||||
public function markdown(string $bookSlug, string $chapterSlug)
|
||||
{
|
||||
$chapter = $this->queries->findVisibleBySlugs($bookSlug, $chapterSlug);
|
||||
$chapter = $this->queries->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
|
||||
$chapterText = $this->exportFormatter->chapterToMarkdown($chapter);
|
||||
|
||||
return $this->download()->directly($chapterText, $chapterSlug . '.md');
|
||||
|
@@ -5,6 +5,7 @@ namespace BookStack\Entities\Controllers;
|
||||
use BookStack\Entities\Models\Book;
|
||||
use BookStack\Entities\Models\Chapter;
|
||||
use BookStack\Entities\Models\Page;
|
||||
use BookStack\Entities\Queries\PageQueries;
|
||||
use BookStack\Entities\Repos\PageRepo;
|
||||
use BookStack\Exceptions\PermissionsException;
|
||||
use BookStack\Http\ApiController;
|
||||
@@ -35,7 +36,8 @@ class PageApiController extends ApiController
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
protected PageRepo $pageRepo
|
||||
protected PageRepo $pageRepo,
|
||||
protected PageQueries $queries,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -97,7 +99,7 @@ class PageApiController extends ApiController
|
||||
*/
|
||||
public function read(string $id)
|
||||
{
|
||||
$page = $this->pageRepo->getById($id, []);
|
||||
$page = $this->queries->findVisibleByIdOrFail($id);
|
||||
|
||||
return response()->json($page->forJsonDisplay());
|
||||
}
|
||||
@@ -113,7 +115,7 @@ class PageApiController extends ApiController
|
||||
{
|
||||
$requestData = $this->validate($request, $this->rules['update']);
|
||||
|
||||
$page = $this->pageRepo->getById($id, []);
|
||||
$page = $this->queries->findVisibleByIdOrFail($id);
|
||||
$this->checkOwnablePermission('page-update', $page);
|
||||
|
||||
$parent = null;
|
||||
@@ -148,7 +150,7 @@ class PageApiController extends ApiController
|
||||
*/
|
||||
public function delete(string $id)
|
||||
{
|
||||
$page = $this->pageRepo->getById($id, []);
|
||||
$page = $this->queries->findVisibleByIdOrFail($id);
|
||||
$this->checkOwnablePermission('page-delete', $page);
|
||||
|
||||
$this->pageRepo->destroy($page);
|
||||
|
@@ -31,7 +31,7 @@ class PageController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected PageRepo $pageRepo,
|
||||
protected PageQueries $pageQueries,
|
||||
protected PageQueries $queries,
|
||||
protected EntityQueries $entityQueries,
|
||||
protected ReferenceFetcher $referenceFetcher
|
||||
) {
|
||||
@@ -44,7 +44,12 @@ class PageController extends Controller
|
||||
*/
|
||||
public function create(string $bookSlug, string $chapterSlug = null)
|
||||
{
|
||||
$parent = $this->pageRepo->getParentFromSlugs($bookSlug, $chapterSlug);
|
||||
if ($chapterSlug) {
|
||||
$parent = $this->entityQueries->chapters->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
|
||||
} else {
|
||||
$parent = $this->entityQueries->books->findVisibleBySlugOrFail($bookSlug);
|
||||
}
|
||||
|
||||
$this->checkOwnablePermission('page-create', $parent);
|
||||
|
||||
// Redirect to draft edit screen if signed in
|
||||
@@ -71,7 +76,12 @@ class PageController extends Controller
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
]);
|
||||
|
||||
$parent = $this->pageRepo->getParentFromSlugs($bookSlug, $chapterSlug);
|
||||
if ($chapterSlug) {
|
||||
$parent = $this->entityQueries->chapters->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
|
||||
} else {
|
||||
$parent = $this->entityQueries->books->findVisibleBySlugOrFail($bookSlug);
|
||||
}
|
||||
|
||||
$this->checkOwnablePermission('page-create', $parent);
|
||||
|
||||
$page = $this->pageRepo->getNewDraftPage($parent);
|
||||
@@ -89,10 +99,10 @@ class PageController extends Controller
|
||||
*/
|
||||
public function editDraft(Request $request, string $bookSlug, int $pageId)
|
||||
{
|
||||
$draft = $this->pageRepo->getById($pageId);
|
||||
$draft = $this->queries->findVisibleByIdOrFail($pageId);
|
||||
$this->checkOwnablePermission('page-create', $draft->getParent());
|
||||
|
||||
$editorData = new PageEditorData($draft, $this->pageRepo, $request->query('editor', ''));
|
||||
$editorData = new PageEditorData($draft, $this->entityQueries, $request->query('editor', ''));
|
||||
$this->setPageTitle(trans('entities.pages_edit_draft'));
|
||||
|
||||
return view('pages.edit', $editorData->getViewData());
|
||||
@@ -109,7 +119,7 @@ class PageController extends Controller
|
||||
$this->validate($request, [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
]);
|
||||
$draftPage = $this->pageRepo->getById($pageId);
|
||||
$draftPage = $this->queries->findVisibleByIdOrFail($pageId);
|
||||
$this->checkOwnablePermission('page-create', $draftPage->getParent());
|
||||
|
||||
$page = $this->pageRepo->publishDraft($draftPage, $request->all());
|
||||
@@ -126,11 +136,12 @@ class PageController extends Controller
|
||||
public function show(string $bookSlug, string $pageSlug)
|
||||
{
|
||||
try {
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
|
||||
} catch (NotFoundException $e) {
|
||||
$page = $this->pageRepo->getByOldSlug($bookSlug, $pageSlug);
|
||||
$revision = $this->entityQueries->revisions->findLatestVersionBySlugs($bookSlug, $pageSlug);
|
||||
$page = $revision->page ?? null;
|
||||
|
||||
if ($page === null) {
|
||||
if (is_null($page)) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
@@ -171,7 +182,7 @@ class PageController extends Controller
|
||||
*/
|
||||
public function getPageAjax(int $pageId)
|
||||
{
|
||||
$page = $this->pageRepo->getById($pageId);
|
||||
$page = $this->queries->findVisibleByIdOrFail($pageId);
|
||||
$page->setHidden(array_diff($page->getHidden(), ['html', 'markdown']));
|
||||
$page->makeHidden(['book']);
|
||||
|
||||
@@ -185,10 +196,10 @@ class PageController extends Controller
|
||||
*/
|
||||
public function edit(Request $request, string $bookSlug, string $pageSlug)
|
||||
{
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
|
||||
$this->checkOwnablePermission('page-update', $page);
|
||||
|
||||
$editorData = new PageEditorData($page, $this->pageRepo, $request->query('editor', ''));
|
||||
$editorData = new PageEditorData($page, $this->entityQueries, $request->query('editor', ''));
|
||||
if ($editorData->getWarnings()) {
|
||||
$this->showWarningNotification(implode("\n", $editorData->getWarnings()));
|
||||
}
|
||||
@@ -209,7 +220,7 @@ class PageController extends Controller
|
||||
$this->validate($request, [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
]);
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
|
||||
$this->checkOwnablePermission('page-update', $page);
|
||||
|
||||
$this->pageRepo->update($page, $request->all());
|
||||
@@ -224,7 +235,7 @@ class PageController extends Controller
|
||||
*/
|
||||
public function saveDraft(Request $request, int $pageId)
|
||||
{
|
||||
$page = $this->pageRepo->getById($pageId);
|
||||
$page = $this->queries->findVisibleByIdOrFail($pageId);
|
||||
$this->checkOwnablePermission('page-update', $page);
|
||||
|
||||
if (!$this->isSignedIn()) {
|
||||
@@ -249,7 +260,7 @@ class PageController extends Controller
|
||||
*/
|
||||
public function redirectFromLink(int $pageId)
|
||||
{
|
||||
$page = $this->pageRepo->getById($pageId);
|
||||
$page = $this->queries->findVisibleByIdOrFail($pageId);
|
||||
|
||||
return redirect($page->getUrl());
|
||||
}
|
||||
@@ -261,7 +272,7 @@ class PageController extends Controller
|
||||
*/
|
||||
public function showDelete(string $bookSlug, string $pageSlug)
|
||||
{
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
|
||||
$this->checkOwnablePermission('page-delete', $page);
|
||||
$this->setPageTitle(trans('entities.pages_delete_named', ['pageName' => $page->getShortName()]));
|
||||
$usedAsTemplate =
|
||||
@@ -283,7 +294,7 @@ class PageController extends Controller
|
||||
*/
|
||||
public function showDeleteDraft(string $bookSlug, int $pageId)
|
||||
{
|
||||
$page = $this->pageRepo->getById($pageId);
|
||||
$page = $this->queries->findVisibleByIdOrFail($pageId);
|
||||
$this->checkOwnablePermission('page-update', $page);
|
||||
$this->setPageTitle(trans('entities.pages_delete_draft_named', ['pageName' => $page->getShortName()]));
|
||||
$usedAsTemplate =
|
||||
@@ -306,7 +317,7 @@ class PageController extends Controller
|
||||
*/
|
||||
public function destroy(string $bookSlug, string $pageSlug)
|
||||
{
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
|
||||
$this->checkOwnablePermission('page-delete', $page);
|
||||
$parent = $page->getParent();
|
||||
|
||||
@@ -323,7 +334,7 @@ class PageController extends Controller
|
||||
*/
|
||||
public function destroyDraft(string $bookSlug, int $pageId)
|
||||
{
|
||||
$page = $this->pageRepo->getById($pageId);
|
||||
$page = $this->queries->findVisibleByIdOrFail($pageId);
|
||||
$book = $page->book;
|
||||
$chapter = $page->chapter;
|
||||
$this->checkOwnablePermission('page-update', $page);
|
||||
@@ -370,7 +381,7 @@ class PageController extends Controller
|
||||
*/
|
||||
public function showMove(string $bookSlug, string $pageSlug)
|
||||
{
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
|
||||
$this->checkOwnablePermission('page-update', $page);
|
||||
$this->checkOwnablePermission('page-delete', $page);
|
||||
|
||||
@@ -388,7 +399,7 @@ class PageController extends Controller
|
||||
*/
|
||||
public function move(Request $request, string $bookSlug, string $pageSlug)
|
||||
{
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
|
||||
$this->checkOwnablePermission('page-update', $page);
|
||||
$this->checkOwnablePermission('page-delete', $page);
|
||||
|
||||
@@ -417,7 +428,7 @@ class PageController extends Controller
|
||||
*/
|
||||
public function showCopy(string $bookSlug, string $pageSlug)
|
||||
{
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
|
||||
$this->checkOwnablePermission('page-view', $page);
|
||||
session()->flashInput(['name' => $page->name]);
|
||||
|
||||
@@ -435,7 +446,7 @@ class PageController extends Controller
|
||||
*/
|
||||
public function copy(Request $request, Cloner $cloner, string $bookSlug, string $pageSlug)
|
||||
{
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
|
||||
$this->checkOwnablePermission('page-view', $page);
|
||||
|
||||
$entitySelection = $request->get('entity_selection') ?: null;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace BookStack\Entities\Controllers;
|
||||
|
||||
use BookStack\Entities\Repos\PageRepo;
|
||||
use BookStack\Entities\Queries\PageQueries;
|
||||
use BookStack\Entities\Tools\ExportFormatter;
|
||||
use BookStack\Entities\Tools\PageContent;
|
||||
use BookStack\Exceptions\NotFoundException;
|
||||
@@ -11,16 +11,10 @@ use Throwable;
|
||||
|
||||
class PageExportController extends Controller
|
||||
{
|
||||
protected $pageRepo;
|
||||
protected $exportFormatter;
|
||||
|
||||
/**
|
||||
* PageExportController constructor.
|
||||
*/
|
||||
public function __construct(PageRepo $pageRepo, ExportFormatter $exportFormatter)
|
||||
{
|
||||
$this->pageRepo = $pageRepo;
|
||||
$this->exportFormatter = $exportFormatter;
|
||||
public function __construct(
|
||||
protected PageQueries $queries,
|
||||
protected ExportFormatter $exportFormatter,
|
||||
) {
|
||||
$this->middleware('can:content-export');
|
||||
}
|
||||
|
||||
@@ -33,7 +27,7 @@ class PageExportController extends Controller
|
||||
*/
|
||||
public function pdf(string $bookSlug, string $pageSlug)
|
||||
{
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
|
||||
$page->html = (new PageContent($page))->render();
|
||||
$pdfContent = $this->exportFormatter->pageToPdf($page);
|
||||
|
||||
@@ -48,7 +42,7 @@ class PageExportController extends Controller
|
||||
*/
|
||||
public function html(string $bookSlug, string $pageSlug)
|
||||
{
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
|
||||
$page->html = (new PageContent($page))->render();
|
||||
$containedHtml = $this->exportFormatter->pageToContainedHtml($page);
|
||||
|
||||
@@ -62,7 +56,7 @@ class PageExportController extends Controller
|
||||
*/
|
||||
public function plainText(string $bookSlug, string $pageSlug)
|
||||
{
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
|
||||
$pageText = $this->exportFormatter->pageToPlainText($page);
|
||||
|
||||
return $this->download()->directly($pageText, $pageSlug . '.txt');
|
||||
@@ -75,7 +69,7 @@ class PageExportController extends Controller
|
||||
*/
|
||||
public function markdown(string $bookSlug, string $pageSlug)
|
||||
{
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$page = $this->queries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
|
||||
$pageText = $this->exportFormatter->pageToMarkdown($page);
|
||||
|
||||
return $this->download()->directly($pageText, $pageSlug . '.md');
|
||||
|
@@ -4,6 +4,7 @@ namespace BookStack\Entities\Controllers;
|
||||
|
||||
use BookStack\Activity\ActivityType;
|
||||
use BookStack\Entities\Models\PageRevision;
|
||||
use BookStack\Entities\Queries\PageQueries;
|
||||
use BookStack\Entities\Repos\PageRepo;
|
||||
use BookStack\Entities\Repos\RevisionRepo;
|
||||
use BookStack\Entities\Tools\PageContent;
|
||||
@@ -18,6 +19,7 @@ class PageRevisionController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected PageRepo $pageRepo,
|
||||
protected PageQueries $pageQueries,
|
||||
protected RevisionRepo $revisionRepo,
|
||||
) {
|
||||
}
|
||||
@@ -29,7 +31,7 @@ class PageRevisionController extends Controller
|
||||
*/
|
||||
public function index(Request $request, string $bookSlug, string $pageSlug)
|
||||
{
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$page = $this->pageQueries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
|
||||
$listOptions = SimpleListOptions::fromRequest($request, 'page_revisions', true)->withSortOptions([
|
||||
'id' => trans('entities.pages_revisions_sort_number')
|
||||
]);
|
||||
@@ -60,7 +62,7 @@ class PageRevisionController extends Controller
|
||||
*/
|
||||
public function show(string $bookSlug, string $pageSlug, int $revisionId)
|
||||
{
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$page = $this->pageQueries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
|
||||
/** @var ?PageRevision $revision */
|
||||
$revision = $page->revisions()->where('id', '=', $revisionId)->first();
|
||||
if ($revision === null) {
|
||||
@@ -89,7 +91,7 @@ class PageRevisionController extends Controller
|
||||
*/
|
||||
public function changes(string $bookSlug, string $pageSlug, int $revisionId)
|
||||
{
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$page = $this->pageQueries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
|
||||
/** @var ?PageRevision $revision */
|
||||
$revision = $page->revisions()->where('id', '=', $revisionId)->first();
|
||||
if ($revision === null) {
|
||||
@@ -121,7 +123,7 @@ class PageRevisionController extends Controller
|
||||
*/
|
||||
public function restore(string $bookSlug, string $pageSlug, int $revisionId)
|
||||
{
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$page = $this->pageQueries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
|
||||
$this->checkOwnablePermission('page-update', $page);
|
||||
|
||||
$page = $this->pageRepo->restoreRevision($page, $revisionId);
|
||||
@@ -136,7 +138,7 @@ class PageRevisionController extends Controller
|
||||
*/
|
||||
public function destroy(string $bookSlug, string $pageSlug, int $revId)
|
||||
{
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$page = $this->pageQueries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
|
||||
$this->checkOwnablePermission('page-delete', $page);
|
||||
|
||||
$revision = $page->revisions()->where('id', '=', $revId)->first();
|
||||
@@ -162,7 +164,7 @@ class PageRevisionController extends Controller
|
||||
*/
|
||||
public function destroyUserDraft(string $pageId)
|
||||
{
|
||||
$page = $this->pageRepo->getById($pageId);
|
||||
$page = $this->pageQueries->findVisibleByIdOrFail($pageId);
|
||||
$this->revisionRepo->deleteDraftsForCurrentUser($page);
|
||||
|
||||
return response('', 200);
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace BookStack\Entities\Controllers;
|
||||
|
||||
use BookStack\Entities\Queries\PageQueries;
|
||||
use BookStack\Entities\Repos\PageRepo;
|
||||
use BookStack\Exceptions\NotFoundException;
|
||||
use BookStack\Http\Controller;
|
||||
@@ -9,14 +10,10 @@ use Illuminate\Http\Request;
|
||||
|
||||
class PageTemplateController extends Controller
|
||||
{
|
||||
protected $pageRepo;
|
||||
|
||||
/**
|
||||
* PageTemplateController constructor.
|
||||
*/
|
||||
public function __construct(PageRepo $pageRepo)
|
||||
{
|
||||
$this->pageRepo = $pageRepo;
|
||||
public function __construct(
|
||||
protected PageRepo $pageRepo,
|
||||
protected PageQueries $pageQueries,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,7 +23,19 @@ class PageTemplateController extends Controller
|
||||
{
|
||||
$page = $request->get('page', 1);
|
||||
$search = $request->get('search', '');
|
||||
$templates = $this->pageRepo->getTemplates(10, $page, $search);
|
||||
$count = 10;
|
||||
|
||||
$query = $this->pageQueries->visibleTemplates()
|
||||
->orderBy('name', 'asc')
|
||||
->skip(($page - 1) * $count)
|
||||
->take($count);
|
||||
|
||||
if ($search) {
|
||||
$query->where('name', 'like', '%' . $search . '%');
|
||||
}
|
||||
|
||||
$templates = $query->paginate($count, ['*'], 'page', $page);
|
||||
$templates->withPath('/templates');
|
||||
|
||||
if ($search) {
|
||||
$templates->appends(['search' => $search]);
|
||||
@@ -44,7 +53,7 @@ class PageTemplateController extends Controller
|
||||
*/
|
||||
public function get(int $templateId)
|
||||
{
|
||||
$page = $this->pageRepo->getById($templateId);
|
||||
$page = $this->pageQueries->findVisibleByIdOrFail($templateId);
|
||||
|
||||
if (!$page->template) {
|
||||
throw new NotFoundException();
|
||||
|
Reference in New Issue
Block a user