1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

#47 - Adds functionality to delete a comment. Also reduces the number of watchers.

This commit is contained in:
Abijeet
2017-06-04 18:52:44 +05:30
parent 2fd421b115
commit 9558f84b97
6 changed files with 147 additions and 15 deletions

View File

@ -67,6 +67,14 @@ class CommentController extends Controller
public function destroy($id) {
$comment = $this->comment->findOrFail($id);
$this->checkOwnablePermission('comment-delete', $comment);
$this->commentRepo->delete($comment);
$comment = $this->commentRepo->getCommentById($comment->id);
return response()->json([
'success' => true,
'message' => trans('entities.comment_deleted'),
'comment' => $comment
]);
}

View File

@ -31,10 +31,26 @@ class CommentRepo {
return $comment;
}
public function update($comment, $input) {
public function update($comment, $input, $activeOnly = true) {
$userId = user()->id;
$comment->updated_by = $userId;
$comment->fill($input);
// only update active comments by default.
$whereClause = ['active' => 1];
if (!$activeOnly) {
$whereClause = [];
}
$comment->update($whereClause);
return $comment;
}
public function delete($comment) {
$comment->text = trans('errors.cannot_add_comment_to_draft');
$comment->html = trans('errors.cannot_add_comment_to_draft');
$comment->active = false;
$userId = user()->id;
$comment->updated_by = $userId;
$comment->save();
return $comment;
}