Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from servicelib.redis import get_project_locked_state

from ..._meta import API_VTAG as VTAG
from ...catalog import catalog_service
from ...login.decorators import login_required
from ...redis import get_redis_lock_manager_client_sdk
from ...resource_manager.user_sessions import PROJECT_ID_KEY, managed_resource
Expand All @@ -39,7 +38,6 @@
from .. import _crud_api_create, _crud_api_read, _projects_service
from .._permalink_service import update_or_pop_permalink_in_project
from ..models import ProjectDict
from ..utils import are_project_services_available, get_project_unavailable_services
from . import _rest_utils
from ._rest_exceptions import handle_plugin_requests_exceptions
from ._rest_schemas import (
Expand Down Expand Up @@ -271,10 +269,6 @@ async def get_project(request: web.Request):
req_ctx = AuthenticatedRequestContext.model_validate(request)
path_params = parse_request_path_parameters_as(ProjectPathParams, request)

user_available_services = await catalog_service.get_services_for_user_in_product(
request.app, user_id=req_ctx.user_id, product_name=req_ctx.product_name
)

project = await _projects_service.get_project_for_user(
request.app,
project_uuid=f"{path_params.project_id}",
Expand All @@ -283,21 +277,6 @@ async def get_project(request: web.Request):
include_trashed_by_primary_gid=True,
)

if not are_project_services_available(project, user_available_services):
unavilable_services = get_project_unavailable_services(
project, user_available_services
)
formatted_services = ", ".join(
f"{service}:{version}" for service, version in unavilable_services
)
# TODO: lack of permissions should be notified with https://httpstatuses.com/403 web.HTTPForbidden
raise web.HTTPNotFound(
reason=(
f"Project '{path_params.project_id}' uses unavailable services. Please ask "
f"for permission for the following services {formatted_services}"
)
)

# Adds permalink
await update_or_pop_permalink_in_project(request, project)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
)
from simcore_postgres_database.webserver_models import ProjectType as ProjectTypeDB

from ..catalog import catalog_service
from ..folders import _folders_repository
from ..workspaces.api import check_user_workspace_access
from . import _projects_service
Expand Down Expand Up @@ -120,10 +119,6 @@ async def list_projects( # pylint: disable=too-many-arguments
) -> tuple[list[ProjectDict], int]:
db = ProjectDBAPI.get_from_app_context(app)

user_available_services = await catalog_service.get_services_for_user_in_product(
app, user_id=user_id, product_name=product_name
)

workspace_is_private = True
if workspace_id:
await check_user_workspace_access(
Expand Down Expand Up @@ -165,7 +160,6 @@ async def list_projects( # pylint: disable=too-many-arguments
filter_by_template_type=(
ProjectTemplateTypeDB(template_type) if template_type else None
),
filter_by_services=user_available_services,
filter_trashed=trashed,
filter_hidden=show_hidden,
# composed attrs
Expand Down Expand Up @@ -202,17 +196,12 @@ async def list_projects_full_depth(
) -> tuple[list[ProjectDict], int]:
db = ProjectDBAPI.get_from_app_context(app)

user_available_services = await catalog_service.get_services_for_user_in_product(
app, user_id=user_id, product_name=product_name
)

db_projects, db_project_types, total_number_projects = await db.list_projects_dicts(
product_name=product_name,
user_id=user_id,
workspace_query=WorkspaceQuery(workspace_scope=WorkspaceScope.ALL),
folder_query=FolderQuery(folder_scope=FolderScope.ALL),
filter_trashed=trashed,
filter_by_services=user_available_services,
filter_by_project_type=ProjectType.STANDARD,
search_by_multi_columns=search_by_multi_columns,
search_by_project_name=search_by_project_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@ async def list_projects_dicts( # pylint: disable=too-many-arguments,too-many-st
# attribute filters
filter_by_project_type: ProjectType | None = None,
filter_by_template_type: ProjectTemplateType | None = None,
filter_by_services: list[dict] | None = None,
filter_published: bool | None = None,
filter_hidden: bool | None = False,
filter_trashed: bool | None = False,
Expand Down Expand Up @@ -670,9 +669,7 @@ async def list_projects_dicts( # pylint: disable=too-many-arguments,too-many-st

prjs, prj_types = await self._execute_without_permission_check(
conn,
user_id=user_id,
select_projects_query=combined_query.offset(offset).limit(limit),
filter_by_services=filter_by_services,
)

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
from models_library.projects import ProjectAtDB, ProjectID, ProjectTemplateType
from models_library.projects_nodes import Node
from models_library.projects_nodes_io import NodeIDStr
from models_library.users import UserID
from models_library.utils.change_case import camel_to_snake, snake_to_camel
from pydantic import ValidationError
from simcore_postgres_database.models.project_to_groups import project_to_groups
from simcore_postgres_database.models.projects_to_products import projects_to_products
from simcore_postgres_database.webserver_models import ProjectType, projects
from sqlalchemy.dialects.postgresql import insert as pg_insert
from sqlalchemy.sql.selectable import CompoundSelect, Select
Expand All @@ -32,7 +30,7 @@
ProjectNotFoundError,
)
from .models import ProjectDict
from .utils import are_project_services_available, find_changed_node_keys
from .utils import find_changed_node_keys

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -189,10 +187,8 @@ async def _upsert_tags_in_project(
async def _execute_without_permission_check(
self,
conn: SAConnection,
user_id: UserID,
*,
select_projects_query: Select | CompoundSelect,
filter_by_services: list[dict] | None = None,
) -> tuple[list[dict[str, Any]], list[ProjectType]]:
api_projects: list[dict] = [] # API model-compatible projects
db_projects: list[dict] = [] # DB model-compatible projects
Expand All @@ -218,19 +214,6 @@ async def _execute_without_permission_check(
prj: dict[str, Any] = dict(row.items())
prj.pop("product_name", None)

if (
filter_by_services is not None
# This checks only old projects that are not in the projects_to_products table.
and row[projects_to_products.c.product_name] is None
and not are_project_services_available(prj, filter_by_services)
):
logger.warning(
"Project %s will not be listed for user %s since it has no access rights"
" for one or more of the services that includes.",
f"{row.id=}",
f"{user_id=}",
)
continue
db_projects.append(prj)

# NOTE: DO NOT nest _get_tags_by_project in async loop above !!!
Expand Down
Loading