]> BookStack Code Mirror - bookstack/blobdiff - resources/assets/js/controllers.js
#47 - Adds comment level permissions to the front-end.
[bookstack] / resources / assets / js / controllers.js
index f64d7c038d4263ce469365c7858b397d58e6f55d..4763f986745e1f639091fb1191d3b2e2507ebbaf 100644 (file)
@@ -756,6 +756,7 @@ module.exports = function (ngApp, events) {
         // keep track of comment levels
         $scope.level = 1;
         vm.totalCommentsStr = 'Loading...';
+        vm.permissions = {};
 
         $scope.$on('evt.new-comment', function (event, comment) {
             // add the comment to the comment list.
@@ -764,6 +765,21 @@ module.exports = function (ngApp, events) {
             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() {
             $http.get(window.baseUrl(`/ajax/page/${$scope.pageId}/comments/`)).then(resp => {
                 if (!resp.data || resp.data.success !== true) {
@@ -772,6 +788,9 @@ module.exports = function (ngApp, events) {
                 }
                 vm.comments = resp.data.comments;
                 vm.totalComments = resp.data.total;
+                vm.permissions = resp.data.permissions;
+                vm.current_user_id = resp.data.user_id;
+
                 // TODO : Fetch message from translate.
                 if (vm.totalComments === 0) {
                     vm.totalCommentsStr = 'No comments found.';