Skip to content

Commit 47c5c0a

Browse files
committed
back to uid
1 parent afa016e commit 47c5c0a

File tree

8 files changed

+36
-17
lines changed

8 files changed

+36
-17
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from ..basic_types import IDStr
88
from ..folders import FolderID
99
from ..groups import GroupID
10+
from ..users import UserID
1011
from ..utils.common_validators import null_or_none_str_to_none_validator
1112
from ..workspaces import WorkspaceID
1213
from ._base import InputSchema, OutputSchema
@@ -19,7 +20,7 @@ class FolderGet(OutputSchema):
1920
created_at: datetime
2021
modified_at: datetime
2122
trashed_at: datetime | None
22-
trashed_by: GroupID | None
23+
trashed_by: UserID | None
2324
owner: GroupID
2425
workspace_id: WorkspaceID | None
2526
my_access_rights: AccessRights

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
PlainSerializer,
2121
field_validator,
2222
)
23+
from simcore_service_webserver.models import UserID
2324

2425
from ..api_schemas_long_running_tasks.tasks import TaskGet
2526
from ..basic_types import LongTruncatedStr, ShortTruncatedStr
2627
from ..emails import LowerCaseEmailStr
2728
from ..folders import FolderID
28-
from ..groups import GroupID
2929
from ..projects import ClassifierID, DateTimeStr, NodesDict, ProjectID
3030
from ..projects_access import AccessRights, GroupIDStr
3131
from ..projects_state import ProjectState
@@ -99,7 +99,7 @@ class ProjectGet(OutputSchema):
9999
folder_id: FolderID | None
100100

101101
trashed_at: datetime | None
102-
trashed_by: GroupID | None
102+
trashed_by: UserID | None
103103

104104
_empty_description = field_validator("description", mode="before")(
105105
none_to_empty_str_pre_validator

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
copy_data_folders_from_project,
3434
get_project_total_size_simcore_s3,
3535
)
36+
from ..users._users_service import get_user_primary_group_id
3637
from ..users.api import get_user_fullname
3738
from ..workspaces.api import check_user_workspace_access, get_user_workspace
3839
from ..workspaces.errors import WorkspaceAccessForbiddenError
@@ -421,7 +422,16 @@ async def create_project( # pylint: disable=too-many-arguments,too-many-branche
421422
}
422423

423424
# Ensures is like ProjectGet
424-
data = ProjectGet.from_domain_model(new_project).data(exclude_unset=True)
425+
if trashed_by_uid := new_project.get("trashed_by"):
426+
trashed_by_primary_gid = await get_user_primary_group_id(
427+
request.app, trashed_by_uid
428+
)
429+
else:
430+
trashed_by_primary_gid = None
431+
432+
data = ProjectGet.from_domain_model(
433+
new_project, trashed_by_primary_gid=trashed_by_primary_gid
434+
).data(exclude_unset=True)
425435

426436
raise web.HTTPCreated(
427437
text=json_dumps({"data": data}),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
projects.c.hidden,
3636
projects.c.workspace_id,
3737
projects.c.trashed,
38+
projects.c.trashed_by,
39+
projects.c.trashed_explicitly,
3840
]
3941

4042

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from . import projects_api
1616
from ._access_rights_api import check_user_project_permission
1717
from .exceptions import ProjectRunningConflictError
18-
from .models import ProjectPatchExtended
18+
from .models import ProjectPatchInternalExtended
1919

2020
_logger = logging.getLogger(__name__)
2121

@@ -94,8 +94,10 @@ async def _schedule():
9494
user_id=user_id,
9595
product_name=product_name,
9696
project_uuid=project_id,
97-
project_patch=ProjectPatchExtended(
98-
trashed_at=arrow.utcnow().datetime, trashed_explicitly=explicit
97+
project_patch=ProjectPatchInternalExtended(
98+
trashed_at=arrow.utcnow().datetime,
99+
trashed_explicitly=explicit,
100+
trashed_by=user_id,
99101
),
100102
)
101103

@@ -113,5 +115,7 @@ async def untrash_project(
113115
user_id=user_id,
114116
product_name=product_name,
115117
project_uuid=project_id,
116-
project_patch=ProjectPatchExtended(trashed_at=None, trashed_explicitly=False),
118+
project_patch=ProjectPatchInternalExtended(
119+
trashed_at=None, trashed_explicitly=False, trashed_by=None
120+
),
117121
)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class ProjectDB(BaseModel):
5353
hidden: bool
5454
workspace_id: WorkspaceID | None
5555
trashed: datetime | None
56+
trashed_by: UserID | None
5657
trashed_explicitly: bool = False
5758

