X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/03e5d61798e6b8df3b4d74b5f3bb1a96fe8199bb..refs/pull/261/head:/app/Http/Controllers/CommentController.php diff --git a/app/Http/Controllers/CommentController.php b/app/Http/Controllers/CommentController.php index e1729bbee..e8d5eab30 100644 --- a/app/Http/Controllers/CommentController.php +++ b/app/Http/Controllers/CommentController.php @@ -5,7 +5,6 @@ use BookStack\Repos\EntityRepo; use BookStack\Comment; use Illuminate\Http\Request; -// delete -checkOwnablePermission \ class CommentController extends Controller { protected $entityRepo; @@ -54,9 +53,12 @@ class CommentController extends Controller $respMsg = trans('entities.comment_updated'); } + $comment = $this->commentRepo->getCommentById($comment->id); + return response()->json([ 'status' => 'success', - 'message' => $respMsg + 'message' => $respMsg, + 'comment' => $comment ]); } @@ -64,33 +66,34 @@ class CommentController extends Controller public function destroy($id) { $comment = $this->comment->findOrFail($id); $this->checkOwnablePermission('comment-delete', $comment); + $this->commentRepo->delete($comment); + $updatedComment = $this->commentRepo->getCommentById($comment->id); - // + return response()->json([ + 'status' => 'success', + 'message' => trans('entities.comment_deleted'), + 'comment' => $updatedComment + ]); } - public function getCommentThread($pageId, $commentId = null) { + + public function getPageComments($pageId) { try { $page = $this->entityRepo->getById('page', $pageId, true); } catch (ModelNotFoundException $e) { return response('Not found', 404); } - if($page->draft) { - // cannot add comments to drafts. - return response()->json([ - 'status' => 'error', - 'message' => trans('errors.no_comments_for_draft'), - ], 400); - } - $this->checkOwnablePermission('page-view', $page); - $comments = $this->commentRepo->getCommentsForPage($pageId, $commentId); - if (empty($commentId)) { - // requesting for parent level comments, send the total count as well. - $totalComments = $this->commentRepo->getCommentCount($pageId); - return response()->json(['success' => true, 'comments'=> $comments, 'total' => $totalComments]); - } - return response()->json(['success' => true, 'comments'=> $comments]); + $comments = $this->commentRepo->getPageComments($pageId); + return response()->json(['status' => 'success', 'comments'=> $comments['comments'], + 'total' => $comments['total'], 'permissions' => [ + 'comment_create' => $this->currentUser->can('comment-create-all'), + 'comment_update_own' => $this->currentUser->can('comment-update-own'), + 'comment_update_all' => $this->currentUser->can('comment-update-all'), + 'comment_delete_all' => $this->currentUser->can('comment-delete-all'), + 'comment_delete_own' => $this->currentUser->can('comment-delete-own'), + ], 'user_id' => $this->currentUser->id]); } }