Skip to content

Commit 277cf70

Browse files
authored
🎨 Enables trash in web-api (#6861)
1 parent 42711d9 commit 277cf70

File tree

5 files changed

+19
-33
lines changed

5 files changed

+19
-33
lines changed

services/web/server/src/simcore_service_webserver/application_settings.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,6 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
280280
WEBSERVER_REMOTE_DEBUG: bool = True
281281
WEBSERVER_SOCKETIO: bool = True
282282
WEBSERVER_TAGS: bool = True
283-
WEBSERVER_TRASH: Annotated[
284-
bool,
285-
Field(
286-
description="Currently only used to enable/disable front-end",
287-
validation_alias=AliasChoices(
288-
"WEBSERVER_TRASH", "WEBSERVER_DEV_FEATURES_ENABLED"
289-
),
290-
),
291-
] = False
292283
WEBSERVER_VERSION_CONTROL: bool = True
293284
WEBSERVER_WALLETS: bool = True
294285
WEBSERVER_WORKSPACES: bool = True
@@ -302,7 +293,7 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
302293

303294
@model_validator(mode="before")
304295
@classmethod
305-
def build_vcs_release_url_if_unset(cls, values):
296+
def _build_vcs_release_url_if_unset(cls, values):
306297
release_url = values.get("SIMCORE_VCS_RELEASE_URL")
307298

308299
if release_url is None and (
@@ -323,12 +314,11 @@ def build_vcs_release_url_if_unset(cls, values):
323314
# TODO: consider mark as dev-feature in field extras of Config attr.
324315
# Then they can be automtically advertised
325316
"WEBSERVER_META_MODELING",
326-
"WEBSERVER_TRASH",
327317
"WEBSERVER_VERSION_CONTROL",
328318
mode="before",
329319
)
330320
@classmethod
331-
def enable_only_if_dev_features_allowed(cls, v, info: ValidationInfo):
321+
def _enable_only_if_dev_features_allowed(cls, v, info: ValidationInfo):
332322
"""Ensures that plugins 'under development' get programatically
333323
disabled if WEBSERVER_DEV_FEATURES_ENABLED=False
334324
"""
@@ -345,19 +335,14 @@ def enable_only_if_dev_features_allowed(cls, v, info: ValidationInfo):
345335
else False
346336
)
347337

348-
@cached_property
349-
def log_level(self) -> int:
350-
level: int = getattr(logging, self.WEBSERVER_LOGLEVEL.upper())
351-
return level
352-
353338
@field_validator("WEBSERVER_LOGLEVEL")
354339
@classmethod
355-
def valid_log_level(cls, value):
340+
def _valid_log_level(cls, value):
356341
return cls.validate_log_level(value)
357342

358343
@field_validator("SC_HEALTHCHECK_TIMEOUT", mode="before")
359344
@classmethod
360-
def get_healthcheck_timeout_in_seconds(cls, v):
345+
def _get_healthcheck_timeout_in_seconds(cls, v):
361346
# Ex. HEALTHCHECK --interval=5m --timeout=3s
362347
if isinstance(v, str):
363348
factor = 1 # defaults on s
@@ -371,6 +356,11 @@ def get_healthcheck_timeout_in_seconds(cls, v):
371356

372357
# HELPERS --------------------------------------------------------
373358

359+
@cached_property
360+
def log_level(self) -> int:
361+
level: int = getattr(logging, self.WEBSERVER_LOGLEVEL.upper())
362+
return level
363+
374364
def is_enabled(self, field_name: str) -> bool:
375365
return bool(getattr(self, field_name, None))
376366

@@ -386,7 +376,6 @@ def _get_disabled_public_plugins(self) -> list[str]:
386376
"WEBSERVER_META_MODELING",
387377
"WEBSERVER_PAYMENTS",
388378
"WEBSERVER_SCICRUNCH",
389-
"WEBSERVER_TRASH",
390379
"WEBSERVER_VERSION_CONTROL",
391380
}
392381
return [_ for _ in public_plugin_candidates if not self.is_enabled(_)]

services/web/server/src/simcore_service_webserver/folders/_trash_handlers.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
)
99

1010
from .._meta import API_VTAG as VTAG
11-
from ..application_settings_utils import requires_dev_feature_enabled
1211
from ..login.decorators import get_user_id, login_required
1312
from ..products.api import get_product_name
1413
from ..security.decorators import permission_required
@@ -23,7 +22,6 @@
2322

2423

