<?php namespace BookStack\Http\Controllers;
-use Exception;
+use BookStack\Auth\Access\SocialAuthService;
+use BookStack\Auth\User;
+use BookStack\Auth\UserRepo;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
-use BookStack\Repos\UserRepo;
-use BookStack\Services\SocialAuthService;
-use BookStack\User;
class UserController extends Controller
{
/**
* UserController constructor.
* @param User $user
- * @param UserRepo $userRepo
+ * @param \BookStack\Auth\UserRepo $userRepo
*/
public function __construct(User $user, UserRepo $userRepo)
{
/**
* Show the form for editing the specified user.
* @param int $id
- * @param SocialAuthService $socialAuthService
+ * @param \BookStack\Auth\Access\SocialAuthService $socialAuthService
* @return Response
*/
public function edit($id, SocialAuthService $socialAuthService)
return $this->currentUser->id == $id;
});
- $viewType = $request->get('book_view_type');
+ $viewType = $request->get('view_type');
if (!in_array($viewType, ['grid', 'list'])) {
$viewType = 'list';
}
return redirect()->back(302, [], "/settings/users/$id");
}
+
+ /**
+ * Update the user's preferred shelf-list display setting.
+ * @param $id
+ * @param Request $request
+ * @return \Illuminate\Http\RedirectResponse
+ */
+ public function switchShelfView($id, Request $request)
+ {
+ $this->checkPermissionOr('users-manage', function () use ($id) {
+ return $this->currentUser->id == $id;
+ });
+
+ $viewType = $request->get('view_type');
+ if (!in_array($viewType, ['grid', 'list'])) {
+ $viewType = 'list';
+ }
+
+ $user = $this->user->findOrFail($id);
+ setting()->putUser($user, 'bookshelves_view_type', $viewType);
+
+ return redirect()->back(302, [], "/settings/users/$id");
+ }
}