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;
class PageApiController extends ApiController
{
- protected PageRepo $pageRepo;
-
protected $rules = [
'create' => [
'book_id' => ['required_without:chapter_id', 'integer'],
'html' => ['required_without:markdown', 'string'],
'markdown' => ['required_without:html', 'string'],
'tags' => ['array'],
+ 'priority' => ['integer'],
],
'update' => [
'book_id' => ['integer'],
'html' => ['string'],
'markdown' => ['string'],
'tags' => ['array'],
+ 'priority' => ['integer'],
],
];
- public function __construct(PageRepo $pageRepo)
- {
- $this->pageRepo = $pageRepo;
+ public function __construct(
+ protected PageRepo $pageRepo,
+ protected PageQueries $queries,
+ ) {
}
/**
/**
* View the details of a single page.
- *
* Pages will always have HTML content. They may have markdown content
* if the markdown editor was used to last update the page.
*
+ * The 'html' property is the fully rendered & escaped HTML content that BookStack
+ * would show on page view, with page includes handled.
+ * The 'raw_html' property is the direct database stored HTML content, which would be
+ * what BookStack shows on page edit.
+ *
* See the "Content Security" section of these docs for security considerations when using
* the page content returned from this endpoint.
*/
public function read(string $id)
{
- $page = $this->pageRepo->getById($id, []);
+ $page = $this->queries->findVisibleByIdOrFail($id);
return response()->json($page->forJsonDisplay());
}
{
$requestData = $this->validate($request, $this->rules['update']);
- $page = $this->pageRepo->getById($id, []);
+ $page = $this->queries->findVisibleByIdOrFail($id);
$this->checkOwnablePermission('page-update', $page);
$parent = null;
*/
public function delete(string $id)
{
- $page = $this->pageRepo->getById($id, []);
+ $page = $this->queries->findVisibleByIdOrFail($id);
$this->checkOwnablePermission('page-delete', $page);
$this->pageRepo->destroy($page);