mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-08 09:26:42 +00:00
b90033a730
- Moves guest user caching from User class to app container for simplicity. - Updates test to use simpler $this->users->guest() method for consistency. - Streamlined helpers to avoid function overlap for simplicity. - Extracted user profile dropdown while doing changes.
41 lines
1001 B
PHP
41 lines
1001 B
PHP
<?php
|
|
|
|
namespace BookStack\Users\Controllers;
|
|
|
|
use BookStack\Http\Controller;
|
|
use BookStack\Users\Models\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)
|
|
{
|
|
$hasPermission = !user()->isGuest() && (
|
|
userCan('users-manage')
|
|
|| userCan('restrictions-manage-own')
|
|
|| userCan('restrictions-manage-all')
|
|
);
|
|
|
|
if (!$hasPermission) {
|
|
$this->showPermissionError();
|
|
}
|
|
|
|
$search = $request->get('search', '');
|
|
$query = User::query()
|
|
->orderBy('name', 'asc')
|
|
->take(20);
|
|
|
|
if (!empty($search)) {
|
|
$query->where('name', 'like', '%' . $search . '%');
|
|
}
|
|
|
|
return view('form.user-select-list', [
|
|
'users' => $query->get(),
|
|
]);
|
|
}
|
|
}
|