2020-12-31 12:25:20 -05:00
|
|
|
<?php
|
|
|
|
|
2023-05-17 12:56:55 -04:00
|
|
|
namespace BookStack\Users\Controllers;
|
2020-12-31 12:25:20 -05:00
|
|
|
|
2023-05-18 15:53:39 -04:00
|
|
|
use BookStack\Http\Controller;
|
2023-05-17 12:56:55 -04:00
|
|
|
use BookStack\Users\Models\User;
|
2020-12-31 12:25:20 -05:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class UserSearchController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Search users in the system, with the response formatted
|
|
|
|
* for use in a select-style list.
|
|
|
|
*/
|
|
|
|
public function forSelect(Request $request)
|
|
|
|
{
|
2023-09-16 08:18:35 -04:00
|
|
|
$hasPermission = !user()->isGuest() && (
|
2021-12-15 08:49:20 -05:00
|
|
|
userCan('users-manage')
|
2021-12-14 13:47:22 -05:00
|
|
|
|| userCan('restrictions-manage-own')
|
|
|
|
|| userCan('restrictions-manage-all')
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!$hasPermission) {
|
|
|
|
$this->showPermissionError();
|
|
|
|
}
|
|
|
|
|
2020-12-31 12:25:20 -05:00
|
|
|
$search = $request->get('search', '');
|
2021-12-14 13:47:22 -05:00
|
|
|
$query = User::query()
|
|
|
|
->orderBy('name', 'asc')
|
2020-12-31 12:25:20 -05:00
|
|
|
->take(20);
|
|
|
|
|
|
|
|
if (!empty($search)) {
|
2021-12-14 13:47:22 -05:00
|
|
|
$query->where('name', 'like', '%' . $search . '%');
|
2020-12-31 12:25:20 -05:00
|
|
|
}
|
|
|
|
|
2021-12-14 13:47:22 -05:00
|
|
|
return view('form.user-select-list', [
|
|
|
|
'users' => $query->get(),
|
|
|
|
]);
|
2020-12-31 12:25:20 -05:00
|
|
|
}
|
|
|
|
}
|