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