5859
model_config = ConfigDict(from_attributes=True, arbitrary_types_allowed=True)
@@ -94,9 +95,10 @@ class UserProjectAccessRightsWithWorkspace(BaseModel):
9495
model_config = ConfigDict(from_attributes=True)
9596

9697

97-
class ProjectPatchExtended(ProjectPatch):
98+
class ProjectPatchInternalExtended(ProjectPatch):
9899
# ONLY used internally
99100
trashed_at: datetime | None
101+
trashed_by: UserID | None
100102
trashed_explicitly: bool
101103

102104
model_config = ConfigDict(populate_by_name=True, extra="forbid")

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
ProjectTooManyProjectOpenedError,
147147
)
148148
from .lock import get_project_locked_state, is_project_locked, lock_project
149-
from .models import ProjectDict, ProjectPatchExtended
149+
from .models import ProjectDict, ProjectPatchInternalExtended
150150
from .settings import ProjectsSettings, get_plugin_settings
151151
from .utils import extract_dns_without_default_port
152152

@@ -252,7 +252,7 @@ async def patch_project(
252252
*,
253253
user_id: UserID,
254254
project_uuid: ProjectID,
255-
project_patch: ProjectPatch | ProjectPatchExtended,
255+
project_patch: ProjectPatch | ProjectPatchInternalExtended,
256256
product_name: ProductName,
257257
):
258258
patch_project_data = project_patch.to_domain_model()

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ async def test_trash_projects( # noqa: PLR0915
150150
assert got.trashed_at
151151
assert trashing_at < got.trashed_at
152152
assert got.trashed_at < arrow.utcnow().datetime
153-
assert got.trashed_by == logged_user["primary_gid"]
153+
assert got.trashed_by == logged_user["id"]
154154

155155
# LIST trashed
156156
resp = await client.get("/v0/projects", params={"filters": '{"trashed": true}'})
@@ -233,7 +233,7 @@ async def test_trash_single_folder(client: TestClient, logged_user: UserInfoDict
233233
assert got.trashed_at
234234
assert trashing_at < got.trashed_at
235235
assert got.trashed_at < arrow.utcnow().datetime
236-
assert got.trashed_by == logged_user["primary_gid"]
236+
assert got.trashed_by == logged_user["id"]
237237
assert got.owner == logged_user["primary_gid"]
238238

239239
# LIST trashed
@@ -350,19 +350,19 @@ async def test_trash_folder_with_content(
350350
data, _ = await assert_status(resp, status.HTTP_200_OK)
351351
got = FolderGet.model_validate(data)
352352
assert got.trashed_at is not None
353-
assert got.trashed_by == logged_user["primary_gid"]
353+
assert got.trashed_by == logged_user["id"]
354354

355355
resp = await client.get(f"/v0/folders/{subfolder.folder_id}")
356356
data, _ = await assert_status(resp, status.HTTP_200_OK)
357357
got = FolderGet.model_validate(data)
358358
assert got.trashed_at is not None
359-
assert got.trashed_by == logged_user["primary_gid"]
359+
assert got.trashed_by == logged_user["id"]
360360

361361
resp = await client.get(f"/v0/projects/{project_uuid}")
362362
data, _ = await assert_status(resp, status.HTTP_200_OK)
363363
got = ProjectGet.model_validate(data)
364364
assert got.trashed_at is not None
365-
assert got.trashed_by == logged_user["primary_gid"]
365+
assert got.trashed_by == logged_user["id"]
366366

367367
# UNTRASH folder
368368
resp = await client.post(f"/v0/folders/{folder.folder_id}:untrash")
@@ -477,7 +477,7 @@ async def test_trash_empty_workspace(
477477
)
478478
assert page.data[0].trashed_at is not None
479479
assert before_trash < page.data[0].trashed_at
480-
assert page.data[0].trashed_by == logged_user["primary_gid"]
480+
assert page.data[0].trashed_by == logged_user["id"]
481481

482482
# --------
483483

0 commit comments

Comments
 (0)