]> BookStack Code Mirror - bookstack/commitdiff
Added missing permission checkboxes and improved image AJAX permission responses
authorDan Brown <redacted>
Sat, 27 Feb 2016 20:52:46 +0000 (20:52 +0000)
committerDan Brown <redacted>
Sat, 27 Feb 2016 20:52:46 +0000 (20:52 +0000)
app/Http/Controllers/Controller.php
resources/assets/js/controllers.js
resources/lang/en/errors.php
resources/views/settings/roles/form.blade.php

index fce479af04e7d1294c2cf17eeb31b2bc40f6ec9d..4182743a7128518c9e63f9c87a9a4dfd4ba8eea9 100644 (file)
@@ -68,9 +68,8 @@ abstract class Controller extends BaseController
     protected function showPermissionError()
     {
         Session::flash('error', trans('errors.permission'));
-        throw new HttpResponseException(
-            redirect('/')
-        );
+        $response = request()->wantsJson() ? response()->json(['error' => trans('errors.permissionJson')], 403) : redirect('/', 403);
+        throw new HttpResponseException($response);
     }
 
     /**
index 76def6abd032a006a5743ad8d67178813f5e7d84..1f73888590d2fc18ffb92d3566ae5aec28af01c7 100644 (file)
@@ -118,6 +118,7 @@ module.exports = function (ngApp, events) {
                     page++;
                 });
             }
+
             $scope.fetchData = fetchData;
 
             /**
@@ -130,12 +131,16 @@ module.exports = function (ngApp, events) {
                 $http.put(url, this.selectedImage).then((response) => {
                     events.emit('success', 'Image details updated');
                 }, (response) => {
-                    var errors = response.data;
-                    var message = '';
-                    Object.keys(errors).forEach((key) => {
-                        message += errors[key].join('\n');
-                    });
-                    events.emit('error', message);
+                    if (response.status === 422) {
+                        var errors = response.data;
+                        var message = '';
+                        Object.keys(errors).forEach((key) => {
+                            message += errors[key].join('\n');
+                        });
+                        events.emit('error', message);
+                    } else if (response.status === 403) {
+                        events.emit('error', response.data.error);
+                    }
                 });
             };
 
@@ -158,6 +163,8 @@ module.exports = function (ngApp, events) {
                     // Pages failure
                     if (response.status === 400) {
                         $scope.dependantPages = response.data;
+                    } else if (response.status === 403) {
+                        events.emit('error', response.data.error);
                     }
                 });
             };
@@ -167,7 +174,7 @@ module.exports = function (ngApp, events) {
              * @param stringDate
              * @returns {Date}
              */
-            $scope.getDate = function(stringDate) {
+            $scope.getDate = function (stringDate) {
                 return new Date(stringDate);
             };
 
index 53785b684ac5e1658908cc64eeb09890becb4d29..b1a252bf3a52a06c057d87ba94e818c3a6642f72 100644 (file)
@@ -8,4 +8,5 @@ return [
 
     // Pages
     'permission' => 'You do not have permission to access the requested page.',
+    'permissionJson' => 'You do not have permission to perform the requested action.'
 ];
\ No newline at end of file
index b9c47053b99cfe864f9d41089d86ff91dedb0ad4..3069896b98e4faf691ef39af5d26280eed91948e 100644 (file)
@@ -31,7 +31,9 @@
             </tr>
             <tr>
                 <td>Books</td>
-                <td>@include('settings/roles/checkbox', ['permission' => 'book-create-all'])</td>
+                <td>
+                    <label>@include('settings/roles/checkbox', ['permission' => 'book-create-all']) All</label>
+                </td>
                 <td>
                     <label>@include('settings/roles/checkbox', ['permission' => 'book-update-own']) Own</label>
                     <label>@include('settings/roles/checkbox', ['permission' => 'book-update-all']) All</label>
             </tr>
             <tr>
                 <td>Chapters</td>
-                <td>@include('settings/roles/checkbox', ['permission' => 'chapter-create-all'])</td>
+                <td>
+                    <label>@include('settings/roles/checkbox', ['permission' => 'chapter-create-own']) Own</label>
+                    <label>@include('settings/roles/checkbox', ['permission' => 'chapter-create-all']) All</label>
+                </td>
                 <td>
                     <label>@include('settings/roles/checkbox', ['permission' => 'chapter-update-own']) Own</label>
                     <label>@include('settings/roles/checkbox', ['permission' => 'chapter-update-all']) All</label>
             </tr>
             <tr>
                 <td>Pages</td>
-                <td>@include('settings/roles/checkbox', ['permission' => 'page-create-all'])</td>
+                <td>
+                    <label>@include('settings/roles/checkbox', ['permission' => 'page-create-own']) Own</label>
+                    <label>@include('settings/roles/checkbox', ['permission' => 'page-create-all']) All</label>
+                </td>
                 <td>
                     <label>@include('settings/roles/checkbox', ['permission' => 'page-update-own']) Own</label>
                     <label>@include('settings/roles/checkbox', ['permission' => 'page-update-all']) All</label>