mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
#47 - Adds comment level permissions to the front-end.
This commit is contained in:
parent
6ff440e677
commit
2fd421b115
@ -88,6 +88,13 @@ class CommentController extends Controller
|
|||||||
$this->checkOwnablePermission('page-view', $page);
|
$this->checkOwnablePermission('page-view', $page);
|
||||||
|
|
||||||
$comments = $this->commentRepo->getPageComments($pageId);
|
$comments = $this->commentRepo->getPageComments($pageId);
|
||||||
return response()->json(['success' => true, 'comments'=> $comments['comments'], 'total' => $comments['total']]);
|
return response()->json(['success' => true, '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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -590,9 +590,4 @@ class PageController extends Controller
|
|||||||
return redirect($page->getUrl());
|
return redirect($page->getUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLastXComments($pageId)
|
|
||||||
{
|
|
||||||
// $this->checkOwnablePermission('page-view', $page);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,11 +43,14 @@ class CommentRepo {
|
|||||||
$comments = $this->comment->getAllPageComments($pageId);
|
$comments = $this->comment->getAllPageComments($pageId);
|
||||||
$index = [];
|
$index = [];
|
||||||
$totalComments = count($comments);
|
$totalComments = count($comments);
|
||||||
|
$finalCommentList = [];
|
||||||
|
|
||||||
// normalizing the response.
|
// normalizing the response.
|
||||||
foreach($comments as &$comment) {
|
for ($i = 0; $i < count($comments); ++$i) {
|
||||||
$comment = $this->normalizeComment($comment);
|
$comment = $this->normalizeComment($comments[$i]);
|
||||||
$parentId = $comment->parent_id;
|
$parentId = $comment->parent_id;
|
||||||
if (empty($parentId)) {
|
if (empty($parentId)) {
|
||||||
|
$finalCommentList[] = $comment;
|
||||||
$index[$comment->id] = $comment;
|
$index[$comment->id] = $comment;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -63,7 +66,7 @@ class CommentRepo {
|
|||||||
$index[$comment->id] = $comment;
|
$index[$comment->id] = $comment;
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
'comments' => $comments,
|
'comments' => $finalCommentList,
|
||||||
'total' => $totalComments
|
'total' => $totalComments
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -756,6 +756,7 @@ module.exports = function (ngApp, events) {
|
|||||||
// keep track of comment levels
|
// keep track of comment levels
|
||||||
$scope.level = 1;
|
$scope.level = 1;
|
||||||
vm.totalCommentsStr = 'Loading...';
|
vm.totalCommentsStr = 'Loading...';
|
||||||
|
vm.permissions = {};
|
||||||
|
|
||||||
$scope.$on('evt.new-comment', function (event, comment) {
|
$scope.$on('evt.new-comment', function (event, comment) {
|
||||||
// add the comment to the comment list.
|
// add the comment to the comment list.
|
||||||
@ -764,6 +765,21 @@ module.exports = function (ngApp, events) {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
vm.canEdit = function (comment) {
|
||||||
|
if (vm.permissions.comment_update_all) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vm.permissions.comment_update_own && comment.created_by.id === vm.current_user_id) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
vm.canComment = function () {
|
||||||
|
return vm.permissions.comment_create;
|
||||||
|
}
|
||||||
|
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
$http.get(window.baseUrl(`/ajax/page/${$scope.pageId}/comments/`)).then(resp => {
|
$http.get(window.baseUrl(`/ajax/page/${$scope.pageId}/comments/`)).then(resp => {
|
||||||
if (!resp.data || resp.data.success !== true) {
|
if (!resp.data || resp.data.success !== true) {
|
||||||
@ -772,6 +788,9 @@ module.exports = function (ngApp, events) {
|
|||||||
}
|
}
|
||||||
vm.comments = resp.data.comments;
|
vm.comments = resp.data.comments;
|
||||||
vm.totalComments = resp.data.total;
|
vm.totalComments = resp.data.total;
|
||||||
|
vm.permissions = resp.data.permissions;
|
||||||
|
vm.current_user_id = resp.data.user_id;
|
||||||
|
|
||||||
// TODO : Fetch message from translate.
|
// TODO : Fetch message from translate.
|
||||||
if (vm.totalComments === 0) {
|
if (vm.totalComments === 0) {
|
||||||
vm.totalCommentsStr = 'No comments found.';
|
vm.totalCommentsStr = 'No comments found.';
|
||||||
|
@ -908,7 +908,7 @@ module.exports = function (ngApp, events) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function removeDupe() {
|
function removeDupe() {
|
||||||
let $existingElement = $document.find('.comments-list comment-reply');
|
let $existingElement = $document.find('.comments-list comment-reply, .comments-list comment-edit');
|
||||||
if (!$existingElement.length) {
|
if (!$existingElement.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -12,5 +12,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div ng-if="::vm.canComment()">
|
||||||
@include('comments/comment-reply', ['pageId' => $pageId])
|
@include('comments/comment-reply', ['pageId' => $pageId])
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
@ -11,8 +11,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="comment-actions">
|
<div class="comment-actions">
|
||||||
<ul>
|
<ul>
|
||||||
<li ng-if="level < 3"><a href="#" comment-reply-link no-comment-reply-dupe="true" comment="comment" is-reply="true">Reply</a></li>
|
<li ng-if="::(level < 3 && vm.canComment())"><a href="#" comment-reply-link no-comment-reply-dupe="true" comment="comment" is-reply="true">Reply</a></li>
|
||||||
<li><a href="#" comment-reply-link no-comment-reply-dupe="true" comment="comment">Edit</a></li>
|
<li ng-if="::vm.canEdit(comment)"><a href="#" comment-reply-link no-comment-reply-dupe="true" comment="comment" >Edit</a></li>
|
||||||
<li>Created <a title="@{{::comment.created.day_time_str}}" href="#comment-@{{::comment.id}}-@{{::pageId}}">@{{::comment.created.diff}}</a></li>
|
<li>Created <a title="@{{::comment.created.day_time_str}}" href="#comment-@{{::comment.id}}-@{{::pageId}}">@{{::comment.created.diff}}</a></li>
|
||||||
<li ng-if="comment.updated"><span title="@{{comment.updated.day_time_str}}">Updated @{{comment.updated.diff}} by
|
<li ng-if="comment.updated"><span title="@{{comment.updated.day_time_str}}">Updated @{{comment.updated.diff}} by
|
||||||
<a href="@{{comment.updated_by.profile_url}}">@{{comment.updated_by.name}}</a></span></li>
|
<a href="@{{comment.updated_by.profile_url}}">@{{comment.updated_by.name}}</a></span></li>
|
||||||
|
Loading…
Reference in New Issue
Block a user