use BookStack\Auth\Access\UserInviteService;
use BookStack\Auth\User;
use BookStack\Auth\UserRepo;
+use BookStack\Exceptions\ImageUploadException;
use BookStack\Exceptions\UserUpdateException;
use BookStack\Uploads\ImageRepo;
+use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
+use Illuminate\Validation\ValidationException;
class UserController extends Controller
{
$this->userRepo = $userRepo;
$this->inviteService = $inviteService;
$this->imageRepo = $imageRepo;
- parent::__construct();
}
/**
'sort' => $request->get('sort', 'name'),
];
$users = $this->userRepo->getAllUsersPaginatedAndSorted(20, $listDetails);
+
$this->setPageTitle(trans('settings.users'));
$users->appends($listDetails);
return view('users.index', ['users' => $users, 'listDetails' => $listDetails]);
/**
* Store a newly created user in storage.
* @throws UserUpdateException
- * @throws \Illuminate\Validation\ValidationException
+ * @throws ValidationException
*/
public function store(Request $request)
{
$user->external_auth_id = $request->get('external_auth_id');
}
+ $user->refreshSlug();
$user->save();
if ($sendInvite) {
/**
* Update the specified user in storage.
* @throws UserUpdateException
- * @throws \BookStack\Exceptions\ImageUploadException
- * @throws \Illuminate\Validation\ValidationException
+ * @throws ImageUploadException
+ * @throws ValidationException
*/
public function update(Request $request, int $id)
{
$user->email = $request->get('email');
}
+ // Refresh the slug if the user's name has changed
+ if ($user->isDirty('name')) {
+ $user->refreshSlug();
+ }
+
// Role updates
if (userCan('users-manage') && $request->filled('roles')) {
$roles = $request->get('roles');
$user->image_id = $image->id;
}
- // Delete the profile image if set to
+ // Delete the profile image if reset option is in request
if ($request->has('profile_image_reset')) {
$this->imageRepo->destroyImage($user->avatar);
}
/**
* Remove the specified user from storage.
- * @throws \Exception
+ * @throws Exception
*/
- public function destroy(int $id)
+ public function destroy(Request $request, int $id)
{
$this->preventAccessInDemoMode();
$this->checkPermissionOrCurrentUser('users-manage', $id);
$user = $this->userRepo->getById($id);
+ $newOwnerId = $request->get('new_owner_id', null);
if ($this->userRepo->isOnlyAdmin($user)) {
$this->showErrorNotification(trans('errors.users_cannot_delete_only_admin'));
return redirect($user->getEditUrl());
}
- $this->userRepo->destroy($user);
+ $this->userRepo->destroy($user, $newOwnerId);
$this->showSuccessNotification(trans('settings.users_delete_success'));
$this->logActivity(ActivityType::USER_DELETE, $user);
return redirect('/settings/users');
}
- /**
- * Show the user profile page
- */
- public function showProfilePage($id)
- {
- $user = $this->userRepo->getById($id);
-
- $userActivity = $this->userRepo->getActivity($user);
- $recentlyCreated = $this->userRepo->getRecentlyCreated($user, 5);
- $assetCounts = $this->userRepo->getAssetCounts($user);
-
- return view('users.profile', [
- 'user' => $user,
- 'activity' => $userActivity,
- 'recentlyCreated' => $recentlyCreated,
- 'assetCounts' => $assetCounts
- ]);
- }
-
/**
* Update the user's preferred book-list display setting.
*/
*/
public function changeSort(Request $request, string $id, string $type)
{
- $validSortTypes = ['books', 'bookshelves'];
+ $validSortTypes = ['books', 'bookshelves', 'shelf_books'];
if (!in_array($type, $validSortTypes)) {
return redirect()->back(500);
}
$this->checkPermissionOrCurrentUser('users-manage', $userId);
$sort = $request->get('sort');
- if (!in_array($sort, ['name', 'created_at', 'updated_at'])) {
+ if (!in_array($sort, ['name', 'created_at', 'updated_at', 'default'])) {
$sort = 'name';
}