Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 Enables trash in web-api #6861

Merged
merged 4 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,6 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
WEBSERVER_REMOTE_DEBUG: bool = True
WEBSERVER_SOCKETIO: bool = True
WEBSERVER_TAGS: bool = True
WEBSERVER_TRASH: Annotated[
bool,
Field(
description="Currently only used to enable/disable front-end",
validation_alias=AliasChoices(
"WEBSERVER_TRASH", "WEBSERVER_DEV_FEATURES_ENABLED"
),
),
] = False
WEBSERVER_VERSION_CONTROL: bool = True
WEBSERVER_WALLETS: bool = True
WEBSERVER_WORKSPACES: bool = True
Expand All @@ -302,7 +293,7 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):

@model_validator(mode="before")
@classmethod
def build_vcs_release_url_if_unset(cls, values):
def _build_vcs_release_url_if_unset(cls, values):
release_url = values.get("SIMCORE_VCS_RELEASE_URL")

if release_url is None and (
Expand All @@ -323,12 +314,11 @@ def build_vcs_release_url_if_unset(cls, values):
# TODO: consider mark as dev-feature in field extras of Config attr.
# Then they can be automtically advertised
"WEBSERVER_META_MODELING",
"WEBSERVER_TRASH",
"WEBSERVER_VERSION_CONTROL",
mode="before",
)
@classmethod
def enable_only_if_dev_features_allowed(cls, v, info: ValidationInfo):
def _enable_only_if_dev_features_allowed(cls, v, info: ValidationInfo):
"""Ensures that plugins 'under development' get programatically
disabled if WEBSERVER_DEV_FEATURES_ENABLED=False
"""
Expand All @@ -345,19 +335,14 @@ def enable_only_if_dev_features_allowed(cls, v, info: ValidationInfo):
else False
)

@cached_property
def log_level(self) -> int:
level: int = getattr(logging, self.WEBSERVER_LOGLEVEL.upper())
return level

@field_validator("WEBSERVER_LOGLEVEL")
@classmethod
def valid_log_level(cls, value):
def _valid_log_level(cls, value):
return cls.validate_log_level(value)

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

# HELPERS --------------------------------------------------------

@cached_property
def log_level(self) -> int:
level: int = getattr(logging, self.WEBSERVER_LOGLEVEL.upper())
return level

def is_enabled(self, field_name: str) -> bool:
return bool(getattr(self, field_name, None))

Expand All @@ -386,7 +376,6 @@ def _get_disabled_public_plugins(self) -> list[str]:
"WEBSERVER_META_MODELING",
"WEBSERVER_PAYMENTS",
"WEBSERVER_SCICRUNCH",
"WEBSERVER_TRASH",
"WEBSERVER_VERSION_CONTROL",
}
return [_ for _ in public_plugin_candidates if not self.is_enabled(_)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
)

from .._meta import API_VTAG as VTAG
from ..application_settings_utils import requires_dev_feature_enabled
from ..login.decorators import get_user_id, login_required
from ..products.api import get_product_name
from ..security.decorators import permission_required
Expand All @@ -23,7 +22,6 @@


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


@routes.post(f"/{VTAG}/folders/{{folder_id}}:untrash", name="untrash_folder")
@requires_dev_feature_enabled
@login_required
@permission_required("folder.delete")
@handle_plugin_requests_exceptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
)

from .._meta import API_VTAG as VTAG
from ..application_settings_utils import requires_dev_feature_enabled
from ..exceptions_handlers import (
ExceptionToHttpErrorMap,
HttpErrorInfo,
Expand Down Expand Up @@ -57,7 +56,6 @@


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


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


@routes.post(f"/{VTAG}/projects/{{project_id}}:untrash", name="untrash_project")
@requires_dev_feature_enabled
@login_required
@permission_required("project.delete")
@_handle_exceptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
)

from .._meta import API_VTAG as VTAG
from ..application_settings_utils import requires_dev_feature_enabled
from ..login.decorators import get_user_id, login_required
from ..products.api import get_product_name
from ..security.decorators import permission_required
Expand All @@ -23,7 +22,6 @@


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


@routes.post(f"/{VTAG}/workspaces/{{workspace_id}}:untrash", name="untrash_workspace")
@requires_dev_feature_enabled
@login_required
@permission_required("workspaces.*")
@handle_plugin_requests_exceptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,16 @@ def test_settings_to_client_statics_plugins(


@pytest.mark.parametrize("is_dev_feature_enabled", [True, False])
def test_settings_to_client_statics_for_webserver_trash(
@pytest.mark.parametrize(
"plugin_name",
["WEBSERVER_META_MODELING", "WEBSERVER_VERSION_CONTROL"]
# NOTE: this is the list in _enable_only_if_dev_features_allowed
)
def test_disabled_plugins_settings_to_client_statics(
is_dev_feature_enabled: bool,
mock_webserver_service_environment: EnvVarsDict,
monkeypatch: pytest.MonkeyPatch,
plugin_name: str,
):
monkeypatch.setenv(
"WEBSERVER_DEV_FEATURES_ENABLED", f"{is_dev_feature_enabled}".lower()
Expand All @@ -116,10 +122,11 @@ def test_settings_to_client_statics_for_webserver_trash(
settings = ApplicationSettings.create_from_envs()
statics = settings.to_client_statics()

# checks whether it is shown to the front-end depending on the value of WEBSERVER_DEV_FEATURES_ENABLED
if is_dev_feature_enabled:
assert "WEBSERVER_TRASH" not in set(statics["pluginsDisabled"])
assert plugin_name not in set(statics["pluginsDisabled"])
else:
assert "WEBSERVER_TRASH" in set(statics["pluginsDisabled"])
assert plugin_name in set(statics["pluginsDisabled"])


def test_avoid_sensitive_info_in_public(app_settings: ApplicationSettings):
Expand Down
Loading