X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/82a8db373961d89ab1c9a3736ba5fc467fe2e03d..refs/pull/2393/head:/app/Auth/UserRepo.php diff --git a/app/Auth/UserRepo.php b/app/Auth/UserRepo.php index e082b2dd5..884f53463 100644 --- a/app/Auth/UserRepo.php +++ b/app/Auth/UserRepo.php @@ -1,15 +1,16 @@ user->where('email', '=', $email)->first(); } @@ -57,13 +57,19 @@ class UserRepo /** * Get all the users with their permissions in a paginated format. - * @param int $count - * @param $sortData - * @return Builder|static */ - public function getAllUsersPaginatedAndSorted($count, $sortData) + public function getAllUsersPaginatedAndSorted(int $count, array $sortData): LengthAwarePaginator { - $query = $this->user->with('roles', 'avatar')->orderBy($sortData['sort'], $sortData['order']); + $sort = $sortData['sort']; + if ($sort === 'latest_activity') { + $sort = \BookStack\Actions\Activity::query()->select('created_at') + ->whereColumn('activities.user_id', 'users.id') + ->latest() + ->take(1); + } + + $query = $this->user->with(['roles', 'avatar', 'latestActivity']) + ->orderBy($sort, $sortData['order']); if ($sortData['search']) { $term = '%' . $sortData['search'] . '%'; @@ -78,31 +84,16 @@ class UserRepo /** * Creates a new user and attaches a role to them. - * @param array $data - * @param boolean $verifyEmail - * @return User */ - public function registerNew(array $data, $verifyEmail = false) + public function registerNew(array $data, bool $emailConfirmed = false): User { - $user = $this->create($data, $verifyEmail); - $this->attachDefaultRole($user); + $user = $this->create($data, $emailConfirmed); + $user->attachDefaultRole(); $this->downloadAndAssignUserAvatar($user); return $user; } - /** - * Give a user the default role. Used when creating a new user. - * @param User $user - */ - public function attachDefaultRole(User $user) - { - $roleId = setting('registration-role'); - if ($roleId !== false && $user->roles()->where('id', '=', $roleId)->count() === 0) { - $user->attachRoleId($roleId); - } - } - /** * Assign a user to a system-level role. * @param User $user @@ -172,17 +163,15 @@ class UserRepo /** * Create a new basic instance of user. - * @param array $data - * @param boolean $verifyEmail - * @return User */ - public function create(array $data, $verifyEmail = false) + public function create(array $data, bool $emailConfirmed = false): User { return $this->user->forceCreate([ 'name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), - 'email_confirmed' => $verifyEmail + 'email_confirmed' => $emailConfirmed, + 'external_auth_id' => $data['external_auth_id'] ?? '', ]); } @@ -256,7 +245,7 @@ class UserRepo */ public function getAllRoles() { - return $this->role->newQuery()->orderBy('name', 'asc')->get(); + return $this->role->newQuery()->orderBy('display_name', 'asc')->get(); } /**