Skip to content

Commit 07dba85

Browse files
add child folders listing
1 parent 1205448 commit 07dba85

File tree

1 file changed

+73
-9
lines changed

1 file changed

+73
-9
lines changed

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

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from simcore_postgres_database.utils_repos import transaction_context
2020

2121
from ..db.plugin import get_asyncpg_engine
22+
from ..folders._folders_service import list_folders
2223
from ..folders._trash_service import trash_folder, untrash_folder
2324
from ..projects._trash_service import trash_project, untrash_project
2425
from . import _workspaces_repository, _workspaces_service
@@ -43,6 +44,66 @@ async def _check_exists_and_access(
4344
)
4445

4546

47+
async def _list_child_folders(
48+
app: web.Application,
49+
*,
50+
product_name: ProductName,
51+
user_id: UserID,
52+
workspace_id: WorkspaceID,
53+
) -> list[FolderID]:
54+
55+
child_folders: list[FolderID] = []
56+
for page_params in iter_pagination_params(limit=MAXIMUM_NUMBER_OF_ITEMS_PER_PAGE):
57+
(
58+
folders,
59+
page_params.total_number_of_items,
60+
) = await list_folders(
61+
app,
62+
user_id=user_id,
63+
product_name=product_name,
64+
folder_id=None,
65+
workspace_id=workspace_id,
66+
trashed=None,
67+
offset=page_params.offset,
68+
limit=page_params.limit,
69+
order_by=OrderBy(field=IDStr("trashed"), direction=OrderDirection.ASC),
70+
)
71+
72+
child_folders.extend([folder.folder_db.folder_id for folder in folders])
73+
74+
return child_folders
75+
76+
77+
async def _list_child_projects(
78+
app: web.Application,
79+
*,
80+
product_name: ProductName,
81+
user_id: UserID,
82+
workspace_id: WorkspaceID,
83+
) -> list[ProjectID]:
84+
85+
child_projects: list[ProjectID] = []
86+
for page_params in iter_pagination_params(limit=MAXIMUM_NUMBER_OF_ITEMS_PER_PAGE):
87+
(
88+
projects,
89+
page_params.total_number_of_items,
90+
) = await list_folders(
91+
app,
92+
user_id=user_id,
93+
product_name=product_name,
94+
folder_id=None,
95+
workspace_id=workspace_id,
96+
trashed=None,
97+
offset=page_params.offset,
98+
limit=page_params.limit,
99+
order_by=OrderBy(field=IDStr("trashed"), direction=OrderDirection.ASC),
100+
)
101+
102+
child_projects.extend([folder.folder_db.folder_id for folder in folders])
103+
104+
return child_folders
105+
106+
46107
async def trash_workspace(
47108
app: web.Application,
48109
*,
@@ -68,9 +129,12 @@ async def trash_workspace(
68129
)
69130

70131
# IMPLICIT trash
71-
child_folders: list[FolderID] = [
72-
# NOTE: follows up with https://github.com/ITISFoundation/osparc-simcore/issues/7034
73-
]
132+
child_folders: list[FolderID] = await _list_child_folders(
133+
app,
134+
product_name=product_name,
135+
user_id=user_id,
136+
workspace_id=workspace_id,
137+
)
74138

75139
for folder_id in child_folders:
76140
await trash_folder(
@@ -117,9 +181,12 @@ async def untrash_workspace(
117181
updates=WorkspaceUpdates(trashed=None, trashed_by=None),
118182
)
119183

120-
child_folders: list[FolderID] = [
121-
# NOTE: follows up with https://github.com/ITISFoundation/osparc-simcore/issues/7034
122-
]
184+
child_folders: list[FolderID] = await _list_child_folders(
185+
app,
186+
product_name=product_name,
187+
user_id=user_id,
188+
workspace_id=workspace_id,
189+
)
123190

124191
for folder_id in child_folders:
125192
await untrash_folder(
@@ -139,9 +206,6 @@ async def untrash_workspace(
139206
)
140207

141208

142-
# delete_trashed_workspace,
143-
144-
145209
def _can_delete(
146210
workspace: UserWorkspaceWithAccessRights,
147211
user_id: UserID,

0 commit comments

Comments
 (0)