2524
@routes.post(f"/{VTAG}/folders/{{folder_id}}:trash", name="trash_folder")
26-
@requires_dev_feature_enabled
2725
@login_required
2826
@permission_required("folder.delete")
2927
@handle_plugin_requests_exceptions
@@ -47,7 +45,6 @@ async def trash_folder(request: web.Request):
4745

4846

4947
@routes.post(f"/{VTAG}/folders/{{folder_id}}:untrash", name="untrash_folder")
50-
@requires_dev_feature_enabled
5148
@login_required
5249
@permission_required("folder.delete")
5350
@handle_plugin_requests_exceptions

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
)
99

1010
from .._meta import API_VTAG as VTAG
11-
from ..application_settings_utils import requires_dev_feature_enabled
1211
from ..exceptions_handlers import (
1312
ExceptionToHttpErrorMap,
1413
HttpErrorInfo,
@@ -57,7 +56,6 @@
5756

5857

5958
@routes.delete(f"/{VTAG}/trash", name="empty_trash")
60-
@requires_dev_feature_enabled
6159
@login_required
6260
@permission_required("project.delete")
6361
@_handle_exceptions
@@ -73,7 +71,6 @@ async def empty_trash(request: web.Request):
7371

7472

7573
@routes.post(f"/{VTAG}/projects/{{project_id}}:trash", name="trash_project")
76-
@requires_dev_feature_enabled
7774
@login_required
7875
@permission_required("project.delete")
7976
@_handle_exceptions
@@ -98,7 +95,6 @@ async def trash_project(request: web.Request):
9895

9996

10097
@routes.post(f"/{VTAG}/projects/{{project_id}}:untrash", name="untrash_project")
101-
@requires_dev_feature_enabled
10298
@login_required
10399
@permission_required("project.delete")
104100
@_handle_exceptions

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
)
99

1010
from .._meta import API_VTAG as VTAG
11-
from ..application_settings_utils import requires_dev_feature_enabled
1211
from ..login.decorators import get_user_id, login_required
1312
from ..products.api import get_product_name
1413
from ..security.decorators import permission_required
@@ -23,7 +22,6 @@
2322

2423

2524
@routes.post(f"/{VTAG}/workspaces/{{workspace_id}}:trash", name="trash_workspace")
26-
@requires_dev_feature_enabled
2725
@login_required
2826
@permission_required("workspaces.*")
2927
@handle_plugin_requests_exceptions
@@ -47,7 +45,6 @@ async def trash_workspace(request: web.Request):
4745

4846

4947
@routes.post(f"/{VTAG}/workspaces/{{workspace_id}}:untrash", name="untrash_workspace")
50-
@requires_dev_feature_enabled
5148
@login_required
5249
@permission_required("workspaces.*")
5350
@handle_plugin_requests_exceptions

services/web/server/tests/unit/isolated/test_application_settings.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,16 @@ def test_settings_to_client_statics_plugins(
104104

105105

106106
@pytest.mark.parametrize("is_dev_feature_enabled", [True, False])
107-
def test_settings_to_client_statics_for_webserver_trash(
107+
@pytest.mark.parametrize(
108+
"plugin_name",
109+
["WEBSERVER_META_MODELING", "WEBSERVER_VERSION_CONTROL"]
110+
# NOTE: this is the list in _enable_only_if_dev_features_allowed
111+
)
112+
def test_disabled_plugins_settings_to_client_statics(
108113
is_dev_feature_enabled: bool,
109114
mock_webserver_service_environment: EnvVarsDict,
110115
monkeypatch: pytest.MonkeyPatch,
116+
plugin_name: str,
111117
):
112118
monkeypatch.setenv(
113119
"WEBSERVER_DEV_FEATURES_ENABLED", f"{is_dev_feature_enabled}".lower()
@@ -116,10 +122,11 @@ def test_settings_to_client_statics_for_webserver_trash(
116122
settings = ApplicationSettings.create_from_envs()
117123
statics = settings.to_client_statics()
118124

125+
# checks whether it is shown to the front-end depending on the value of WEBSERVER_DEV_FEATURES_ENABLED
119126
if is_dev_feature_enabled:
120-
assert "WEBSERVER_TRASH" not in set(statics["pluginsDisabled"])
127+
assert plugin_name not in set(statics["pluginsDisabled"])
121128
else:
122-
assert "WEBSERVER_TRASH" in set(statics["pluginsDisabled"])
129+
assert plugin_name in set(statics["pluginsDisabled"])
123130

124131

125132
def test_avoid_sensitive_info_in_public(app_settings: ApplicationSettings):

0 commit comments

Comments
 (0)