Added missing permission checkboxes and improved image AJAX permission responses
Showing
4 changed files
with
28 additions
and
13 deletions
| ... | @@ -68,9 +68,8 @@ abstract class Controller extends BaseController | ... | @@ -68,9 +68,8 @@ abstract class Controller extends BaseController |
| 68 | protected function showPermissionError() | 68 | protected function showPermissionError() |
| 69 | { | 69 | { |
| 70 | Session::flash('error', trans('errors.permission')); | 70 | Session::flash('error', trans('errors.permission')); |
| 71 | - throw new HttpResponseException( | 71 | + $response = request()->wantsJson() ? response()->json(['error' => trans('errors.permissionJson')], 403) : redirect('/', 403); |
| 72 | - redirect('/') | 72 | + throw new HttpResponseException($response); |
| 73 | - ); | ||
| 74 | } | 73 | } |
| 75 | 74 | ||
| 76 | /** | 75 | /** | ... | ... |
| ... | @@ -118,6 +118,7 @@ module.exports = function (ngApp, events) { | ... | @@ -118,6 +118,7 @@ module.exports = function (ngApp, events) { |
| 118 | page++; | 118 | page++; |
| 119 | }); | 119 | }); |
| 120 | } | 120 | } |
| 121 | + | ||
| 121 | $scope.fetchData = fetchData; | 122 | $scope.fetchData = fetchData; |
| 122 | 123 | ||
| 123 | /** | 124 | /** |
| ... | @@ -130,12 +131,16 @@ module.exports = function (ngApp, events) { | ... | @@ -130,12 +131,16 @@ module.exports = function (ngApp, events) { |
| 130 | $http.put(url, this.selectedImage).then((response) => { | 131 | $http.put(url, this.selectedImage).then((response) => { |
| 131 | events.emit('success', 'Image details updated'); | 132 | events.emit('success', 'Image details updated'); |
| 132 | }, (response) => { | 133 | }, (response) => { |
| 133 | - var errors = response.data; | 134 | + if (response.status === 422) { |
| 134 | - var message = ''; | 135 | + var errors = response.data; |
| 135 | - Object.keys(errors).forEach((key) => { | 136 | + var message = ''; |
| 136 | - message += errors[key].join('\n'); | 137 | + Object.keys(errors).forEach((key) => { |
| 137 | - }); | 138 | + message += errors[key].join('\n'); |
| 138 | - events.emit('error', message); | 139 | + }); |
| 140 | + events.emit('error', message); | ||
| 141 | + } else if (response.status === 403) { | ||
| 142 | + events.emit('error', response.data.error); | ||
| 143 | + } | ||
| 139 | }); | 144 | }); |
| 140 | }; | 145 | }; |
| 141 | 146 | ||
| ... | @@ -158,6 +163,8 @@ module.exports = function (ngApp, events) { | ... | @@ -158,6 +163,8 @@ module.exports = function (ngApp, events) { |
| 158 | // Pages failure | 163 | // Pages failure |
| 159 | if (response.status === 400) { | 164 | if (response.status === 400) { |
| 160 | $scope.dependantPages = response.data; | 165 | $scope.dependantPages = response.data; |
| 166 | + } else if (response.status === 403) { | ||
| 167 | + events.emit('error', response.data.error); | ||
| 161 | } | 168 | } |
| 162 | }); | 169 | }); |
| 163 | }; | 170 | }; |
| ... | @@ -167,7 +174,7 @@ module.exports = function (ngApp, events) { | ... | @@ -167,7 +174,7 @@ module.exports = function (ngApp, events) { |
| 167 | * @param stringDate | 174 | * @param stringDate |
| 168 | * @returns {Date} | 175 | * @returns {Date} |
| 169 | */ | 176 | */ |
| 170 | - $scope.getDate = function(stringDate) { | 177 | + $scope.getDate = function (stringDate) { |
| 171 | return new Date(stringDate); | 178 | return new Date(stringDate); |
| 172 | }; | 179 | }; |
| 173 | 180 | ... | ... |
| ... | @@ -8,4 +8,5 @@ return [ | ... | @@ -8,4 +8,5 @@ return [ |
| 8 | 8 | ||
| 9 | // Pages | 9 | // Pages |
| 10 | 'permission' => 'You do not have permission to access the requested page.', | 10 | 'permission' => 'You do not have permission to access the requested page.', |
| 11 | + 'permissionJson' => 'You do not have permission to perform the requested action.' | ||
| 11 | ]; | 12 | ]; |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -31,7 +31,9 @@ | ... | @@ -31,7 +31,9 @@ |
| 31 | </tr> | 31 | </tr> |
| 32 | <tr> | 32 | <tr> |
| 33 | <td>Books</td> | 33 | <td>Books</td> |
| 34 | - <td>@include('settings/roles/checkbox', ['permission' => 'book-create-all'])</td> | 34 | + <td> |
| 35 | + <label>@include('settings/roles/checkbox', ['permission' => 'book-create-all']) All</label> | ||
| 36 | + </td> | ||
| 35 | <td> | 37 | <td> |
| 36 | <label>@include('settings/roles/checkbox', ['permission' => 'book-update-own']) Own</label> | 38 | <label>@include('settings/roles/checkbox', ['permission' => 'book-update-own']) Own</label> |
| 37 | <label>@include('settings/roles/checkbox', ['permission' => 'book-update-all']) All</label> | 39 | <label>@include('settings/roles/checkbox', ['permission' => 'book-update-all']) All</label> |
| ... | @@ -43,7 +45,10 @@ | ... | @@ -43,7 +45,10 @@ |
| 43 | </tr> | 45 | </tr> |
| 44 | <tr> | 46 | <tr> |
| 45 | <td>Chapters</td> | 47 | <td>Chapters</td> |
| 46 | - <td>@include('settings/roles/checkbox', ['permission' => 'chapter-create-all'])</td> | 48 | + <td> |
| 49 | + <label>@include('settings/roles/checkbox', ['permission' => 'chapter-create-own']) Own</label> | ||
| 50 | + <label>@include('settings/roles/checkbox', ['permission' => 'chapter-create-all']) All</label> | ||
| 51 | + </td> | ||
| 47 | <td> | 52 | <td> |
| 48 | <label>@include('settings/roles/checkbox', ['permission' => 'chapter-update-own']) Own</label> | 53 | <label>@include('settings/roles/checkbox', ['permission' => 'chapter-update-own']) Own</label> |
| 49 | <label>@include('settings/roles/checkbox', ['permission' => 'chapter-update-all']) All</label> | 54 | <label>@include('settings/roles/checkbox', ['permission' => 'chapter-update-all']) All</label> |
| ... | @@ -55,7 +60,10 @@ | ... | @@ -55,7 +60,10 @@ |
| 55 | </tr> | 60 | </tr> |
| 56 | <tr> | 61 | <tr> |
| 57 | <td>Pages</td> | 62 | <td>Pages</td> |
| 58 | - <td>@include('settings/roles/checkbox', ['permission' => 'page-create-all'])</td> | 63 | + <td> |
| 64 | + <label>@include('settings/roles/checkbox', ['permission' => 'page-create-own']) Own</label> | ||
| 65 | + <label>@include('settings/roles/checkbox', ['permission' => 'page-create-all']) All</label> | ||
| 66 | + </td> | ||
| 59 | <td> | 67 | <td> |
| 60 | <label>@include('settings/roles/checkbox', ['permission' => 'page-update-own']) Own</label> | 68 | <label>@include('settings/roles/checkbox', ['permission' => 'page-update-own']) Own</label> |
| 61 | <label>@include('settings/roles/checkbox', ['permission' => 'page-update-all']) All</label> | 69 | <label>@include('settings/roles/checkbox', ['permission' => 'page-update-all']) All</label> | ... | ... |
-
Please register or sign in to post a comment