Fix: Исправлено добавление пользователей в группы
✅ Проверка на дубликаты (не добавлять если уже в группе) ✅ Фильтрация поиска по организации группы ✅ UserSearchController фильтрует по organization_id ✅ Подсказка в modal для групп организации Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user