Skip to content

Commit 001a4dd

Browse files
committed
fixing mapping
1 parent f8ef4e4 commit 001a4dd

File tree

5 files changed

+56
-18
lines changed

5 files changed

+56
-18
lines changed

packages/models-library/src/models_library/api_schemas_webserver/projects.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
"""
77

88
from datetime import datetime
9-
from typing import Annotated, Any, Literal, TypeAlias
9+
from typing import Annotated, Any, Literal, Self, TypeAlias
1010

11+
from common_library.dict_tools import remap_keys
1112
from models_library.folders import FolderID
1213
from models_library.utils._original_fastapi_encoders import jsonable_encoder
1314
from models_library.workspaces import WorkspaceID
@@ -35,6 +36,7 @@
3536
)
3637
from ..workspaces import WorkspaceID
3738
from ._base import EmptyModel, InputSchema, OutputSchema
39+
from .groups import GroupID
3840
from .permalinks import ProjectPermalink
3941

4042

@@ -95,14 +97,28 @@ class ProjectGet(OutputSchema):
9597
permalink: ProjectPermalink | None = None
9698
workspace_id: WorkspaceID | None
9799
folder_id: FolderID | None
100+
98101
trashed_at: datetime | None
102+
trashed_by: Annotated[
103+
GroupID | None,
104+
Field(description="Primary group ID of the user who trashed this item"),
105+
]
99106

100107
_empty_description = field_validator("description", mode="before")(
101108
none_to_empty_str_pre_validator
102109
)
103110

104111
model_config = ConfigDict(frozen=False)
105112

113+
@classmethod
114+
def from_model(cls, project: dict[str, Any]) -> Self:
115+
return cls.model_validate(
116+
remap_keys(
117+
project,
118+
rename={"trashed": "trashed_at"},
119+
)
120+
)
121+
106122

107123
TaskProjectGet: TypeAlias = TaskGet
108124

packages/models-library/src/models_library/projects.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from .projects_nodes_io import NodeIDStr
2121
from .projects_state import ProjectState
2222
from .projects_ui import StudyUI
23+
from .users import UserID
2324
from .utils.common_validators import (
2425
empty_str_to_none_pre_validator,
2526
none_to_empty_str_pre_validator,
@@ -182,10 +183,10 @@ class Project(BaseProjectModel):
182183
alias="folderId",
183184
)
184185

185-
trashed_at: datetime | None = Field(
186-
default=None,
187-
alias="trashedAt",
188-
)
189-
trashed_explicitly: bool = Field(default=False, alias="trashedExplicitly")
186+
trashed: datetime | None = None
187+
trashed_by: Annotated[UserID | None, Field(alias="trashedBy")] = None
188+
trashed_explicitly: Annotated[bool, Field(alias="trashedExplicitly")] = False
190189

191-
model_config = ConfigDict(title="osparc-simcore project", extra="forbid")
190+
model_config = ConfigDict(
191+
extra="forbid",
192+
)

services/web/server/src/simcore_service_webserver/projects/_crud_api_create.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ async def create_project( # pylint: disable=too-many-arguments,too-many-branche
423423
}
424424

425425
# Ensures is like ProjectGet
426-
data = ProjectGet.model_validate(new_project).data(exclude_unset=True)
426+
data = ProjectGet.from_model(new_project).data(exclude_unset=True)
427427

428428
raise web.HTTPCreated(
429429
text=json_dumps({"data": data}),

services/web/server/src/simcore_service_webserver/projects/_db_utils.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,20 @@ def convert_to_schema_names(
8282
) -> dict:
8383
# SEE https://github.com/ITISFoundation/osparc-simcore/issues/3516
8484
converted_args = {}
85-
for key, value in project_database_data.items():
86-
if key in DB_EXCLUSIVE_COLUMNS:
85+
for col_name, col_value in project_database_data.items():
86+
if col_name in DB_EXCLUSIVE_COLUMNS:
8787
continue
88-
converted_value = value
89-
if isinstance(value, datetime) and key not in {"trashed"}:
90-
converted_value = format_datetime(value)
91-
elif key == "prj_owner":
88+
converted_value = col_value
89+
if isinstance(col_value, datetime) and col_name not in {"trashed"}:
90+
converted_value = format_datetime(col_value)
91+
elif col_name == "prj_owner":
9292
# this entry has to be converted to the owner e-mail address
9393
converted_value = user_email
9494

95-
if key in SCHEMA_NON_NULL_KEYS and value is None:
95+
if col_name in SCHEMA_NON_NULL_KEYS and col_value is None:
9696
converted_value = ""
9797

98-
converted_args[snake_to_camel(key)] = converted_value
98+
converted_args[snake_to_camel(col_name)] = converted_value
9999
converted_args.update(**kwargs)
100100
return converted_args
101101

@@ -275,7 +275,26 @@ async def _get_project(
275275

276276
query = (
277277
sa.select(
278-
*[col for col in projects.columns if col.name not in ["access_rights"]],
278+
projects.c.id,
279+
projects.c.type,
280+
projects.c.uuid,
281+
projects.c.name,
282+
projects.c.description,
283+
projects.c.thumbnail,
284+
projects.c.prj_owner, # == user.id (who created)
285+
projects.c.creation_date,
286+
projects.c.last_change_date,
287+
projects.c.workbench,
288+
projects.c.ui,
289+
projects.c.classifiers,
290+
projects.c.dev,
291+
projects.c.quality,
292+
projects.c.published,
293+
projects.c.hidden,
294+
projects.c.trashed,
295+
projects.c.trashed_by, # == user.id (who trashed)
296+
projects.c.trashed_explicitly,
297+
projects.c.workspace_id,
279298
access_rights_subquery.c.access_rights,
280299
)
281300
.select_from(projects.join(access_rights_subquery, isouter=True))

services/web/server/tests/unit/with_dbs/03/test_project_db.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ def _assert_added_project(
9797
"creationDate",
9898
"lastChangeDate",
9999
"accessRights", # NOTE: access rights were moved away from the projects table
100-
"trashedAt",
100+
"trashed",
101+
"trashedBy",
101102
"trashedExplicitly",
102103
]
103104
assert {k: v for k, v in expected_prj.items() if k in _DIFFERENT_KEYS} != {
@@ -184,6 +185,7 @@ async def insert_project_in_db(
184185
client: TestClient,
185186
) -> AsyncIterator[Callable[..., Awaitable[dict[str, Any]]]]:
186187
inserted_projects = []
188+
assert client.app
187189

188190
async def _inserter(prj: dict[str, Any], **overrides) -> dict[str, Any]:
189191
# add project without user id -> by default creates a template

0 commit comments

Comments
 (0)