Fix: Исправлено добавление пользователей в группы
✅ Проверка на дубликаты (не добавлять если уже в группе) ✅ Фильтрация поиска по организации группы ✅ UserSearchController фильтрует по organization_id ✅ Подсказка в modal для групп организации Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
parent
fff890e950
commit
98b0e7f9a9
|
|
@ -129,9 +129,14 @@ class GroupUserController extends Controller
|
||||||
$user = User::find($userId);
|
$user = User::find($userId);
|
||||||
if (!$user) continue;
|
if (!$user) continue;
|
||||||
|
|
||||||
// Проверка доступа
|
// Проверка: если группа организации - только пользователи этой организации
|
||||||
if ($group->organization_id && $user->organization_id !== $group->organization_id) {
|
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);
|
$group->users()->attach($userId);
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,16 @@ class UserSearchController extends Controller
|
||||||
public function __invoke(Request $request)
|
public function __invoke(Request $request)
|
||||||
{
|
{
|
||||||
$query = $request->get('q', '');
|
$query = $request->get('q', '');
|
||||||
|
$organizationId = $request->get('organization_id', null);
|
||||||
|
|
||||||
$users = User::query()
|
$usersQuery = User::query()->with('organization');
|
||||||
->with('organization')
|
|
||||||
|
// Если указан organization_id - фильтруем
|
||||||
|
if ($organizationId) {
|
||||||
|
$usersQuery->where('organization_id', $organizationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
$users = $usersQuery
|
||||||
->where('name', 'like', "%{$query}%")
|
->where('name', 'like', "%{$query}%")
|
||||||
->orWhere('email', 'like', "%{$query}%")
|
->orWhere('email', 'like', "%{$query}%")
|
||||||
->orderBy('name')
|
->orderBy('name')
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,15 @@
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<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>
|
||||||
<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