]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/UserController.php
Adds test cases and fixes an issue with the permission checking.
[bookstack] / app / Http / Controllers / UserController.php
index fe5c7a243b6c4e7899cf5730da9755225268f371..397bb2922b6f558a5a2ede8e12c3f6275ccdc1bc 100644 (file)
@@ -249,4 +249,27 @@ class UserController extends Controller
             'assetCounts' => $assetCounts
         ]);
     }
+
+    public function switchBookView($id, Request $request) {
+        $this->checkPermissionOr('users-manage', function () use ($id) {
+            return $this->currentUser->id == $id;
+        });
+        $viewType = $request->get('book_view_type');
+
+        if (!in_array($viewType, ['grid', 'list'])) {
+            $viewType = 'list';
+        }
+
+        $user = $this->user->findOrFail($id);
+        setting()->putUser($user, 'books_view_type', $viewType);
+
+        $previousUrl = url()->previous();
+        if (empty($previousUrl)) {
+            // if no previous URL, redirect to settings
+            return redirect("/settings/users/$id");
+        } else {
+            // redirect to the previous page.
+            return redirect($previousUrl);
+        }
+    }
 }