Fix: Фильтрация групп + исправление GroupPolicy
✅ API groups/search принимает user_id параметр ✅ Фильтр: общие + группы организации ИЛИ только общие ✅ tags-input передаёт user_id в API ✅ Очистка кэша для GroupPolicy Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
parent
11c5dcaf48
commit
be44d09169
|
|
@ -11,9 +11,28 @@ class GroupSearchController extends Controller
|
|||
public function __invoke(Request $request)
|
||||
{
|
||||
$query = $request->get('q', '');
|
||||
$userId = $request->get('user_id', null);
|
||||
|
||||
$groups = Group::query()
|
||||
->with('organization')
|
||||
$groupsQuery = Group::query()->with('organization');
|
||||
|
||||
// Если указан user_id - фильтруем по доступным группам
|
||||
if ($userId) {
|
||||
$user = \App\Models\User::find($userId);
|
||||
if ($user) {
|
||||
if ($user->organization_id) {
|
||||
// Пользователь в организации - показываем общие + группы организации
|
||||
$groupsQuery->where(function($q) use ($user) {
|
||||
$q->whereNull('organization_id')
|
||||
->orWhere('organization_id', $user->organization_id);
|
||||
});
|
||||
} else {
|
||||
// Пользователь без организации - только общие группы
|
||||
$groupsQuery->whereNull('organization_id');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$groups = $groupsQuery
|
||||
->where('name', 'like', "%{$query}%")
|
||||
->orderBy('name')
|
||||
->limit(50)
|
||||
|
|
|
|||
|
|
@ -66,8 +66,9 @@
|
|||
<x-tags-input
|
||||
name="groups"
|
||||
url="{{ route('api.groups.search') }}"
|
||||
placeholder="Начните вводить название группы..."
|
||||
placeholder="Начните введите название группы..."
|
||||
:value="$userGroups"
|
||||
:user_id="$user->id"
|
||||
/>
|
||||
<small class="text-muted">Выберите группы</small>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
@props(['name', 'url', 'placeholder' => 'Начните вводить...', 'value' => []])
|
||||
@props(['name', 'url', 'placeholder' => 'Начните вводить...', 'value' => [], 'user_id' => null])
|
||||
|
||||
<div class="tags-input-container">
|
||||
<input type="text" class="form-control" id="{{ $name }}-input" placeholder="{{ $placeholder }}" autocomplete="off">
|
||||
|
|
@ -69,7 +69,12 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
load: function(query, callback) {
|
||||
if (query.length < 2) return callback();
|
||||
|
||||
fetch('{{ $url }}?q=' + encodeURIComponent(query))
|
||||
let url = '{{ $url }}?q=' + encodeURIComponent(query);
|
||||
@if($user_id)
|
||||
url += '&user_id={{ $user_id }}';
|
||||
@endif
|
||||
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
// Фильтруем уже выбранные
|
||||
|
|
|
|||
Loading…
Reference in New Issue