This commit is contained in:
Timothy Jaeryang Baek committed 2026-05-13 16:02:11 +09:00
1 parent 2f642754ac
commit 3b00e5721a
1 file changed
+21 -6
+21 -6
View File
@@ -1809,6 +1809,8 @@ async def grep_knowledge_files(
files_to_search.append(file) files_to_search.append(file)
elif __model_knowledge__: elif __model_knowledge__:
# Scoped to model's attached knowledge # Scoped to model's attached knowledge
from open_webui.models.access_grants import AccessGrants
seen_ids = set() seen_ids = set()
for item in __model_knowledge__: for item in __model_knowledge__:
item_type = item.get('type') item_type = item.get('type')
@@ -1822,12 +1824,25 @@ async def grep_knowledge_files(
knowledge = await Knowledges.get_knowledge_by_id(item_id) knowledge = await Knowledges.get_knowledge_by_id(item_id)
if not knowledge: if not knowledge:
continue continue
for fid in (knowledge.data or {}).get('file_ids', []): # Verify user can access this KB
if fid not in seen_ids: if not (
file = await Files.get_file_by_id(fid) user_role == 'admin'
if file: or knowledge.user_id == user_id
files_to_search.append(file) or await AccessGrants.has_access(
seen_ids.add(fid) user_id=user_id,
resource_type='knowledge',
resource_id=knowledge.id,
permission='read',
user_group_ids=set(user_group_ids),
)
):
continue
kb_files = await Knowledges.get_files_by_id(item_id)
if kb_files:
for f in kb_files:
if f.id not in seen_ids:
files_to_search.append(f)
seen_ids.add(f.id)
else: else:
# All accessible knowledge bases — use the same search pattern as list_knowledge_bases # All accessible knowledge bases — use the same search pattern as list_knowledge_bases
result = await Knowledges.search_knowledge_bases( result = await Knowledges.search_knowledge_bases(