This commit is contained in:
Timothy Jaeryang Baek committed 2026-11-27 15:18:31 +04:00
1 parent 91ef645d95
commit 79d556efda
2 files changed
+12 -11

No files matched your search

+5 -2
View File
@@ -1934,11 +1934,14 @@ class ChatTable:
return None
async def get_chat_by_id_and_user_id(
self, id: str, user_id: str, db: AsyncSession | None = None
self, id: str, user_id: str, where: ColumnElement[bool] | None = None, db: AsyncSession | None = None
) -> ChatModel | None:
try:
async with get_async_db_context(db) as session:
result = await session.execute(select(Chat).filter_by(id=id, user_id=user_id))
stmt = select(Chat).filter_by(id=id, user_id=user_id)
if where is not None:
stmt = stmt.filter(where)
result = await session.execute(stmt)
chat = result.scalars().first()
if not chat:
return None
+7 -9
View File
@@ -76,8 +76,7 @@ from open_webui.utils.access_control.files import has_access_to_note_files
from open_webui.utils.access_control.notes import has_note_access
from open_webui.utils.chat_id import is_saved_chat_id
from open_webui.utils.json_codec import JSONCodec
from open_webui.models.folders import Folders
from open_webui.utils.memory import get_chat_search_condition, get_memory_folder, is_folder_only
from open_webui.utils.memory import get_chat_search_condition, get_memory_folder
from open_webui.utils.notifications import notify_target
from open_webui.utils.sanitize import sanitize_code
from open_webui.utils.skill_files import SkillFile, SkillFileOperation, skill_content_page, skill_overview
@@ -1862,13 +1861,12 @@ async def view_chat(
try:
user_id = __user__.get('id')
chat = await Chats.get_chat_by_id_and_user_id(chat_id, user_id)
folder = await get_memory_folder(UserModel(**__user__), getattr(__request__.state, 'metadata', None))
chat_folder = await Folders.get_folder_by_id(chat.folder_id) if chat and chat.folder_id else None
if not chat or (
chat.folder_id != folder.id if is_folder_only(folder) else is_folder_only(chat_folder)
):
chat = await Chats.get_chat_by_id_and_user_id(
chat_id,
user_id,
where=await get_chat_search_condition(UserModel(**__user__), getattr(__request__.state, 'metadata', None)),
)
if not chat:
return JSONCodec.dumps({'error': 'Chat not found or access denied'})
# Extract messages from history