Fix: Организация - пользователи и группы
✅ Добавлен use User и use Group ✅ exclude_organization_id для поиска пользователей ✅ Исключение пользователей из текущей организации Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
parent
de64be24eb
commit
21a836ef4d
|
|
@ -4,6 +4,8 @@ namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Organization;
|
use App\Models\Organization;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\Group;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,18 @@ class UserSearchController extends Controller
|
||||||
{
|
{
|
||||||
$query = $request->get('q', '');
|
$query = $request->get('q', '');
|
||||||
$organizationId = $request->get('organization_id', null);
|
$organizationId = $request->get('organization_id', null);
|
||||||
|
$excludeOrganizationId = $request->get('exclude_organization_id', null);
|
||||||
|
|
||||||
$usersQuery = User::query()->with('organization');
|
$usersQuery = User::query()->with('organization');
|
||||||
|
|
||||||
|
// Исключаем пользователей из организации (для добавления в организацию)
|
||||||
|
if ($excludeOrganizationId) {
|
||||||
|
$usersQuery->where(function($q) use ($excludeOrganizationId) {
|
||||||
|
$q->whereNull('organization_id')
|
||||||
|
->orWhere('organization_id', '!=', $excludeOrganizationId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Если указан organization_id - фильтруем
|
// Если указан organization_id - фильтруем
|
||||||
if ($organizationId) {
|
if ($organizationId) {
|
||||||
$usersQuery->where('organization_id', $organizationId);
|
$usersQuery->where('organization_id', $organizationId);
|
||||||
|
|
@ -33,7 +42,7 @@ class UserSearchController extends Controller
|
||||||
->map(function($user) {
|
->map(function($user) {
|
||||||
return [
|
return [
|
||||||
'id' => $user->id,
|
'id' => $user->id,
|
||||||
'text' => $user->name . ($user->organization ? " ({$user->organization->name})" : ''),
|
'text' => $user->name . ($user->organization ? " ({$user->organization->name})" : ' (Без организации)'),
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -134,11 +134,11 @@
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<x-tags-input
|
<x-tags-input
|
||||||
name="user_ids"
|
name="user_ids"
|
||||||
url="{{ route('api.users.search') }}"
|
url="{{ route('api.users.search', ['exclude_organization_id' => $organization->id]) }}"
|
||||||
placeholder="Начните вводить имя (пользователи без организации)..."
|
placeholder="Начните вводить имя (пользователи без организации или из других организаций)..."
|
||||||
badge_color="success"
|
badge_color="success"
|
||||||
/>
|
/>
|
||||||
<small class="text-muted">Можно добавить пользователей без организации</small>
|
<small class="text-muted">Можно добавить пользователей без организации или из других организаций</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</button>
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</button>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue