-
Notifications
You must be signed in to change notification settings - Fork 32
✨ Trash projects #6579
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
Merged
Merged
✨ Trash projects #6579
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
e178044
drafts
pcrespov 72c0cdc
updates reqs to build dev
pcrespov ba0c94e
api for trashing
pcrespov 91698e7
api models
pcrespov ea21095
oas
pcrespov c29d4ef
services/webserver api version: 0.43.1 → 0.44.0
pcrespov dbac766
drafts test
pcrespov 4cfcd28
adds filters
pcrespov 31417c0
aadds filters
pcrespov 14fe4bf
filter in rest api
pcrespov 892b2a2
filter model
pcrespov 0518c39
migration
pcrespov e50ce48
projects repo
pcrespov 1b54965
test filter list_project
pcrespov 2d4e397
trash
pcrespov 916e018
adds project trash
pcrespov 02558ae
updates OAS
pcrespov f991865
settings
pcrespov 9cccff2
updates test
pcrespov a3fca4c
adds internal model
pcrespov 4fb76a5
project patch extended moved
pcrespov 8a9375c
fixes
pcrespov 0ba5994
WIP test
pcrespov 1f55a2d
test pass
pcrespov e244252
cleanup
pcrespov 30ec4a2
fixes
pcrespov ce22af3
creates periodic tasks
pcrespov 72e3578
rm folders
pcrespov 7ddab2a
circular dependency and fixes test
pcrespov 73b7dca
updates settings
pcrespov 6125a9d
oas test
pcrespov 3b048f3
fxies tests
pcrespov 2379372
@matusdrobuliak66 review: todo
pcrespov 0ace86b
@matusdrobuliak66 review: db model
pcrespov d92cfd4
@sanderegg review: doc
pcrespov 2c4f13e
@sanderegg review: stop before trashing
pcrespov 6474259
error handling
pcrespov f5fe9aa
prepares tests
pcrespov ad167f2
fixes tests
pcrespov 07c296d
improves OAS
pcrespov 576abee
cleanup
pcrespov fe14260
changed force
pcrespov 373e554
cleanup
pcrespov 0c3a2cb
fixes test
pcrespov 3aef58a
extends test
pcrespov fa5ea4a
pylint
pcrespov 8b1b523
pylint
pcrespov 5571fb7
api
pcrespov 88575c2
rename
pcrespov e81b8ae
stop
pcrespov 144d37d
stop before run and permissions
pcrespov 40a67ac
fixes coro
pcrespov 29e8d36
fixes coro
pcrespov 3c21197
null
pcrespov 5b94385
Merge branch 'master' into is468/trash-api
pcrespov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # pylint: disable=redefined-outer-name | ||
| # pylint: disable=unused-argument | ||
| # pylint: disable=unused-variable | ||
| # pylint: disable=too-many-arguments | ||
|
|
||
|
|
||
| from enum import Enum | ||
| from typing import Annotated | ||
|
|
||
| from fastapi import APIRouter, Depends, status | ||
| from simcore_service_webserver._meta import API_VTAG | ||
| from simcore_service_webserver.projects._trash_handlers import ( | ||
| ProjectPathParams, | ||
| RemoveQueryParams, | ||
| ) | ||
|
|
||
| router = APIRouter( | ||
| prefix=f"/{API_VTAG}", | ||
| tags=["trash"], | ||
| ) | ||
|
|
||
|
|
||
| @router.delete( | ||
| "/trash", | ||
| status_code=status.HTTP_204_NO_CONTENT, | ||
| ) | ||
| def empty_trash(): | ||
| ... | ||
|
|
||
|
|
||
| _extra_tags: list[str | Enum] = ["projects"] | ||
|
|
||
|
|
||
| @router.post( | ||
| "/projects/{project_id}:trash", | ||
| tags=_extra_tags, | ||
| status_code=status.HTTP_204_NO_CONTENT, | ||
| responses={ | ||
| status.HTTP_404_NOT_FOUND: {"description": "Not such a project"}, | ||
| status.HTTP_409_CONFLICT: { | ||
| "description": "Project is in use and cannot be trashed" | ||
| }, | ||
| status.HTTP_503_SERVICE_UNAVAILABLE: {"description": "Trash service error"}, | ||
| }, | ||
| ) | ||
| def trash_project( | ||
| _p: Annotated[ProjectPathParams, Depends()], | ||
| _q: Annotated[RemoveQueryParams, Depends()], | ||
| ): | ||
| ... | ||
|
|
||
|
|
||
| @router.post( | ||
| "/projects/{project_id}:untrash", | ||
| tags=_extra_tags, | ||
| status_code=status.HTTP_204_NO_CONTENT, | ||
| ) | ||
| def untrash_project( | ||
| _p: Annotated[ProjectPathParams, Depends()], | ||
| ): | ||
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
packages/models-library/src/models_library/api_schemas_webserver/folders_v2.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 17 additions & 2 deletions
19
packages/models-library/src/models_library/rest_filters.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,22 @@ | ||
| from pydantic import BaseModel | ||
| from typing import Generic, TypeVar | ||
|
|
||
| from pydantic import BaseModel, Field, Json | ||
| from pydantic.generics import GenericModel | ||
|
|
||
|
|
||
| class Filters(BaseModel): | ||
| """inspired by Docker API https://docs.docker.com/engine/api/v1.43/#tag/Container/operation/ContainerList. | ||
| """ | ||
| Encoded as JSON. Each available filter can have its own logic (should be well documented) | ||
| Inspired by Docker API https://docs.docker.com/engine/api/v1.43/#tag/Container/operation/ContainerList. | ||
| """ | ||
|
|
||
|
|
||
| # Custom filter | ||
| FilterT = TypeVar("FilterT", bound=Filters) | ||
|
|
||
|
|
||
| class FiltersQueryParameters(GenericModel, Generic[FilterT]): | ||
| filters: Json[FilterT] | None = Field( # pylint: disable=unsubscriptable-object | ||
| default=None, | ||
| description="Custom filter query parameter encoded as JSON", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import logging | ||
|
|
||
| import pytest | ||
| from models_library.rest_filters import Filters, FiltersQueryParameters | ||
| from pydantic import Extra, ValidationError | ||
|
|
||
|
|
||
| # 1. create filter model | ||
| class CustomFilter(Filters): | ||
| is_trashed: bool | None = None | ||
| is_hidden: bool | None = None | ||
|
|
||
|
|
||
| class CustomFilterStrict(CustomFilter): | ||
| class Config(CustomFilter.Config): | ||
| extra = Extra.forbid | ||
|
|
||
|
|
||
| def test_custom_filter_query_parameters(): | ||
|
|
||
| # 2. use generic as query parameters | ||
| logging.info( | ||
| "json schema is for the query \n %s", | ||
| FiltersQueryParameters[CustomFilter].schema_json(indent=1), | ||
| ) | ||
|
|
||
| # lets filter only is_trashed and unset is_hidden | ||
| custom_filter = CustomFilter(is_trashed=True) | ||
| assert custom_filter.json() == '{"is_trashed": true, "is_hidden": null}' | ||
|
|
||
| # default to None (optional) | ||
| query_param = FiltersQueryParameters[CustomFilter]() | ||
| assert query_param.filters is None | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "url_query_value,expects", | ||
| [ | ||
| ('{"is_trashed": true, "is_hidden": null}', CustomFilter(is_trashed=True)), | ||
| ('{"is_trashed": true}', CustomFilter(is_trashed=True)), | ||
| (None, None), | ||
| ], | ||
| ) | ||
| def test_valid_filter_queries( | ||
| url_query_value: str | None, expects: CustomFilter | None | ||
| ): | ||
| query_param = FiltersQueryParameters[CustomFilter](filters=url_query_value) | ||
| assert query_param.filters == expects | ||
|
|
||
|
|
||
| def test_invalid_filter_query_is_ignored(): | ||
| # NOTE: invalid filter get ignored! | ||
| url_query_value = '{"undefined_filter": true, "is_hidden": true}' | ||
|
|
||
| query_param = FiltersQueryParameters[CustomFilter](filters=url_query_value) | ||
| assert query_param.filters == CustomFilter(is_hidden=True) | ||
|
|
||
|
|
||
| @pytest.mark.xfail | ||
| def test_invalid_filter_query_fails(): | ||
| # NOTE: this should fail according to pydantic manual but it does not | ||
| url_query_value = '{"undefined_filter": true, "is_hidden": true}' | ||
pcrespov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| with pytest.raises(ValidationError): | ||
| FiltersQueryParameters[CustomFilterStrict](filters=url_query_value) | ||
29 changes: 29 additions & 0 deletions
29
.../src/simcore_postgres_database/migration/versions/fce5d231e16d_new_projects_trashed_at.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| """new projects trashed_at | ||
|
|
||
| Revision ID: fce5d231e16d | ||
| Revises: ea3952fe5a0e | ||
| Create Date: 2024-10-23 14:32:32.350937+00:00 | ||
|
|
||
| """ | ||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "fce5d231e16d" | ||
| down_revision = "ea3952fe5a0e" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.add_column( | ||
| "projects", sa.Column("trashed_at", sa.DateTime(timezone=True), nullable=True) | ||
| ) | ||
| # ### end Alembic commands ### | ||
|
|
||
|
|
||
| def downgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.drop_column("projects", "trashed_at") | ||
| # ### end Alembic commands ### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0.43.1 | ||
| 0.44.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.