33namespace BookStack \Activity \Controllers ;
44
55use BookStack \Activity \CommentRepo ;
6- use BookStack \Entities \Models \ Page ;
6+ use BookStack \Entities \Queries \ PageQueries ;
77use BookStack \Http \Controller ;
88use Illuminate \Http \Request ;
99use Illuminate \Validation \ValidationException ;
1010
1111class CommentController extends Controller
1212{
1313 public function __construct (
14- protected CommentRepo $ commentRepo
14+ protected CommentRepo $ commentRepo ,
15+ protected PageQueries $ pageQueries ,
1516 ) {
1617 }
1718
@@ -22,12 +23,12 @@ public function __construct(
2223 */
2324 public function savePageComment (Request $ request , int $ pageId )
2425 {
25- $ this ->validate ($ request , [
26- 'text ' => ['required ' , 'string ' ],
26+ $ input = $ this ->validate ($ request , [
27+ 'html ' => ['required ' , 'string ' ],
2728 'parent_id ' => ['nullable ' , 'integer ' ],
2829 ]);
2930
30- $ page = Page:: visible ()-> find ($ pageId );
31+ $ page = $ this -> pageQueries -> findVisibleById ($ pageId );
3132 if ($ page === null ) {
3233 return response ('Not found ' , 404 );
3334 }
@@ -39,7 +40,7 @@ public function savePageComment(Request $request, int $pageId)
3940
4041 // Create a new comment.
4142 $ this ->checkPermission ('comment-create-all ' );
42- $ comment = $ this ->commentRepo ->create ($ page , $ request -> get ( ' text ' ) , $ request -> get ( 'parent_id ' ) );
43+ $ comment = $ this ->commentRepo ->create ($ page , $ input [ ' html ' ] , $ input [ 'parent_id ' ] ?? null );
4344
4445 return view ('comments.comment-branch ' , [
4546 'readOnly ' => false ,
@@ -57,17 +58,20 @@ public function savePageComment(Request $request, int $pageId)
5758 */
5859 public function update (Request $ request , int $ commentId )
5960 {
60- $ this ->validate ($ request , [
61- 'text ' => ['required ' , 'string ' ],
61+ $ input = $ this ->validate ($ request , [
62+ 'html ' => ['required ' , 'string ' ],
6263 ]);
6364
6465 $ comment = $ this ->commentRepo ->getById ($ commentId );
6566 $ this ->checkOwnablePermission ('page-view ' , $ comment ->entity );
6667 $ this ->checkOwnablePermission ('comment-update ' , $ comment );
6768
68- $ comment = $ this ->commentRepo ->update ($ comment , $ request -> get ( ' text ' ) );
69+ $ comment = $ this ->commentRepo ->update ($ comment , $ input [ ' html ' ] );
6970
70- return view ('comments.comment ' , ['comment ' => $ comment , 'readOnly ' => false ]);
71+ return view ('comments.comment ' , [
72+ 'comment ' => $ comment ,
73+ 'readOnly ' => false ,
74+ ]);
7175 }
7276
7377 /**
0 commit comments