refac: resolve knowledge file access from the file association (#29937)

`has_access_to_file` now derives knowledge-base access purely from the knowledge-file association, instead of also consulting the `collection_name` value stored on the file record.
This commit is contained in:
Classic298
2026-09-16 15:59:25 -04:00
committed by GitHub
parent ff7f35a30d
commit fbc4897269
@@ -63,28 +63,6 @@ async def has_access_to_file(
) and (access_type == 'read' or knowledge_base.user_id == file.user_id):
return True
knowledge_base_id = file.meta.get('collection_name') if file.meta else None
if knowledge_base_id:
# Fetch the one referenced knowledge base instead of listing every
# knowledge base the user can access just to scan for this id.
knowledge_base = await Knowledges.get_knowledge_by_id(knowledge_base_id, db=db)
if (
knowledge_base
and (access_type == 'read' or knowledge_base.user_id == file.user_id)
and (
knowledge_base.user_id == user.id
or await AccessGrants.has_access(
user_id=user.id,
resource_type='knowledge',
resource_id=knowledge_base.id,
permission=access_type,
user_group_ids=user_group_ids,
db=db,
)
)
):
return True
# Check if the file is associated with any channels the user has access to
channels = await Channels.get_channels_by_file_id_and_user_id(file_id, user.id, db=db)
if access_type == 'read' and channels: