From 5cd9a395344e882b4384bec0899f503ad540aecc Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 10 Aug 2026 23:40:31 -0600 Subject: [PATCH] refac --- backend/open_webui/retrieval/utils.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/retrieval/utils.py b/backend/open_webui/retrieval/utils.py index 98e15d38e8..1e159b01a5 100644 --- a/backend/open_webui/retrieval/utils.py +++ b/backend/open_webui/retrieval/utils.py @@ -1416,8 +1416,21 @@ async def get_sources_from_items( elif item.get('type') == 'chat': # Chat Attached chat = await Chats.get_chat_by_id(item.get('id')) + has_read_access = bool(chat and (user.role == 'admin' or chat.user_id == user.id)) - if chat and (user.role == 'admin' or chat.user_id == user.id): + if chat and not has_read_access: + has_read_access = await AccessGrants.has_access( + user_id=user.id, + resource_type='shared_chat', + resource_id=chat.id, + permission='read', + ) + + if chat and not has_read_access and chat.folder_id: + folder = await Folders.get_folder_by_id(chat.folder_id) + has_read_access = folder and await has_folder_access(user.id, folder, 'read', db=None) + + if has_read_access: messages_map = chat.chat.get('history', {}).get('messages', {}) message_id = chat.chat.get('history', {}).get('currentId')