Skip to content

Commit 838797d

Browse files
committed
ongoing
1 parent 0540dc5 commit 838797d

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

services/storage/src/simcore_service_storage/simcore_s3_dsm.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
from .dsm_factory import BaseDataManager
5555
from .exceptions.errors import (
5656
FileAccessRightError,
57+
FileFilterInvalidError,
5758
FileMetaDataNotFoundError,
5859
LinkAlreadyExistsError,
5960
ProjectAccessRightError,
@@ -146,8 +147,51 @@ async def list_files_paginated(
146147
offset: NonNegativeInt,
147148
) -> tuple[list[FileMetaData], TotalNumber]:
148149
"""returns a page of the file meta data a user has access to"""
149-
get_s3_client(self.app).list_objects_paginated()
150-
return [], 0
150+
151+
# if we have a file_filter, that means that we have at least a partial project ID
152+
# TODO: what about api/{uuid} or anything else? this should be handled at some point
153+
try:
154+
project_id = ProjectID(file_filter.parts[0]) if file_filter else None
155+
except ValueError as exc:
156+
raise FileFilterInvalidError(
157+
user_id=user_id, file_filter=file_filter
158+
) from exc
159+
160+
async with self.engine.connect() as conn:
161+
if project_id:
162+
project_access_rights = await get_project_access_rights(
163+
conn=conn, user_id=user_id, project_id=project_id
164+
)
165+
if not project_access_rights.read:
166+
raise ProjectAccessRightError(
167+
access_right="read", project_id=project_id
168+
)
169+
accessible_projects_ids = [project_id]
170+
else:
171+
accessible_projects_ids = await get_readable_project_ids(conn, user_id)
172+
173+
file_and_directory_meta_data = await file_meta_data.list_direct_children(
174+
conn,
175+
filter_by_user_id=user_id,
176+
file_id_prefix=None,
177+
is_directory=None,
178+
partial_file_id=f"{file_filter}" if file_filter else None,
179+
sha256_checksum=None,
180+
limit=limit,
181+
offset=offset,
182+
)
183+
184+
list_s3_objects = await get_s3_client(self.app).list_objects(
185+
bucket=self.simcore_bucket_name,
186+
prefix=file_filter,
187+
start_after=None,
188+
limit=limit,
189+
)
190+
# TODO: computing the total can be expensive, do we want that?
191+
total = limit + 1
192+
if len(list_s3_objects) < limit:
193+
total = len(list_s3_objects)
194+
return [], total
151195

152196
async def list_files( # noqa C901
153197
self,

0 commit comments

Comments
 (0)