-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Project list items include permalink (#4214)
- Loading branch information
Showing
6 changed files
with
137 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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 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
100 changes: 100 additions & 0 deletions
100
services/web/server/src/simcore_service_webserver/projects/_read_utils.py
This file contains 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,100 @@ | ||
""" Utils to implement READ operations (from cRud) on the project resource | ||
Read operations are list, get | ||
""" | ||
from aiohttp import web | ||
from models_library.projects import ProjectID | ||
from models_library.users import UserID | ||
from pydantic import NonNegativeInt | ||
from servicelib.utils import logged_gather | ||
from simcore_postgres_database.webserver_models import ProjectType as ProjectTypeDB | ||
from simcore_service_webserver.rest_schemas_base import OutputSchema | ||
|
||
from .. import catalog | ||
from . import projects_api | ||
from ._permalink import update_or_pop_permalink_in_project | ||
from ._rest_schemas import ProjectListItem | ||
from .project_models import ProjectDict, ProjectTypeAPI | ||
from .projects_db import ProjectDBAPI | ||
|
||
|
||
async def _append_fields( | ||
request: web.Request, | ||
user_id: UserID, | ||
project: ProjectDict, | ||
is_template: bool, | ||
model_schema_cls: type[OutputSchema], | ||
): | ||
# state | ||
await projects_api.add_project_states_for_user( | ||
user_id=user_id, | ||
project=project, | ||
is_template=is_template, | ||
app=request.app, | ||
) | ||
|
||
# permalink | ||
await update_or_pop_permalink_in_project(request, project) | ||
|
||
# validate | ||
project_data = model_schema_cls.parse_obj(project).data(exclude_unset=True) | ||
return project_data | ||
|
||
|
||
async def list_projects( | ||
request: web.Request, | ||
user_id: UserID, | ||
product_name: str, | ||
project_type: ProjectTypeAPI, | ||
show_hidden: bool, | ||
offset: NonNegativeInt, | ||
limit: int, | ||
) -> tuple[list[ProjectDict], int]: | ||
|
||
app = request.app | ||
db = ProjectDBAPI.get_from_app_context(app) | ||
|
||
user_available_services: list[ | ||
dict | ||
] = await catalog.get_services_for_user_in_product( | ||
app, user_id, product_name, only_key_versions=True | ||
) | ||
|
||
db_projects, db_project_types, total_number_projects = await db.list_projects( | ||
user_id=user_id, | ||
product_name=product_name, | ||
filter_by_project_type=ProjectTypeAPI.to_project_type_db(project_type), | ||
filter_by_services=user_available_services, | ||
offset=offset, | ||
limit=limit, | ||
include_hidden=show_hidden, | ||
) | ||
|
||
projects: list[ProjectDict] = await logged_gather( | ||
*( | ||
_append_fields( | ||
request, | ||
user_id, | ||
project=prj, | ||
is_template=prj_type == ProjectTypeDB.TEMPLATE, | ||
model_schema_cls=ProjectListItem, | ||
) | ||
for prj, prj_type in zip(db_projects, db_project_types) | ||
), | ||
reraise=True, | ||
max_concurrency=100, | ||
) | ||
|
||
return projects, total_number_projects | ||
|
||
|
||
async def get_project( | ||
request: web.Request, | ||
user_id: UserID, | ||
product_name: str, | ||
project_uuid: ProjectID, | ||
project_type: ProjectTypeAPI, | ||
): | ||
raise NotImplementedError() |
This file contains 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 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 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