X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/dc6013fd7e5b6c261da4ce8a88052dd3f7b5111f..refs/heads/development:/app/Activity/Controllers/CommentController.php diff --git a/app/Activity/Controllers/CommentController.php b/app/Activity/Controllers/CommentController.php index 52ccc8238..479d57c4d 100644 --- a/app/Activity/Controllers/CommentController.php +++ b/app/Activity/Controllers/CommentController.php @@ -3,6 +3,8 @@ namespace BookStack\Activity\Controllers; use BookStack\Activity\CommentRepo; +use BookStack\Activity\Tools\CommentTree; +use BookStack\Activity\Tools\CommentTreeNode; use BookStack\Entities\Queries\PageQueries; use BookStack\Http\Controller; use Illuminate\Http\Request; @@ -26,6 +28,7 @@ class CommentController extends Controller $input = $this->validate($request, [ 'html' => ['required', 'string'], 'parent_id' => ['nullable', 'integer'], + 'content_ref' => ['string'], ]); $page = $this->pageQueries->findVisibleById($pageId); @@ -40,14 +43,12 @@ class CommentController extends Controller // Create a new comment. $this->checkPermission('comment-create-all'); - $comment = $this->commentRepo->create($page, $input['html'], $input['parent_id'] ?? null); + $contentRef = $input['content_ref'] ?? ''; + $comment = $this->commentRepo->create($page, $input['html'], $input['parent_id'] ?? null, $contentRef); return view('comments.comment-branch', [ 'readOnly' => false, - 'branch' => [ - 'comment' => $comment, - 'children' => [], - ] + 'branch' => new CommentTreeNode($comment, 0, []), ]); } @@ -74,6 +75,46 @@ class CommentController extends Controller ]); } + /** + * Mark a comment as archived. + */ + public function archive(int $id) + { + $comment = $this->commentRepo->getById($id); + $this->checkOwnablePermission('page-view', $comment->entity); + if (!userCan('comment-update', $comment) && !userCan('comment-delete', $comment)) { + $this->showPermissionError(); + } + + $this->commentRepo->archive($comment); + + $tree = new CommentTree($comment->entity); + return view('comments.comment-branch', [ + 'readOnly' => false, + 'branch' => $tree->getCommentNodeForId($id), + ]); + } + + /** + * Unmark a comment as archived. + */ + public function unarchive(int $id) + { + $comment = $this->commentRepo->getById($id); + $this->checkOwnablePermission('page-view', $comment->entity); + if (!userCan('comment-update', $comment) && !userCan('comment-delete', $comment)) { + $this->showPermissionError(); + } + + $this->commentRepo->unarchive($comment); + + $tree = new CommentTree($comment->entity); + return view('comments.comment-branch', [ + 'readOnly' => false, + 'branch' => $tree->getCommentNodeForId($id), + ]); + } + /** * Delete a comment from the system. */