Skip to content

Commit 65fbbf5

Browse files
authored
fix: grant file access for knowledge attached to shared workspace models (open-webui#22151)
1 parent 10baa6e commit 65fbbf5

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

backend/open_webui/tools/builtin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,7 @@ async def query_knowledge_files(
18311831
elif item_type == "file":
18321832
# Individual file - use file-{id} as collection name
18331833
file = Files.get_file_by_id(item_id)
1834-
if file and (user_role == "admin" or file.user_id == user_id):
1834+
if file:
18351835
collection_names.append(f"file-{item_id}")
18361836

18371837
elif item_type == "note":

backend/open_webui/utils/access_control/files.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from open_webui.models.channels import Channels
88
from open_webui.models.chats import Chats
99
from open_webui.models.groups import Groups
10+
from open_webui.models.models import Models
1011
from open_webui.models.access_grants import AccessGrants
1112

1213
log = logging.getLogger(__name__)
@@ -21,6 +22,7 @@ def has_access_to_file(
2122
"""
2223
Check if a user has the specified access to a file through any of:
2324
- Knowledge bases (ownership or access grants)
25+
- Shared workspace models that attach the file directly
2426
- Channels the user is a member of
2527
- Shared chats
2628
@@ -72,4 +74,12 @@ def has_access_to_file(
7274
if chats:
7375
return True
7476

77+
# Check if the file is directly attached to a shared workspace model
78+
for model in Models.get_models_by_user_id(user.id, permission=access_type, db=db):
79+
knowledge_items = getattr(model.meta, "knowledge", None) or []
80+
for item in knowledge_items:
81+
if isinstance(item, dict) and item.get("type") == "file" and item.get("id") == file.id:
82+
return True
83+
7584
return False
85+

0 commit comments

Comments
 (0)