Skip to content

Commit

Permalink
project patch extended moved
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Oct 23, 2024
1 parent 5d590e3 commit fb9ace6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit fb9ace6

Please sign in to comment.