Skip to content

Commit 6e5df41

Browse files
committed
pass displayed path
1 parent 7674c16 commit 6e5df41

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

services/storage/src/simcore_service_storage/models.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ class FileMetaData(FileMetaDataGet):
108108
user_id: UserID | None
109109
sha256_checksum: SHA256Str | None
110110

111+
def update_display_fields(self, id_name_mapping: dict[str, str]) -> None:
112+
if self.project_id:
113+
self.project_name = id_name_mapping.get(f"{self.project_id}")
114+
if self.node_id:
115+
self.node_name = id_name_mapping.get(f"{self.node_id}")
116+
111117
@classmethod
112118
@validate_call
113119
def from_simcore_node(
@@ -343,6 +349,7 @@ def none(cls) -> "AccessRights":
343349

344350
class PathMetaData(BaseModel):
345351
path: Path
352+
display_path: Path
346353
location_id: LocationID
347354
location: LocationName
348355
bucket_name: str
@@ -355,14 +362,22 @@ class PathMetaData(BaseModel):
355362

356363
file_meta_data: FileMetaData | None
357364

358-
model_config = ConfigDict(from_attributes=True)
365+
def update_display_fields(self, id_name_mapping: dict[str, str]) -> None:
366+
display_path = f"{self.path}"
367+
for old, new in id_name_mapping.items():
368+
display_path = display_path.replace(old, new)
369+
self.display_path = Path(display_path)
370+
371+
if self.file_meta_data:
372+
self.file_meta_data.update_display_fields(id_name_mapping)
359373

360374
@classmethod
361375
def from_s3_object_in_dir(
362376
cls, s3_object: S3MetaData | S3DirectoryMetaData, dir_fmd: FileMetaData
363377
) -> "PathMetaData":
364378
return cls(
365379
path=s3_object.as_path(),
380+
display_path=s3_object.as_path(),
366381
location_id=dir_fmd.location_id,
367382
location=dir_fmd.location,
368383
bucket_name=dir_fmd.bucket_name,
@@ -379,6 +394,6 @@ def from_s3_object_in_dir(
379394
def to_api_model(self) -> PathMetaDataGet:
380395
return PathMetaDataGet.model_construct(
381396
path=self.path,
382-
display_path=self.path,
397+
display_path=self.display_path,
383398
file_meta_data=self.file_meta_data,
384399
)

services/storage/src/simcore_service_storage/modules/db/projects.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from contextlib import suppress
33

44
import sqlalchemy as sa
5-
from models_library.projects import ProjectAtDB, ProjectID
5+
from models_library.projects import ProjectAtDB, ProjectID, ProjectIDStr
6+
from models_library.projects_nodes_io import NodeIDStr
67
from pydantic import ValidationError
78
from simcore_postgres_database.storage_models import projects
89
from sqlalchemy.ext.asyncio import AsyncConnection
@@ -37,3 +38,19 @@ async def project_exists(
3738
)
3839
== 1
3940
)
41+
42+
43+
async def get_project_id_and_node_id_to_names_map(
44+
conn: AsyncConnection, project_uuids: list[ProjectID]
45+
) -> dict[ProjectID, dict[ProjectIDStr | NodeIDStr, str]]:
46+
mapping = {}
47+
async for row in await conn.stream(
48+
sa.select(projects.c.uuid, projects.c.name, projects.c.workbench).where(
49+
projects.c.uuid.in_(f"{pid}" for pid in project_uuids)
50+
)
51+
):
52+
mapping[ProjectID(f"{row.uuid}")] = {f"{row.uuid}": row.name} | {
53+
f"{node_id}": node["label"] for node_id, node in row.workbench.items()
54+
}
55+
56+
return mapping

services/storage/src/simcore_service_storage/simcore_s3_dsm.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,20 @@ async def list_paths(
250250
cursor=cursor,
251251
)
252252

253+
# extract the returned project_ids
254+
project_ids = list(
255+
{path.project_id for path in paths_metadata if path.project_id is not None}
256+
)
257+
async with self.engine.connect() as conn:
258+
ids_names_map = await projects.get_project_id_and_node_id_to_names_map(
259+
conn, project_ids
260+
)
261+
262+
for path in paths_metadata:
263+
if path.project_id is not None:
264+
id_name_map = ids_names_map.get(path.project_id, {})
265+
path.update_display_fields(id_name_map)
266+
253267
return paths_metadata, next_cursor, total
254268

255269
async def list_files(

0 commit comments

Comments
 (0)