]> BookStack Code Mirror - bookstack/blobdiff - app/Activity/Controllers/CommentController.php
Tests: Updated comment test to account for new editor usage
[bookstack] / app / Activity / Controllers / CommentController.php
index 7a290ebabc526969ae38232be72982c8af953f30..479d57c4db941455bf34d8a158c6e186b12a686c 100644 (file)
@@ -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;
@@ -41,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, $input['content_ref']);
+        $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, []),
         ]);
     }
 
@@ -81,15 +81,17 @@ class CommentController extends Controller
     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);
 
-        return view('comments.comment', [
-            'comment' => $comment,
+        $tree = new CommentTree($comment->entity);
+        return view('comments.comment-branch', [
             'readOnly' => false,
+            'branch' => $tree->getCommentNodeForId($id),
         ]);
     }
 
@@ -99,15 +101,17 @@ class CommentController extends Controller
     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);
 
-        return view('comments.comment', [
-            'comment' => $comment,
+        $tree = new CommentTree($comment->entity);
+        return view('comments.comment-branch', [
             'readOnly' => false,
+            'branch' => $tree->getCommentNodeForId($id),
         ]);
     }