/**
* Show the form for editing the specified user.
- * @param int $id
- * @param \BookStack\Auth\Access\SocialAuthService $socialAuthService
- * @return Response
*/
- public function edit($id, SocialAuthService $socialAuthService)
+ public function edit(int $id, SocialAuthService $socialAuthService)
{
$this->checkPermissionOrCurrentUser('users-manage', $id);
- $user = $this->user->findOrFail($id);
+ $user = $this->user->newQuery()->with(['apiTokens'])->findOrFail($id);
$authMethod = ($user->system_name) ? 'system' : config('auth.method');
$activeSocialDrivers = $socialAuthService->getActiveDrivers();
$this->setPageTitle(trans('settings.user_profile'));
$roles = $this->userRepo->getAllRoles();
- return view('users.edit', ['user' => $user, 'activeSocialDrivers' => $activeSocialDrivers, 'authMethod' => $authMethod, 'roles' => $roles]);
+ return view('users.edit', [
+ 'user' => $user,
+ 'activeSocialDrivers' => $activeSocialDrivers,
+ 'authMethod' => $authMethod,
+ 'roles' => $roles
+ ]);
}
/**
*/
public function update(Request $request, $id)
{
- $this->preventAccessForDemoUsers();
+ $this->preventAccessInDemoMode();
$this->checkPermissionOrCurrentUser('users-manage', $id);
$this->validate($request, [
'password' => 'min:6|required_with:password_confirm',
'password-confirm' => 'same:password|required_with:password',
'setting' => 'array',
- 'profile_image' => $this->imageRepo->getImageValidationRules(),
+ 'profile_image' => 'nullable|' . $this->getImageValidationRules(),
]);
$user = $this->userRepo->getById($id);
}
// External auth id updates
- if ($this->currentUser->can('users-manage') && $request->filled('external_auth_id')) {
+ if (user()->can('users-manage') && $request->filled('external_auth_id')) {
$user->external_auth_id = $request->get('external_auth_id');
}
}
// Save profile image if in request
- if ($request->has('profile_image')) {
+ if ($request->hasFile('profile_image')) {
$imageUpload = $request->file('profile_image');
$this->imageRepo->destroyImage($user->avatar);
$image = $this->imageRepo->saveNew($imageUpload, 'user', $user->id);
}
$user->save();
- session()->flash('success', trans('settings.users_edit_success'));
+ $this->showSuccessNotification(trans('settings.users_edit_success'));
$redirectUrl = userCan('users-manage') ? '/settings/users' : ('/settings/users/' . $user->id);
return redirect($redirectUrl);
*/
public function destroy($id)
{
- $this->preventAccessForDemoUsers();
+ $this->preventAccessInDemoMode();
$this->checkPermissionOrCurrentUser('users-manage', $id);
$user = $this->userRepo->getById($id);
if ($this->userRepo->isOnlyAdmin($user)) {
- session()->flash('error', trans('errors.users_cannot_delete_only_admin'));
+ $this->showErrorNotification(trans('errors.users_cannot_delete_only_admin'));
return redirect($user->getEditUrl());
}
if ($user->system_name === 'public') {
- session()->flash('error', trans('errors.users_cannot_delete_guest'));
+ $this->showErrorNotification(trans('errors.users_cannot_delete_guest'));
return redirect($user->getEditUrl());
}
$this->userRepo->destroy($user);
- session()->flash('success', trans('settings.users_delete_success'));
+ $this->showSuccessNotification(trans('settings.users_delete_success'));
return redirect('/settings/users');
}
$user = $this->userRepo->getById($id);
$userActivity = $this->userRepo->getActivity($user);
- $recentlyCreated = $this->userRepo->getRecentlyCreated($user, 5, 0);
+ $recentlyCreated = $this->userRepo->getRecentlyCreated($user, 5);
$assetCounts = $this->userRepo->getAssetCounts($user);
return view('users.profile', [
/**
* Update the user's preferred book-list display setting.
- * @param $id
* @param Request $request
+ * @param $id
* @return \Illuminate\Http\RedirectResponse
*/
- public function switchBookView($id, Request $request)
+ public function switchBookView(Request $request, $id)
{
return $this->switchViewType($id, $request, 'books');
}
/**
* Update the user's preferred shelf-list display setting.
- * @param $id
* @param Request $request
+ * @param $id
* @return \Illuminate\Http\RedirectResponse
*/
- public function switchShelfView($id, Request $request)
+ public function switchShelfView(Request $request, $id)
{
return $this->switchViewType($id, $request, 'bookshelves');
}
/**
* Change the stored sort type for a particular view.
+ * @param Request $request
* @param string $id
* @param string $type
- * @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/
- public function changeSort(string $id, string $type, Request $request)
+ public function changeSort(Request $request, string $id, string $type)
{
$validSortTypes = ['books', 'bookshelves'];
if (!in_array($type, $validSortTypes)) {
/**
* Update the stored section expansion preference for the given user.
+ * @param Request $request
* @param string $id
* @param string $key
- * @param Request $request
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
*/
- public function updateExpansionPreference(string $id, string $key, Request $request)
+ public function updateExpansionPreference(Request $request, string $id, string $key)
{
$this->checkPermissionOrCurrentUser('users-manage', $id);
$keyWhitelist = ['home-details'];