Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions backend/onyx/file_store/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

logger = setup_logger()

RECENT_FOLDER_ID = -1


def user_file_id_to_plaintext_file_name(user_file_id: int) -> str:
"""Generate a consistent file name for storing plaintext content of a user file."""
Expand Down Expand Up @@ -244,14 +246,21 @@ def get_user_files_as_user(
Fetches all UserFile database records for a given user.
"""
user_files = get_user_files(user_file_ids, user_folder_ids, db_session)
current_user_files = []
for user_file in user_files:
# Note: if user_id is None, then all files should be None as well
# (since auth must be disabled in this case)
Comment on lines 251 to 252
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: The comment about user_id being None when auth is disabled suggests this function handles both authenticated and unauthenticated scenarios, but the filtering logic doesn't account for this properly - it would filter out all files when user_id is None.

Suggested change
# Note: if user_id is None, then all files should be None as well
# (since auth must be disabled in this case)
current_user_files = []
for user_file in user_files:
# Note: if user_id is None, then all files should be None as well
# (since auth must be disabled in this case)
if user_file.user_id == user_id:
current_user_files.append(user_file)
return current_user_files

if user_file.user_id != user_id:
raise ValueError(
f"User {user_id} does not have access to file {user_file.id}"
)
return user_files
if user_file.folder_id == RECENT_FOLDER_ID:
if user_file.user_id == user_id:
current_user_files.append(user_file)
else:
if user_file.user_id != user_id:
raise ValueError(
f"User {user_id} does not have access to file {user_file.id}"
)
current_user_files.append(user_file)

return current_user_files


def save_file_from_url(url: str) -> str:
Expand Down
Loading