Skip to content

Commit eab0655

Browse files
hide trashed projects
1 parent 45ae7a5 commit eab0655

File tree

3 files changed

+71
-13
lines changed

3 files changed

+71
-13
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,26 @@ async def is_project_hidden(app: web.Application, project_id: ProjectID) -> bool
10361036
return await db.is_hidden(project_id)
10371037

10381038

1039+
async def set_project_hidden_flag(
1040+
app: web.Application,
1041+
*,
1042+
product_name: ProductName,
1043+
user_id: UserID,
1044+
project_id: ProjectID,
1045+
hidden: bool,
1046+
) -> None:
1047+
await check_user_project_permission(
1048+
app,
1049+
project_id=project_id,
1050+
user_id=user_id,
1051+
product_name=product_name,
1052+
permission="write",
1053+
)
1054+
1055+
projects_repo: ProjectDBAPI = app[APP_PROJECT_DBAPI]
1056+
await projects_repo.set_hidden_flag(project_id, hidden=hidden)
1057+
1058+
10391059
async def patch_project_node(
10401060
app: web.Application,
10411061
*,

services/web/server/src/simcore_service_webserver/trash/_rest.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import logging
32

43
from aiohttp import web
@@ -50,10 +49,7 @@ async def empty_trash(request: web.Request):
5049
user_id = get_user_id(request)
5150
product_name = products_web.get_product_name(request)
5251

53-
is_fired = asyncio.Event()
54-
5552
async def _empty_trash():
56-
is_fired.set()
5753
await _service.safe_empty_trash(
5854
request.app, product_name=product_name, user_id=user_id
5955
)
@@ -64,10 +60,7 @@ async def _empty_trash():
6460
fire_and_forget_tasks_collection=request.app[APP_FIRE_AND_FORGET_TASKS_KEY],
6561
)
6662

67-
# NOTE: Ensures `fire_and_forget_task` is triggered; otherwise,
68-
# when the front-end requests the trash item list,
69-
# it may still display items, misleading the user into
70-
# thinking the `empty trash` operation failed.
71-
await is_fired.wait()
63+
# ensure trashed entities are hidden before returning response
64+
await _service.hide_trashed(request.app, product_name=product_name, user_id=user_id)
7265

7366
return web.json_response(status=status.HTTP_204_NO_CONTENT)

services/web/server/src/simcore_service_webserver/trash/_service.py

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from ..folders import folders_trash_service
1313
from ..products import products_service
14-
from ..projects import projects_trash_service
14+
from ..projects import projects_service, projects_trash_service
1515
from .settings import get_plugin_settings
1616

1717
_logger = logging.getLogger(__name__)
@@ -35,8 +35,9 @@ async def _empty_explicitly_trashed_projects(
3535
with log_context(
3636
_logger,
3737
logging.DEBUG,
38-
"Deleting %s explicitly trashed projects",
38+
"Deleting %s explicitly trashed projects: %s",
3939
len(trashed_projects_ids),
40+
trashed_projects_ids,
4041
):
4142
for project_id in trashed_projects_ids:
4243
try:
@@ -57,7 +58,6 @@ async def _empty_explicitly_trashed_projects(
5758
"product_name": product_name,
5859
"user_id": user_id,
5960
},
60-
tip=_TIP,
6161
)
6262
)
6363

@@ -72,8 +72,9 @@ async def _empty_explicitly_trashed_folders_and_content(
7272
with log_context(
7373
_logger,
7474
logging.DEBUG,
75-
"Deleting %s trashed folders (and all its content)",
75+
"Deleting %s trashed folders (and all its content): %s",
7676
len(trashed_folders_ids),
77+
trashed_folders_ids,
7778
):
7879
for folder_id in trashed_folders_ids:
7980
try:
@@ -99,6 +100,50 @@ async def _empty_explicitly_trashed_folders_and_content(
99100
)
100101

101102

103+
async def _hide_trashed_projects(
104+
app: web.Application, product_name: ProductName, user_id: UserID
105+
):
106+
trashed_projects_ids = (
107+
await projects_trash_service.list_explicitly_trashed_projects(
108+
app=app, product_name=product_name, user_id=user_id
109+
)
110+
)
111+
with log_context(
112+
_logger,
113+
logging.DEBUG,
114+
"Hiding %s explicitly trashed projects",
115+
len(trashed_projects_ids),
116+
):
117+
for project_id in trashed_projects_ids:
118+
try:
119+
await projects_service.set_project_hidden_flag(
120+
app,
121+
product_name=product_name,
122+
user_id=user_id,
123+
project_id=project_id,
124+
hidden=True,
125+
)
126+
except Exception as exc: # pylint: disable=broad-exception-caught
127+
_logger.warning(
128+
**create_troubleshotting_log_kwargs(
129+
"Error hiding a trashed project while emptying trash.",
130+
error=exc,
131+
error_context={
132+
"project_id": project_id,
133+
"product_name": product_name,
134+
"user_id": user_id,
135+
},
136+
tip=_TIP,
137+
)
138+
)
139+
140+
141+
async def hide_trashed(
142+
app: web.Application, *, product_name: ProductName, user_id: UserID
143+
):
144+
await _hide_trashed_projects(app, product_name, user_id)
145+
146+
102147
async def safe_empty_trash(
103148
app: web.Application, *, product_name: ProductName, user_id: UserID
104149
):

0 commit comments

Comments
 (0)