From fb9ace65a4f6cfd560873ebd076a9115ff918210 Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Wed, 23 Oct 2024 20:40:01 +0200 Subject: [PATCH] project patch extended moved --- .../api_schemas_webserver/projects.py | 5 ---- .../projects/_trash_api.py | 2 +- .../projects/_trash_handlers.py | 25 ------------------- .../projects/models.py | 12 ++++++++- .../projects/projects_api.py | 7 ++---- 5 files changed, 14 insertions(+), 37 deletions(-) diff --git a/packages/models-library/src/models_library/api_schemas_webserver/projects.py b/packages/models-library/src/models_library/api_schemas_webserver/projects.py index a50fd322e945..2de49bb708da 100644 --- a/packages/models-library/src/models_library/api_schemas_webserver/projects.py +++ b/packages/models-library/src/models_library/api_schemas_webserver/projects.py @@ -146,11 +146,6 @@ class ProjectPatch(InputSchema): quality: dict[str, Any] = FieldNotRequired() -class ProjectPatchExtended(ProjectPatch): - # Only used internally - trashed_at: datetime | None = None - - __all__: tuple[str, ...] = ( "EmptyModel", "ProjectCopyOverride", diff --git a/services/web/server/src/simcore_service_webserver/projects/_trash_api.py b/services/web/server/src/simcore_service_webserver/projects/_trash_api.py index a57c3c310a2f..c763dee4226b 100644 --- a/services/web/server/src/simcore_service_webserver/projects/_trash_api.py +++ b/services/web/server/src/simcore_service_webserver/projects/_trash_api.py @@ -1,11 +1,11 @@ import arrow from aiohttp import web -from models_library.api_schemas_webserver.projects import ProjectPatchExtended from models_library.products import ProductName from models_library.projects import ProjectID from models_library.users import UserID from . import projects_api +from .models import ProjectPatchExtended async def empty_trash(app: web.Application, product_name: ProductName, user_id: UserID): diff --git a/services/web/server/src/simcore_service_webserver/projects/_trash_handlers.py b/services/web/server/src/simcore_service_webserver/projects/_trash_handlers.py index 535ebad31de6..e42efbffc418 100644 --- a/services/web/server/src/simcore_service_webserver/projects/_trash_handlers.py +++ b/services/web/server/src/simcore_service_webserver/projects/_trash_handlers.py @@ -1,13 +1,6 @@ -import functools - from aiohttp import web from servicelib.aiohttp import status from servicelib.aiohttp.requests_validation import parse_request_path_parameters_as -from servicelib.aiohttp.typing_extension import Handler -from simcore_postgres_database.utils_tags import ( - TagNotFoundError, - TagOperationNotAllowedError, -) from .._meta import API_VTAG as VTAG from ..login.decorators import get_user_id, login_required @@ -16,29 +9,12 @@ from ..security.decorators import permission_required from . import _trash_api - -def _handle_trash_exceptions(handler: Handler): - @functools.wraps(handler) - async def wrapper(request: web.Request) -> web.StreamResponse: - try: - return await handler(request) - - except TagNotFoundError as exc: - raise web.HTTPNotFound(reason=f"{exc}") from exc - - except TagOperationNotAllowedError as exc: - raise web.HTTPForbidden(reason=f"{exc}") from exc - - return wrapper - - routes = web.RouteTableDef() @routes.delete(f"/{VTAG}/trash", name="empty_trash") @login_required @permission_required("project.delete") -@_handle_trash_exceptions async def empty_trash(request: web.Request): user_id = get_user_id(request) product_name = get_product_name(request) @@ -58,7 +34,6 @@ async def empty_trash(request: web.Request): @routes.post(f"/{VTAG}/projects/{{project_id}}:trash", name="trash_project") @login_required @permission_required("project.delete") -@_handle_trash_exceptions async def trash_project(request: web.Request): user_id = get_user_id(request) product_name = get_product_name(request) diff --git a/services/web/server/src/simcore_service_webserver/projects/models.py b/services/web/server/src/simcore_service_webserver/projects/models.py index 8f4a13c172be..8ca693a54a33 100644 --- a/services/web/server/src/simcore_service_webserver/projects/models.py +++ b/services/web/server/src/simcore_service_webserver/projects/models.py @@ -3,6 +3,7 @@ from typing import Any, TypeAlias from aiopg.sa.result import RowProxy +from models_library.api_schemas_webserver.projects import ProjectPatch from models_library.basic_types import HttpUrlWithCustomMinLength from models_library.folders import FolderID from models_library.projects import ClassifierID, ProjectID @@ -13,7 +14,7 @@ none_to_empty_str_pre_validator, ) from models_library.workspaces import WorkspaceID -from pydantic import BaseModel, validator +from pydantic import BaseModel, Extra, validator from simcore_postgres_database.models.projects import ProjectType, projects ProjectDict: TypeAlias = dict[str, Any] @@ -97,6 +98,15 @@ class Config: orm_mode = True +class ProjectPatchExtended(ProjectPatch): + # Only used internally + trashed_at: datetime | None = None + + class Config: + allow_population_by_field_name = True + extra = Extra.forbid + + __all__: tuple[str, ...] = ( "ProjectDict", "ProjectProxy", diff --git a/services/web/server/src/simcore_service_webserver/projects/projects_api.py b/services/web/server/src/simcore_service_webserver/projects/projects_api.py index ec99246d094d..6e3b6acf428b 100644 --- a/services/web/server/src/simcore_service_webserver/projects/projects_api.py +++ b/services/web/server/src/simcore_service_webserver/projects/projects_api.py @@ -30,10 +30,7 @@ DynamicServiceStart, DynamicServiceStop, ) -from models_library.api_schemas_webserver.projects import ( - ProjectPatch, - ProjectPatchExtended, -) +from models_library.api_schemas_webserver.projects import ProjectPatch from models_library.api_schemas_webserver.projects_nodes import NodePatch from models_library.basic_types import KeyIDStr from models_library.errors import ErrorDict @@ -147,7 +144,7 @@ ProjectTooManyProjectOpenedError, ) from .lock import get_project_locked_state, is_project_locked, lock_project -from .models import ProjectDict +from .models import ProjectDict, ProjectPatchExtended from .settings import ProjectsSettings, get_plugin_settings from .utils import extract_dns_without_default_port