3 namespace BookStack\Auth\Queries;
5 use BookStack\Auth\User;
6 use Illuminate\Pagination\LengthAwarePaginator;
9 * Get all the users with their permissions in a paginated format.
10 * Note: Due to the use of email search this should only be used when
11 * user is assumed to be trusted. (Admin users).
12 * Email search can be abused to extract email addresses.
14 class AllUsersPaginatedAndSorted
17 * @param array{sort: string, order: string, search: string} $sortData
19 public function run(int $count, array $sortData): LengthAwarePaginator
21 $sort = $sortData['sort'];
22 if ($sort === 'created_at') {
23 $sort = 'users.created_at';
26 $query = User::query()->select(['*'])
27 ->scopes(['withLastActivityAt'])
28 ->with(['roles', 'avatar'])
29 ->withCount('mfaValues')
30 ->orderBy($sort, $sortData['order']);
32 if ($sortData['search']) {
33 $term = '%' . $sortData['search'] . '%';
34 $query->where(function ($query) use ($term) {
35 $query->where('name', 'like', $term)
36 ->orWhere('email', 'like', $term);
40 return $query->paginate($count);