Skip to content

Commit bb71ef5

Browse files
committed
drafts trash section
1 parent 9db26b7 commit bb71ef5

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import logging
2+
3+
import arrow
4+
from aiohttp import web
5+
from models_library.products import ProductName
6+
from models_library.projects import ProjectID
7+
from models_library.users import UserID
8+
from models_library.workspaces import WorkspaceID
9+
10+
from ..projects._trash_api import trash_project, untrash_project
11+
12+
_logger = logging.getLogger(__name__)
13+
14+
15+
async def trash_workspace(
16+
app: web.Application,
17+
*,
18+
product_name: ProductName,
19+
user_id: UserID,
20+
workspace_id: WorkspaceID,
21+
force_stop_first: bool,
22+
):
23+
# TODO: Check
24+
25+
# Trash
26+
trashed_at = arrow.utcnow().datetime
27+
28+
_logger.debug(
29+
"TODO: Unit of work for all workspaces and projects and fails if force_stop_first=%s is False",
30+
force_stop_first,
31+
)
32+
33+
# 1. TODO: Trash workspace
34+
35+
# 2. Trash all child folders
36+
37+
# 2. Trash all child projects that I am an owner
38+
child_projects: list[ProjectID] = []
39+
40+
for project_id in child_projects:
41+
await trash_project(
42+
app,
43+
product_name=product_name,
44+
user_id=user_id,
45+
project_id=project_id,
46+
force_stop_first=force_stop_first,
47+
explicit=False,
48+
)
49+
50+
51+
async def untrash_workspace(
52+
app: web.Application,
53+
*,
54+
product_name: ProductName,
55+
user_id: UserID,
56+
workspace_id: WorkspaceID,
57+
):
58+
# TODO: Check
59+
60+
# 3. UNtrash
61+
62+
# 3.1 UNtrash workspace and children
63+
64+
# 3.2 UNtrash all child projects that I am an owner
65+
child_projects: list[ProjectID] = []
66+
for project_id in child_projects:
67+
await untrash_project(
68+
app, product_name=product_name, user_id=user_id, project_id=project_id
69+
)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import logging
2+
3+
from aiohttp import web
4+
from servicelib.aiohttp import status
5+
from servicelib.aiohttp.requests_validation import (
6+
parse_request_path_parameters_as,
7+
parse_request_query_parameters_as,
8+
)
9+
10+
from .._meta import API_VTAG as VTAG
11+
from ..application_settings_utils import requires_dev_feature_enabled
12+
from ..login.decorators import get_user_id, login_required
13+
from ..products.api import get_product_name
14+
from ..security.decorators import permission_required
15+
from . import _trash_api
16+
from ._exceptions_handlers import handle_plugin_requests_exceptions
17+
from ._models import RemoveQueryParams, WorkspacesPathParams
18+
19+
_logger = logging.getLogger(__name__)
20+
21+
22+
routes = web.RouteTableDef()
23+
24+
25+
@routes.post(f"/{VTAG}/workspaces/{{workspace_id}}:trash", name="trash_workspace")
26+
@requires_dev_feature_enabled
27+
@login_required
28+
@permission_required("workspace.delete")
29+
@handle_plugin_requests_exceptions
30+
async def trash_workspace(request: web.Request):
31+
user_id = get_user_id(request)
32+
product_name = get_product_name(request)
33+
path_params = parse_request_path_parameters_as(WorkspacesPathParams, request)
34+
query_params: RemoveQueryParams = parse_request_query_parameters_as(
35+
RemoveQueryParams, request
36+
)
37+
38+
await _trash_api.trash_workspace(
39+
request.app,
40+
product_name=product_name,
41+
user_id=user_id,
42+
workspace_id=path_params.workspace_id,
43+
force_stop_first=query_params.force,
44+
)
45+
46+
return web.json_response(status=status.HTTP_204_NO_CONTENT)
47+
48+
49+
@routes.post(f"/{VTAG}/workspaces/{{workspace_id}}:untrash", name="untrash_workspace")
50+
@requires_dev_feature_enabled
51+
@login_required
52+
@permission_required("workspace.delete")
53+
@handle_plugin_requests_exceptions
54+
async def untrash_workspace(request: web.Request):
55+
user_id = get_user_id(request)
56+
product_name = get_product_name(request)
57+
path_params = parse_request_path_parameters_as(WorkspacesPathParams, request)
58+
59+
await _trash_api.untrash_workspace(
60+
request.app,
61+
product_name=product_name,
62+
user_id=user_id,
63+
workspace_id=path_params.workspace_id,
64+
)
65+
66+
return web.json_response(status=status.HTTP_204_NO_CONTENT)

0 commit comments

Comments
 (0)