|
| 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