2021-01-01 01:25:20 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Http\Controllers;
|
|
|
|
|
|
|
|
use BookStack\Auth\User;
|
|
|
|
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)
|
|
|
|
{
|
2021-12-15 02:47:22 +08:00
|
|
|
$hasPermission = signedInUser() && (
|
|
|
|
userCan('users-manage')
|
|
|
|
|| userCan('restrictions-manage-own')
|
|
|
|
|| userCan('restrictions-manage-all')
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!$hasPermission) {
|
|
|
|
$this->showPermissionError();
|
|
|
|
}
|
|
|
|
|
2021-01-01 01:25:20 +08:00
|
|
|
$search = $request->get('search', '');
|
2021-12-15 02:47:22 +08:00
|
|
|
$query = User::query()
|
|
|
|
->orderBy('name', 'asc')
|
2021-01-01 01:25:20 +08:00
|
|
|
->take(20);
|
|
|
|
|
|
|
|
if (!empty($search)) {
|
2021-12-15 02:47:22 +08:00
|
|
|
$query->where('name', 'like', '%' . $search . '%');
|
2021-01-01 01:25:20 +08:00
|
|
|
}
|
|
|
|
|
2021-12-15 02:47:22 +08:00
|
|
|
return view('form.user-select-list', [
|
|
|
|
'users' => $query->get(),
|
|
|
|
]);
|
2021-01-01 01:25:20 +08:00
|
|
|
}
|
|
|
|
}
|