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'];
23 $query = User::query()->select(['*'])
24 ->scopes(['withLastActivityAt'])
25 ->with(['roles', 'avatar'])
26 ->withCount('mfaValues')
27 ->orderBy($sort, $sortData['order']);
29 if ($sortData['search']) {
30 $term = '%' . $sortData['search'] . '%';
31 $query->where(function ($query) use ($term) {
32 $query->where('name', 'like', $term)
33 ->orWhere('email', 'like', $term);
37 return $query->paginate($count);