Fix: Исправлено добавление пользователей в группы

 Проверка на дубликаты (не добавлять если уже в группе)
 Фильтрация поиска по организации группы
 UserSearchController фильтрует по organization_id
 Подсказка в modal для групп организации

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
mirivlad 2026-03-31 15:57:39 +08:00
parent fff890e950
commit 98b0e7f9a9
3 changed files with 25 additions and 5 deletions

View File

@ -129,9 +129,14 @@ class GroupUserController extends Controller
$user = User::find($userId);
if (!$user) continue;
// Проверка доступа
// Проверка: если группа организации - только пользователи этой организации
if ($group->organization_id && $user->organization_id !== $group->organization_id) {
continue; // Пропускаем пользователей из других организаций
continue;
}
// Проверка: не состоит ли уже в группе
if ($group->users()->where('user_id', $userId)->exists()) {
continue;
}
$group->users()->attach($userId);

View File

@ -11,9 +11,16 @@ class UserSearchController extends Controller
public function __invoke(Request $request)
{
$query = $request->get('q', '');
$organizationId = $request->get('organization_id', null);
$users = User::query()
->with('organization')
$usersQuery = User::query()->with('organization');
// Если указан organization_id - фильтруем
if ($organizationId) {
$usersQuery->where('organization_id', $organizationId);
}
$users = $usersQuery
->where('name', 'like', "%{$query}%")
->orWhere('email', 'like', "%{$query}%")
->orderBy('name')

View File

@ -85,7 +85,15 @@
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<x-tags-input name="user_ids" url="{{ route('api.users.search') }}" placeholder="Начните вводить имя..." badge_color="success" />
<x-tags-input
name="user_ids"
url="{{ route('api.users.search') }}?{{ $group->organization_id ? 'organization_id=' . $group->organization_id : '' }}"
placeholder="{{ $group->organization_id ? 'Начните вводить имя (только ваша организация)...' : 'Начните вводить имя...' }}"
badge_color="success"
/>
@if($group->organization_id)
<small class="text-muted">Показываются только пользователи вашей организации</small>
@endif
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</button>