From a4b7c7a67dea15a7bc40efb8afb08a93b81c0186 Mon Sep 17 00:00:00 2001 From: Matus Drobuliak <60785969+matusdrobuliak66@users.noreply.github.com> Date: Wed, 13 Nov 2024 18:54:09 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20listing=20folders=20in=20w?= =?UTF-8?q?orkspace=20(#6718)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Odei Maiz <33152403+odeimaiz@users.noreply.github.com> --- .../folders/_folders_db.py | 6 ++ ...t_workspaces__folders_and_projects_crud.py | 95 +++++++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/services/web/server/src/simcore_service_webserver/folders/_folders_db.py b/services/web/server/src/simcore_service_webserver/folders/_folders_db.py index f4e27fa3a7a..e2992d111ee 100644 --- a/services/web/server/src/simcore_service_webserver/folders/_folders_db.py +++ b/services/web/server/src/simcore_service_webserver/folders/_folders_db.py @@ -178,6 +178,12 @@ async def list_( # pylint: disable=too-many-arguments,too-many-branches & (folders_v2.c.user_id.is_(None)) ) ) + + if workspace_query.workspace_scope == WorkspaceScope.SHARED: + shared_workspace_query = shared_workspace_query.where( + folders_v2.c.workspace_id == workspace_query.workspace_id + ) + else: shared_workspace_query = None diff --git a/services/web/server/tests/unit/with_dbs/04/workspaces/test_workspaces__folders_and_projects_crud.py b/services/web/server/tests/unit/with_dbs/04/workspaces/test_workspaces__folders_and_projects_crud.py index c95aebe6fdd..717de9303fd 100644 --- a/services/web/server/tests/unit/with_dbs/04/workspaces/test_workspaces__folders_and_projects_crud.py +++ b/services/web/server/tests/unit/with_dbs/04/workspaces/test_workspaces__folders_and_projects_crud.py @@ -365,3 +365,98 @@ async def test_workspaces_delete_folders( resp = await client.get(url) data, _ = await assert_status(resp, status.HTTP_200_OK) assert len(data) == 0 + + +@pytest.mark.parametrize("user_role,expected", [(UserRole.USER, status.HTTP_200_OK)]) +async def test_listing_folders_and_projects_in_workspace__multiple_workspaces_created( + client: TestClient, + logged_user: UserInfoDict, + user_project: ProjectDict, + expected: HTTPStatus, + mock_catalog_api_get_services_for_user_in_product: MockerFixture, + fake_project: ProjectDict, + workspaces_clean_db: None, +): + assert client.app + + # create a new workspace + url = client.app.router["create_workspace"].url_for() + resp = await client.post( + url.path, + json={ + "name": "My first workspace", + "description": "Custom description", + "thumbnail": None, + }, + ) + added_workspace_1, _ = await assert_status(resp, status.HTTP_201_CREATED) + + # Create project in workspace + project_data = deepcopy(fake_project) + project_data["workspace_id"] = f"{added_workspace_1['workspaceId']}" + project = await create_project( + client.app, + project_data, + user_id=logged_user["id"], + product_name="osparc", + ) + + # Create folder in workspace + url = client.app.router["create_folder"].url_for() + resp = await client.post( + url.path, + json={ + "name": "Original user folder", + "workspaceId": f"{added_workspace_1['workspaceId']}", + }, + ) + first_folder, _ = await assert_status(resp, status.HTTP_201_CREATED) + + # create a new workspace + url = client.app.router["create_workspace"].url_for() + resp = await client.post( + url.path, + json={ + "name": "My first workspace", + "description": "Custom description", + "thumbnail": None, + }, + ) + added_workspace_2, _ = await assert_status(resp, status.HTTP_201_CREATED) + + # Create project in workspace + project_data = deepcopy(fake_project) + project_data["workspace_id"] = f"{added_workspace_2['workspaceId']}" + project = await create_project( + client.app, + project_data, + user_id=logged_user["id"], + product_name="osparc", + ) + + # Create folder in workspace + url = client.app.router["create_folder"].url_for() + resp = await client.post( + url.path, + json={ + "name": "Original user folder", + "workspaceId": f"{added_workspace_2['workspaceId']}", + }, + ) + first_folder, _ = await assert_status(resp, status.HTTP_201_CREATED) + + # List projects in workspace 1 + base_url = client.app.router["list_projects"].url_for() + url = base_url.with_query({"workspace_id": f"{added_workspace_1['workspaceId']}"}) + resp = await client.get(url) + data, _ = await assert_status(resp, status.HTTP_200_OK) + assert len(data) == 1 + + # List folders in workspace 1 + base_url = client.app.router["list_folders"].url_for() + url = base_url.with_query( + {"workspace_id": f"{added_workspace_1['workspaceId']}", "folder_id": "null"} + ) + resp = await client.get(url) + data, _ = await assert_status(resp, status.HTTP_200_OK) + assert len(data) == 1