Skip to content

Commit

Permalink
fixes sonarcloud issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Apr 12, 2023
1 parent 441b52e commit 92c2a1b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
1 change: 0 additions & 1 deletion packages/models-library/src/models_library/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class Config:


class DateTimeStr(ConstrainedStr):
# TODO: should we use datetime??
regex = re.compile(DATE_RE)

class Config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ async def _copy_files_from_source_project(
await long_running_task.result()


async def _compose_project_data(
app: web.Application, new_project: ProjectDict, predefined_project: ProjectDict
) -> ProjectDict:
if new_project: # creates from a copy, just override fields
for key in OVERRIDABLE_DOCUMENT_KEYS:
if non_null_value := predefined_project.get(key):
new_project[key] = non_null_value
else:
new_project = predefined_project
await projects_api.validate_project(app, new_project)
return new_project


async def create_project(
task_progress: TaskProgress,
app: web.Application,
Expand Down Expand Up @@ -183,14 +196,9 @@ async def create_project(

if predefined_project:
# 2. overrides with optional body and re-validate
if new_project:
for key in OVERRIDABLE_DOCUMENT_KEYS:
if non_null_value := predefined_project.get(key):
new_project[key] = non_null_value
else:
# FIXME: this can change ALL for a new project!
new_project = predefined_project
await projects_api.validate_project(app, new_project)
new_project = await _compose_project_data(
app, new_project, predefined_project
)

# 3. save new project in DB
new_project = await db.insert_project(
Expand Down Expand Up @@ -241,12 +249,12 @@ async def create_project(
raise web.HTTPNotFound(reason=f"Project {exc.project_uuid} not found") from exc
except ProjectInvalidRightsError as exc:
raise web.HTTPUnauthorized from exc

except asyncio.CancelledError:
log.warning(
"cancelled creation of project for '%s', cleaning up",
f"{user_id=}",
)
# FIXME: If cancelled during shutdown, cancellation of all_tasks will produce "new tasks"!
if prj_uuid := new_project.get("uuid"):
await projects_api.submit_delete_project_task(app, prj_uuid, user_id)
if project_uuid := new_project.get("uuid"):
await projects_api.submit_delete_project_task(app, project_uuid, user_id)
raise
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ..storage_api import delete_data_folders_of_project
from ..users_api import UserNameDict
from ..users_exceptions import UserNotFoundError
from .projects_db import APP_PROJECT_DBAPI, ProjectDBAPI
from .projects_db import ProjectDBAPI
from .projects_exceptions import (
ProjectDeleteError,
ProjectInvalidRightsError,
Expand All @@ -31,7 +31,7 @@


class RemoveProjectServicesCallable(Protocol):
# TODO: this function was tmp added here to avoid refactoring all projects_api in a single PR
# NOTE: this function was tmp added here to avoid refactoring all projects_api in a single PR
async def __call__(
self,
user_id: int,
Expand All @@ -50,15 +50,13 @@ async def mark_project_as_deleted(
::raises ProjectInvalidRightsError
::raises ProjectNotFoundError
"""
db: ProjectDBAPI = app[APP_PROJECT_DBAPI]
# TODO: tmp using invisible as a "deletion mark"
# Even if any of the steps below fail, the project will remain invisible
# TODO: see https://github.com/ITISFoundation/osparc-simcore/pull/2522
# NOTE: https://github.com/ITISFoundation/osparc-issues/issues/468
db: ProjectDBAPI = ProjectDBAPI.get_from_app_context(app)
await db.check_delete_project_permission(user_id, f"{project_uuid}")

await db.check_project_has_only_one_product(project_uuid)

# TODO: note that if any of the steps below fail, it might results in a
# NOTE: if any of the steps below fail, it might results in a
# services/projects/data that might be incosistent. The GC should
# be able to detect that and resolve it.
await db.set_hidden_flag(project_uuid, enabled=True)
Expand All @@ -68,7 +66,7 @@ async def delete_project(
app: web.Application,
project_uuid: ProjectID,
user_id: UserID,
# TODO: this function was tmp added here to avoid refactoring all projects_api in a single PR
# NOTE: this function was tmp added here to avoid refactoring all projects_api in a single PR
remove_project_dynamic_services: RemoveProjectServicesCallable,
) -> None:
"""Stops dynamic services, deletes data and finally deletes project
Expand All @@ -83,7 +81,7 @@ async def delete_project(
f"{project_uuid=}",
f"{user_id=}",
)
db: ProjectDBAPI = app[APP_PROJECT_DBAPI]
db: ProjectDBAPI = ProjectDBAPI.get_from_app_context(app)

try:
await mark_project_as_deleted(app, project_uuid, user_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ async def create_project(request: web.Request):
copy_data=query_params.copy_data,
user_id=req_ctx.user_id,
product_name=req_ctx.product_name,
predefined_project=project_create.dict(exclude_unset=True),
predefined_project=project_create.dict(
exclude_unset=True, by_alias=True, exclude_none=True
),
)


Expand Down

0 comments on commit 92c2a1b

Please sign in to comment.