namespace BookStack\Entities\Controllers;
+use BookStack\Activity\Tools\CommentTree;
use BookStack\Entities\Queries\EntityQueries;
use BookStack\Entities\Queries\PageQueries;
use BookStack\Entities\Repos\PageRepo;
use BookStack\Exceptions\PermissionsException;
use BookStack\Http\ApiController;
+use BookStack\Permissions\Permission;
use Exception;
use Illuminate\Http\Request;
} else {
$parent = $this->entityQueries->books->findVisibleByIdOrFail(intval($request->get('book_id')));
}
- $this->checkOwnablePermission('page-create', $parent);
+ $this->checkOwnablePermission(Permission::PageCreate, $parent);
$draft = $this->pageRepo->getNewDraftPage($parent);
$this->pageRepo->publishDraft($draft, $request->only(array_keys($this->rules['create'])));
/**
* 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.
+ * if the Markdown editor was used to last update the page.
*
- * The 'html' property is the fully rendered & escaped HTML content that BookStack
+ * The 'html' property is the fully rendered and 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.
+ *
+ * Comments for the page are provided in a tree-structure representing the hierarchy of top-level
+ * comments and replies, for both archived and active comments.
*/
public function read(string $id)
{
$page = $this->queries->findVisibleByIdOrFail($id);
- return response()->json($page->forJsonDisplay());
+ $page = $page->forJsonDisplay();
+ $commentTree = (new CommentTree($page));
+ $commentTree->loadVisibleHtml();
+ $page->setAttribute('comments', [
+ 'active' => $commentTree->getActive(),
+ 'archived' => $commentTree->getArchived(),
+ ]);
+
+ return response()->json($page);
}
/**
$requestData = $this->validate($request, $this->rules['update']);
$page = $this->queries->findVisibleByIdOrFail($id);
- $this->checkOwnablePermission('page-update', $page);
+ $this->checkOwnablePermission(Permission::PageUpdate, $page);
$parent = null;
if ($request->has('chapter_id')) {
}
if ($parent && !$parent->matches($page->getParent())) {
- $this->checkOwnablePermission('page-delete', $page);
+ $this->checkOwnablePermission(Permission::PageDelete, $page);
try {
$this->pageRepo->move($page, $parent->getType() . ':' . $parent->id);
public function delete(string $id)
{
$page = $this->queries->findVisibleByIdOrFail($id);
- $this->checkOwnablePermission('page-delete', $page);
+ $this->checkOwnablePermission(Permission::PageDelete, $page);
$this->pageRepo->destroy($page);